From d088ff389a292ebe9f482672f7e8ded0d0adb3d1 Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Tue, 26 May 2026 02:39:02 +0800 Subject: [PATCH] =?UTF-8?q?CI/CD=20=E4=BC=98=E5=8C=96=EF=BC=9A=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E6=9E=84=E5=BB=BA=E4=BA=A7=E7=89=A9=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=20artifact=EF=BC=8CVPS=20=E8=B7=B3=E8=BF=87=E4=BA=8C=E6=AC=A1?= =?UTF-8?q?=20npm=20run=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 29 +++++++++++++++++++++-------- frontend/prod.Dockerfile | 22 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 frontend/prod.Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2693003c..6a1a5932 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,25 +54,38 @@ jobs: - name: Build run: npm run build - docker-build: + - name: Upload frontend build artifact + uses: actions/upload-artifact@v4 + with: + name: frontend-next + path: | + frontend/.next + frontend/package.json + frontend/package-lock.json + frontend/next.config.mjs + frontend/public + !frontend/.next/cache + + deploy: + needs: [python-quality, frontend-quality] + if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - - name: Build Docker image - run: docker build -t polyweather-ci . + - name: Download frontend build artifact + uses: actions/download-artifact@v4 + with: + name: frontend-next + path: frontend - deploy: - needs: [python-quality, frontend-quality, docker-build] - if: github.event_name == 'push' && github.ref == 'refs/heads/main' - runs-on: ubuntu-latest - steps: - name: Deploy to VPS run: | mkdir -p ~/.ssh echo "${{ secrets.VPS_SSH_KEY }}" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa + scp -o StrictHostKeyChecking=accept-new -r frontend/.next frontend/package.json frontend/package-lock.json frontend/next.config.mjs ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }}:/root/PolyWeather/frontend/ ssh -o StrictHostKeyChecking=accept-new ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} " cd /root/PolyWeather git fetch origin main && git reset --hard origin/main diff --git a/frontend/prod.Dockerfile b/frontend/prod.Dockerfile new file mode 100644 index 00000000..ba07e183 --- /dev/null +++ b/frontend/prod.Dockerfile @@ -0,0 +1,22 @@ +FROM node:20-alpine + +ARG NEXT_PUBLIC_SUPABASE_URL +ARG NEXT_PUBLIC_SUPABASE_ANON_KEY +ARG NEXT_PUBLIC_SITE_URL +ARG NEXT_PUBLIC_POLYWEATHER_API_BASE_URL +ARG NEXT_PUBLIC_POLYWEATHER_LOCAL_FULL_ACCESS + +ENV NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL +ENV NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY +ENV NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL +ENV NEXT_PUBLIC_POLYWEATHER_API_BASE_URL=$NEXT_PUBLIC_POLYWEATHER_API_BASE_URL +ENV NEXT_PUBLIC_POLYWEATHER_LOCAL_FULL_ACCESS=$NEXT_PUBLIC_POLYWEATHER_LOCAL_FULL_ACCESS + +WORKDIR /app/frontend +COPY package.json package-lock.json ./ +RUN npm ci +COPY .next .next/ +COPY public public/ +COPY next.config.mjs ./ +EXPOSE 3000 +CMD ["npm", "run", "start"]