1+ name : Contribution Manager App - VPS
2+
3+ on :
4+ push :
5+ branches : [ master, main ]
6+ paths :
7+ - ' src/**'
8+ - ' public/**'
9+ - ' package.json'
10+ - ' package-lock.json'
11+ - ' next.config.ts'
12+ - ' tailwind.config.ts'
13+ - ' tsconfig.json'
14+ - ' deploy/Dockerfile.c-m-app'
15+ - ' .github/workflows/Contribution.Manager.VPS.yaml'
16+
17+ env :
18+ SERVICE_NAME : frontend
19+ IMAGE : ghcr.io/${{ github.repository_owner }}/contribution-manager-app
20+ DOCKERFILE : deploy/Dockerfile.c-m-app
21+ NODE_VERSION : ' 22.x'
22+
23+ permissions :
24+ contents : read
25+ packages : write
26+
27+ jobs :
28+ build-and-push :
29+ runs-on : ubuntu-latest
30+ steps :
31+ - name : Checkout
32+ uses : actions/checkout@v4
33+
34+ - name : Set up QEMU (multiarch)
35+ uses : docker/setup-qemu-action@v3
36+
37+ - name : Set up Docker Buildx
38+ uses : docker/setup-buildx-action@v3
39+
40+ - name : Login to GHCR
41+ uses : docker/login-action@v3
42+ with :
43+ registry : ghcr.io
44+ username : ${{ github.actor }}
45+ password : ${{ secrets.GHCR_PAT }}
46+
47+ - name : Extract metadata
48+ id : meta
49+ uses : docker/metadata-action@v5
50+ with :
51+ images : ${{ env.IMAGE }}
52+ tags : |
53+ type=ref,event=branch
54+ type=ref,event=pr
55+ type=sha,prefix={{branch}}-
56+ type=raw,value=latest,enable={{is_default_branch}}
57+
58+ - name : Build and push Docker image
59+ uses : docker/build-push-action@v5
60+ with :
61+ context : .
62+ file : ${{ env.DOCKERFILE }}
63+ push : true
64+ tags : ${{ steps.meta.outputs.tags }}
65+ labels : ${{ steps.meta.outputs.labels }}
66+ platforms : linux/amd64,linux/arm64
67+ cache-from : type=gha
68+ cache-to : type=gha,mode=max
69+ build-args : |
70+ NODE_ENV=production
71+ NEXT_PUBLIC_FIREBASE_API_KEY=${{ secrets.NEXT_PUBLIC_FIREBASE_API_KEY }}
72+ NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=${{ secrets.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN }}
73+ NEXT_PUBLIC_FIREBASE_PROJECT_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_PROJECT_ID }}
74+ NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=${{ secrets.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET }}
75+ NEXT_PUBLIC_FIREBASE_FIRESTORE_DATABASE=${{ secrets.NEXT_PUBLIC_FIREBASE_FIRESTORE_DATABASE }}
76+ NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID }}
77+ NEXT_PUBLIC_FIREBASE_APP_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_APP_ID }}
78+ NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID }}
79+ NEXT_PUBLIC_CONTRIBUTION_API_URL=${{ secrets.NEXT_PUBLIC_CONTRIBUTION_API_URL }}
80+ secrets : |
81+ google_credentials=${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}
82+
83+ deploy :
84+ needs : build-and-push
85+ runs-on : ubuntu-latest
86+ steps :
87+ - name : Deploy to VPS
88+ 89+ with :
90+ host : ${{ secrets.VPS_HOST }}
91+ username : ${{ secrets.VPS_USER }}
92+ key : ${{ secrets.SSH_PRIVATE_KEY }}
93+ script : |
94+ set -e
95+ echo "Deploying Manager App..."
96+
97+ # Login to GHCR
98+ echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
99+
100+ # Navigate to app directory
101+ cd /srv/app || exit 1
102+
103+ # Create Google credentials file if it doesn't exist
104+ if [ ! -f "/srv/app/.secrets/google-credentials.json" ]; then
105+ mkdir -p /srv/app/.secrets
106+ echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}" | base64 --decode > /srv/app/.secrets/google-credentials.json
107+ chmod 600 /srv/app/.secrets/google-credentials.json
108+ fi
109+
110+ # Pull latest images
111+ docker compose pull ${{ env.SERVICE_NAME }}
112+
113+ # Restart the service
114+ docker compose up -d ${{ env.SERVICE_NAME }}
115+
116+ # Clean up old images
117+ docker image prune -f
118+
119+ echo "Manager App deployed successfully!"
0 commit comments