-
Notifications
You must be signed in to change notification settings - Fork 1.8k
112 lines (92 loc) · 3.58 KB
/
deploy.yml
File metadata and controls
112 lines (92 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Deploy to GCP (Singapore)
# Triggers on every push to main, or manually from the Actions tab.
on:
push:
branches: [main]
workflow_dispatch:
# ── GitHub repository secrets (Settings → Secrets) ───────────────────────────
# VM_IP – 34.142.253.116 (reserved static IP, whitelist in Binance)
# VM_SSH_PRIVATE_KEY – ed25519 private key for the ubuntu user on the VM
# VM_USER – SSH user (ubuntu)
# GHCR_OWNER – GitHub username that owns the package (lukecold)
env:
IMAGE: ghcr.io/${{ secrets.GHCR_OWNER || github.repository_owner }}/valuecell
DEPLOY_DIR: /opt/valuecell
jobs:
build-and-push:
name: Build & Push image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # push to GHCR
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push (linux/amd64 – e2-micro is x86)
uses: docker/build-push-action@v6
with:
context: .
file: docker/Dockerfile.cloud
platforms: linux/amd64
push: true
build-args: |
VITE_API_BASE_URL=/api/v1
tags: |
${{ env.IMAGE }}:latest
${{ env.IMAGE }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
name: Deploy to GCE VM
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Checkout (for docker-compose.yml)
uses: actions/checkout@v4
- name: Copy docker-compose.yml to VM
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.VM_IP }}
username: ${{ secrets.VM_USER }}
key: ${{ secrets.VM_SSH_PRIVATE_KEY }}
source: cloud/docker-compose.yml
target: ${{ env.DEPLOY_DIR }}
strip_components: 1
- name: Pull new image and restart
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.VM_IP }}
username: ${{ secrets.VM_USER }}
key: ${{ secrets.VM_SSH_PRIVATE_KEY }}
script: |
set -euo pipefail
cd ${{ env.DEPLOY_DIR }}
mkdir -p data
# Log in to GHCR so Docker can pull the image
echo "${{ secrets.GITHUB_TOKEN }}" | \
docker login ghcr.io -u ${{ github.actor }} --password-stdin
GHCR_OWNER=${{ secrets.GHCR_OWNER || github.repository_owner }} \
docker compose pull
GHCR_OWNER=${{ secrets.GHCR_OWNER || github.repository_owner }} \
docker compose --env-file .env up -d --remove-orphans
docker image prune -f
sleep 5
curl -sf http://localhost:8080/api/v1/healthz \
&& echo "✓ Health check passed" \
|| echo "✗ Health check failed – run: docker logs valuecell"
- name: Summary
run: |
echo "### Deployed to GCP Singapore (asia-southeast1)" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "**URL**: http://${{ secrets.VM_IP }}:8080" >> "$GITHUB_STEP_SUMMARY"
echo "**Fixed IP** (whitelist in Binance): \`${{ secrets.VM_IP }}\`" >> "$GITHUB_STEP_SUMMARY"