From e127865e4d8a80db9b51c9023b98bd75c71d7233 Mon Sep 17 00:00:00 2001 From: yinxue <2643126914@qq.com> Date: Tue, 21 Oct 2025 20:26:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B7=A5=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci.yaml | 38 ++++++++++++++++++++++++++++++++++++++ Dockerfile | 21 +++++++++++++++++++++ nginx.conf | 21 +++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 .gitea/workflows/ci.yaml create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml new file mode 100644 index 0000000..d83daa5 --- /dev/null +++ b/.gitea/workflows/ci.yaml @@ -0,0 +1,38 @@ +name: CI Pipeline + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + container: + image: gitea/runner-images:ubuntu-latest + steps: + - name: 拉取代码 + uses: https://devstar.cn/actions/checkout@v4 + with: + fetch-depth: 0 + + - name: 安装依赖 + working-directory: + run: | + npm install + npm add -D vitepress + + - name: 构建项目 + working-directory: + run: | + chmod +x node_modules/.bin/vitepress + npm run docs:build + + - name: 构建 Docker 镜像 + run: | + docker build -t mengningsoftware-docs:${{ gitea.sha }} . + + - name: 登录 Docker Registry 并推送镜像 + run: | + echo "${{ secrets.DOCKER_REGISTRY_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_REGISTRY_USERNAME }} ${{ vars.DOCKER_REGISTRY_ADDRESS }} --password-stdin + docker tag mengningsoftware-docs:${{ gitea.sha }} ${{ vars.DOCKER_REGISTRY_ADDRESS }}/mengningsoftware/docs:${{ gitea.sha }} + docker tag mengningsoftware-docs:${{ gitea.sha }} ${{ vars.DOCKER_REGISTRY_ADDRESS }}/mengningsoftware/docs:latest + docker push ${{ vars.DOCKER_REGISTRY_ADDRESS }}/mengningsoftware/docs:${{ gitea.sha }} + docker push ${{ vars.DOCKER_REGISTRY_ADDRESS }}/mengningsoftware/docs:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..06903bf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +# 第一阶段:node镜像打包 +FROM node:20-alpine AS frontend-builder +WORKDIR /build-app +COPY . . +RUN npm install +RUN npm add -D vitepress +RUN npm run docs:build + +# 第二阶段:nginx打包 +FROM nginx:1.25-alpine +EXPOSE 80 +WORKDIR /app +# 替换nginx配置 +COPY nginx.conf /etc/nginx/conf.d/default.conf +# 将第一阶段的静态文件复制到nginx中 +RUN rm -rf /usr/share/nginx/html +RUN mkdir /usr/share/nginx/html +COPY --from=frontend-builder /build-app/docs/.vitepress/dist /usr/share/nginx/html + +# 运行 +CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..c480c0c --- /dev/null +++ b/nginx.conf @@ -0,0 +1,21 @@ +server { + listen 80; + listen [::]:80; + server_name localhost; + + access_log /var/log/nginx/host.access.log main; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + + # 新增下面这句,其他是默认nginx配置 + # 解决部分前端框架的路由问题,在浏览器刷新报错404 + try_files $uri $uri/ /index.html; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +}