From d010af765667ba9ab830a8cac7be7f05b7a7398f Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 17 Apr 2026 21:21:47 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E6=9B=B4=E6=96=B0cicd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/main.yml | 38 ++++++++++++++++++++++++++++++++++++++ Dockerfile | 10 ++++++++++ 2 files changed, 48 insertions(+) create mode 100644 .gitea/workflows/main.yml create mode 100644 Dockerfile diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml new file mode 100644 index 0000000..480b099 --- /dev/null +++ b/.gitea/workflows/main.yml @@ -0,0 +1,38 @@ +name: main + +on: + push: + branches: [main] + +jobs: + main: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: 构建镜像 + run: | + docker build -t react-app . + docker save react-app | gzip > app.tar.gz + + - name: 复制到服务器并运行 + uses: appleboy/scp-action@v0.1.5 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.SSH_KEY }} + source: "app.tar.gz" + target: "/tmp/" + + - name: 部署 + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.SSH_KEY }} + script: | + gunzip -c /tmp/app.tar.gz | docker load + docker stop react-app 2>/dev/null || true + docker rm react-app 2>/dev/null || true + docker run -d --name react-app -p 8080:80 --restart always react-app + rm -f /tmp/app.tar.gz diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..24fcb42 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM node:20-alpine AS builder +WORKDIR /app +COPY package*.json ./ +RUN npm ci +COPY . . +RUN npm run build + +FROM nginx:alpine +COPY --from=builder /app/dist /usr/share/nginx/html +EXPOSE 80 \ No newline at end of file