fix:cicd
This commit is contained in:
parent
9003d8718a
commit
fc939ab672
@ -46,16 +46,16 @@ jobs:
|
|||||||
uses: https://gitee.com/zsqai/ssh-action@v1.0.3
|
uses: https://gitee.com/zsqai/ssh-action@v1.0.3
|
||||||
with:
|
with:
|
||||||
host: ${{ vars.HOST }}
|
host: ${{ vars.HOST }}
|
||||||
username: ${{ vars.USERNAME }}
|
username: root
|
||||||
key: ${{ secrets.SSH_KEY }}
|
password: ${{ secrets.MAIN_HOST_PASSWORD }}
|
||||||
port: 22
|
port: 22
|
||||||
script: |
|
script: |
|
||||||
# 登录阿里云镜像仓库
|
# 登录阿里云镜像仓库
|
||||||
docker login --username=${{ vars.ALIYUN_USERNAME }} --password=${{ secrets.ALIYUN_PASSWORD }} ${{ vars.ALIYUN_REGISTRY }}
|
docker login --username=${{ vars.ALIYUN_USERNAME }} --password=${{ secrets.ALIYUN_PASSWORD }} ${{ vars.ALIYUN_REGISTRY }}
|
||||||
|
|
||||||
# 停止并删除旧容器
|
# 停止并删除旧容器
|
||||||
docker stop ai-personage-web 2>/dev/null || true
|
docker stop website-01 2>/dev/null || true
|
||||||
docker rm ai-personage-web 2>/dev/null || true
|
docker rm website-01 2>/dev/null || true
|
||||||
|
|
||||||
# 删除旧镜像(强制重新拉取)
|
# 删除旧镜像(强制重新拉取)
|
||||||
docker rmi ${{ vars.ALIYUN_REGISTRY }}/${{ vars.ALIYUN_NAMESPACE }}/${{ vars.ALIYUN_REPO }}:latest 2>/dev/null || true
|
docker rmi ${{ vars.ALIYUN_REGISTRY }}/${{ vars.ALIYUN_NAMESPACE }}/${{ vars.ALIYUN_REPO }}:latest 2>/dev/null || true
|
||||||
@ -65,9 +65,9 @@ jobs:
|
|||||||
|
|
||||||
# 运行新容器
|
# 运行新容器
|
||||||
docker run -d \
|
docker run -d \
|
||||||
--name ai-personage-web \
|
--name website-01 \
|
||||||
--restart always \
|
--restart always \
|
||||||
-p 8085:3003 \
|
-p 8085:3002 \
|
||||||
-e NODE_OPTIONS="--max-old-space-size=4096" \
|
-e NODE_OPTIONS="--max-old-space-size=4096" \
|
||||||
-e NODE_ENV="production" \
|
-e NODE_ENV="production" \
|
||||||
${{ vars.ALIYUN_REGISTRY }}/${{ vars.ALIYUN_NAMESPACE }}/${{ vars.ALIYUN_REPO }}:latest
|
${{ vars.ALIYUN_REGISTRY }}/${{ vars.ALIYUN_NAMESPACE }}/${{ vars.ALIYUN_REPO }}:latest
|
||||||
@ -77,12 +77,12 @@ jobs:
|
|||||||
|
|
||||||
# 查看 BUILD_ID 确认更新
|
# 查看 BUILD_ID 确认更新
|
||||||
echo "=== Build ID ==="
|
echo "=== Build ID ==="
|
||||||
docker exec -it ai-personage-web cat .next/BUILD_ID 2>/dev/null || echo "Cannot read BUILD_ID"
|
docker exec -it website-01 cat .next/BUILD_ID 2>/dev/null || echo "Cannot read BUILD_ID"
|
||||||
|
|
||||||
# 查看日志
|
# 查看日志
|
||||||
echo ""
|
echo ""
|
||||||
echo "=== Container Logs ==="
|
echo "=== Container Logs ==="
|
||||||
docker logs ai-personage-web --tail 20
|
docker logs website-01 --tail 20
|
||||||
|
|
||||||
# 清理无用镜像
|
# 清理无用镜像
|
||||||
docker image prune -f
|
docker image prune -f
|
||||||
44
Dockerfile
Normal file
44
Dockerfile
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# 构建阶段
|
||||||
|
FROM crpi-jlsdxetsdmy4ckxh.cn-shenzhen.personal.cr.aliyuncs.com/zsq_proxy/node:20-alpine AS build
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 添加构建参数
|
||||||
|
ARG BUILD_VERSION
|
||||||
|
ARG BUILD_TIME
|
||||||
|
ARG CACHE_BUST
|
||||||
|
|
||||||
|
ENV BUILD_VERSION=$BUILD_VERSION
|
||||||
|
ENV BUILD_TIME=$BUILD_TIME
|
||||||
|
|
||||||
|
# 强制打破 Docker 缓存
|
||||||
|
RUN echo "Cache bust: ${CACHE_BUST} - ${BUILD_VERSION} - ${BUILD_TIME}"
|
||||||
|
|
||||||
|
RUN yarn config set registry https://registry.npmmirror.com && \
|
||||||
|
yarn config set network-timeout 60000
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN yarn install --frozen-lockfile
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# 强制清理 .next
|
||||||
|
RUN rm -rf .next
|
||||||
|
|
||||||
|
# 构建
|
||||||
|
RUN yarn build
|
||||||
|
|
||||||
|
# 部署阶段
|
||||||
|
FROM crpi-jlsdxetsdmy4ckxh.cn-shenzhen.personal.cr.aliyuncs.com/zsq_proxy/node:20-alpine AS app
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV NODE_OPTIONS="--max-old-space-size=4096"
|
||||||
|
|
||||||
|
COPY --from=build /app/.next ./.next
|
||||||
|
COPY --from=build /app/public ./public
|
||||||
|
COPY --from=build /app/package.json ./package.json
|
||||||
|
COPY --from=build /app/node_modules ./node_modules
|
||||||
|
|
||||||
|
EXPOSE 3002
|
||||||
|
|
||||||
|
CMD ["yarn", "start"]
|
||||||
113
docker/nginx.conf
Executable file
113
docker/nginx.conf
Executable file
@ -0,0 +1,113 @@
|
|||||||
|
# Generated by nginxconfig.io
|
||||||
|
# See nginxconfig.txt for the configuration share link
|
||||||
|
|
||||||
|
user nginx;
|
||||||
|
pid /var/run/nginx.pid;
|
||||||
|
worker_processes auto;
|
||||||
|
worker_rlimit_nofile 65535;
|
||||||
|
|
||||||
|
# Load modules
|
||||||
|
include /etc/nginx/modules-enabled/*.conf;
|
||||||
|
|
||||||
|
events {
|
||||||
|
multi_accept on;
|
||||||
|
worker_connections 65535;
|
||||||
|
}
|
||||||
|
|
||||||
|
http {
|
||||||
|
charset utf-8;
|
||||||
|
sendfile on;
|
||||||
|
tcp_nopush on;
|
||||||
|
tcp_nodelay on;
|
||||||
|
server_tokens off;
|
||||||
|
log_not_found off;
|
||||||
|
types_hash_max_size 2048;
|
||||||
|
types_hash_bucket_size 64;
|
||||||
|
client_max_body_size 16M;
|
||||||
|
|
||||||
|
# MIME
|
||||||
|
include mime.types;
|
||||||
|
default_type application/octet-stream;
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
access_log /dev/stdout;
|
||||||
|
error_log /dev/stderr warn;
|
||||||
|
|
||||||
|
# 上游 Next.js 服务器(端口 3003)
|
||||||
|
upstream nextjs {
|
||||||
|
# 使用容器名称(如果在同一个 Docker 网络)
|
||||||
|
server website-01:3002;
|
||||||
|
# 如果使用宿主机 IP,取消下面这行注释,并注释上面那行
|
||||||
|
# server 172.17.0.1:3002;
|
||||||
|
keepalive 64;
|
||||||
|
}
|
||||||
|
|
||||||
|
# HTTP 服务器
|
||||||
|
server {
|
||||||
|
listen 8085;
|
||||||
|
listen [::]:8085;
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
# 静态资源缓存(由 Next.js 提供)
|
||||||
|
location /_next/static {
|
||||||
|
proxy_pass http://nextjs;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Connection "";
|
||||||
|
expires 365d;
|
||||||
|
add_header Cache-Control "public, immutable";
|
||||||
|
}
|
||||||
|
|
||||||
|
location /static {
|
||||||
|
proxy_pass http://nextjs;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Connection "";
|
||||||
|
expires 365d;
|
||||||
|
add_header Cache-Control "public, immutable";
|
||||||
|
}
|
||||||
|
|
||||||
|
# 图标文件缓存
|
||||||
|
location ~* \.(ico|svg|png|jpg|jpeg|gif|webp)$ {
|
||||||
|
proxy_pass http://nextjs;
|
||||||
|
expires 30d;
|
||||||
|
add_header Cache-Control "public, immutable";
|
||||||
|
}
|
||||||
|
|
||||||
|
# API 路由代理
|
||||||
|
location /api {
|
||||||
|
proxy_pass http://nextjs;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection 'upgrade';
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_cache_bypass $http_upgrade;
|
||||||
|
|
||||||
|
# 超时设置
|
||||||
|
proxy_connect_timeout 60s;
|
||||||
|
proxy_send_timeout 60s;
|
||||||
|
proxy_read_timeout 60s;
|
||||||
|
}
|
||||||
|
|
||||||
|
# 所有其他请求代理到 Next.js(SSR)
|
||||||
|
location / {
|
||||||
|
proxy_pass http://nextjs;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection 'upgrade';
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_cache_bypass $http_upgrade;
|
||||||
|
}
|
||||||
|
|
||||||
|
# gzip
|
||||||
|
gzip on;
|
||||||
|
gzip_vary on;
|
||||||
|
gzip_proxied any;
|
||||||
|
gzip_comp_level 6;
|
||||||
|
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,9 +4,9 @@
|
|||||||
"description": "corp-official-website Next.js 14 client",
|
"description": "corp-official-website Next.js 14 client",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev -p 3001",
|
"dev": "next dev -p 3002",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start -p 3001",
|
"start": "next start -p 3002",
|
||||||
"lint": "next lint",
|
"lint": "next lint",
|
||||||
"format": "prettier --write \"app/**/*.{ts,tsx}\" \"components/**/*.{ts,tsx}\" \"lib/**/*.{ts,tsx}\""
|
"format": "prettier --write \"app/**/*.{ts,tsx}\" \"components/**/*.{ts,tsx}\" \"lib/**/*.{ts,tsx}\""
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user