添加工作流

This commit is contained in:
2025-10-21 20:26:25 +08:00
parent dd9cc60ceb
commit e127865e4d
3 changed files with 80 additions and 0 deletions

38
.gitea/workflows/ci.yaml Normal file
View File

@@ -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

21
Dockerfile Normal file
View File

@@ -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;"]

21
nginx.conf Normal file
View File

@@ -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;
}
}