CI/CD 优化:前端构建产物上传 artifact,VPS 跳过二次 npm run build
This commit is contained in:
@@ -54,25 +54,38 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: npm run 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
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Build Docker image
|
- name: Download frontend build artifact
|
||||||
run: docker build -t polyweather-ci .
|
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
|
- name: Deploy to VPS
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.VPS_SSH_KEY }}" > ~/.ssh/id_rsa
|
echo "${{ secrets.VPS_SSH_KEY }}" > ~/.ssh/id_rsa
|
||||||
chmod 600 ~/.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 }} "
|
ssh -o StrictHostKeyChecking=accept-new ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} "
|
||||||
cd /root/PolyWeather
|
cd /root/PolyWeather
|
||||||
git fetch origin main && git reset --hard origin/main
|
git fetch origin main && git reset --hard origin/main
|
||||||
|
|||||||
@@ -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"]
|
||||||
Reference in New Issue
Block a user