Skip to content

Commit 80cb206

Browse files
authored
Add GitHub Actions workflow for GCP deployment
This workflow automates the deployment process to a Google Cloud VM server, including code checkout, authentication, setup, deployment, and verification of services.
1 parent 716c149 commit 80cb206

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

.github/workflows/deploy-jl.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Deploy to GCP Server 2
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Authenticate to Google Cloud
18+
uses: google-github-actions/auth@v2
19+
with:
20+
credentials_json: ${{ secrets.GCP_SA_KEY }}
21+
22+
- name: Setup Google Cloud SDK
23+
uses: google-github-actions/setup-gcloud@v2
24+
with:
25+
project_id: ${{ secrets.GCP_PROJECT_ID }}
26+
27+
- name: Deploy to GCP VM Server 2
28+
env:
29+
GCP_VM_NAME: alfred-server2
30+
GCP_ZONE: us-central1-a
31+
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
32+
run: |
33+
gcloud compute ssh ${GCP_VM_NAME} --zone=${GCP_ZONE} --command="
34+
sudo git config --global --add safe.directory /opt/alfred &&
35+
cd /opt/alfred &&
36+
sudo git fetch origin &&
37+
sudo git reset --hard origin/main &&
38+
sudo git clean -fd -e credentials -e .env &&
39+
sudo chmod +x deployment/deploy.sh &&
40+
sudo ./deployment/deploy.sh
41+
"
42+
43+
- name: Verify deployment
44+
env:
45+
GCP_VM_NAME: alfred-server2
46+
GCP_ZONE: us-central1-a
47+
run: |
48+
# Get VM external IP
49+
EXTERNAL_IP=$(gcloud compute instances describe ${GCP_VM_NAME} \
50+
--zone=${GCP_ZONE} \
51+
--format='get(networkInterfaces[0].accessConfigs[0].natIP)')
52+
53+
echo "Testing services at ${EXTERNAL_IP}..."
54+
55+
# Test health endpoints
56+
sleep 10
57+
curl -f http://${EXTERNAL_IP}:8001/health || exit 1
58+
curl -f http://${EXTERNAL_IP}:8002/health || exit 1
59+
60+
echo "✅ Server 2 deployment verified!"

0 commit comments

Comments
 (0)