ci: deploy

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-09-21 23:26:01 +08:00
parent f67d8d3797
commit 9e162bd595
4 changed files with 81 additions and 49 deletions
-22
View File
@@ -1,22 +0,0 @@
name: Deploy to Cloudflare
on:
push:
branches: [qas]
paths:
- 'apps/api/**'
- 'docker-compose.yml'
- 'pnpm-workspace.yaml'
workflow_dispatch: {}
jobs:
deploy:
# Runner lives on the same home machine (ux) that Cloudflare Tunnel
# already points at — no WireGuard/SSH hop needed like the droplet
# workflow, the runner IS the target.
runs-on: [self-hosted, ux]
steps:
- uses: actions/checkout@v4
- name: Rebuild and restart backend
run: docker compose up -d --build backend
+79 -26
View File
@@ -1,47 +1,100 @@
name: Deploy to droplet name: Deploy to production droplet
on: on:
push: push:
branches: [main] branches: [main]
paths:
- 'apps/api/**'
- 'docker-compose.yml'
- 'pnpm-workspace.yaml'
workflow_dispatch: {} workflow_dispatch: {}
concurrency:
group: production-deployment
cancel-in-progress: true
jobs: jobs:
deploy: deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
# nodejs-api only accepts SSH over its WireGuard tunnel (public :22 was - name: Check out source
# removed). This peer is scoped to AllowedIPs 10.100.1.3/32 on the uses: actions/checkout@v4
# droplet side, so it can only ever reach 10.100.1.1 — nothing else.
- name: Bring up WireGuard tunnel - name: Install WireGuard
run: | run: |
sudo apt-get update -y sudo apt-get update -y
sudo apt-get install -y wireguard-tools sudo apt-get install -y wireguard-tools
# The CI peer must be configured on the droplet's wg0 interface:
# PublicKey = <public key matching CI_WG_PRIVATE_KEY>
# AllowedIPs = 10.100.2.11/32
- name: Bring up production WireGuard tunnel
env:
CI_WG_PRIVATE_KEY: ${{ secrets.CI_WG_PRIVATE_KEY }}
DROPLET_WG_PUBLIC_KEY: ${{ secrets.DROPLET_WG_PUBLIC_KEY }}
run: |
set -Eeuo pipefail
umask 077 umask 077
sudo mkdir -p /etc/wireguard sudo mkdir -p /etc/wireguard
cat <<EOF | sudo tee /etc/wireguard/wg0.conf > /dev/null cat <<EOF | sudo tee /etc/wireguard/new-starr-ci.conf > /dev/null
[Interface] [Interface]
PrivateKey = ${{ secrets.CI_WG_PRIVATE_KEY }} PrivateKey = ${CI_WG_PRIVATE_KEY}
Address = 10.100.1.3/32 Address = 10.100.2.11/32
[Peer] [Peer]
PublicKey = ${{ secrets.NODEJS_API_WG_PUBLIC_KEY }} PublicKey = ${DROPLET_WG_PUBLIC_KEY}
Endpoint = 68.183.239.171:51820 Endpoint = 161.35.103.214:51820
AllowedIPs = 10.100.1.1/32 AllowedIPs = 10.100.2.1/32
PersistentKeepalive = 25 PersistentKeepalive = 25
EOF EOF
sudo wg-quick up wg0 sudo wg-quick up /etc/wireguard/new-starr-ci.conf
# The key below is restricted server-side to only run - name: Configure SSH
# /opt/new_starr/deploy.sh (see authorized_keys forced-command on the env:
# droplet) — it can't run arbitrary commands even if this secret leaks. DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
- name: Deploy via SSH run: |
uses: appleboy/ssh-action@v1 set -Eeuo pipefail
with: install -d -m 700 "$HOME/.ssh"
host: 10.100.1.1 printf '%s\n' "$DEPLOY_SSH_KEY" > "$HOME/.ssh/new-starr-deploy"
username: deploy chmod 600 "$HOME/.ssh/new-starr-deploy"
key: ${{ secrets.DEPLOY_SSH_KEY }} ssh-keyscan -H 10.100.2.1 >> "$HOME/.ssh/known_hosts"
script: deploy
- name: Build frontend bundle
run: |
set -Eeuo pipefail
scp -i "$HOME/.ssh/new-starr-deploy" \
-o IdentitiesOnly=yes \
starr-deploy@10.100.2.1:/home/starr-deploy/new_starr/apps/web/.env \
apps/web/.env
corepack enable
corepack prepare pnpm@11.3.0 --activate
pnpm install --no-frozen-lockfile
pnpm --filter web build
- name: Upload source
run: |
set -Eeuo pipefail
tar \
--exclude=.git \
--exclude=node_modules \
--exclude='apps/api/.env' \
--exclude='apps/web/.env' \
-czf - . |
ssh -i "$HOME/.ssh/new-starr-deploy" \
-o IdentitiesOnly=yes \
starr-deploy@10.100.2.1 \
'rm -rf "$HOME/new_starr-release" && mkdir -p "$HOME/new_starr-release" && tar -xzf - -C "$HOME/new_starr-release"'
- name: Build and restart production stack
run: |
set -Eeuo pipefail
ssh -i "$HOME/.ssh/new-starr-deploy" \
-o IdentitiesOnly=yes \
starr-deploy@10.100.2.1 <<'REMOTE'
set -Eeuo pipefail
cd "$HOME/new_starr-release"
test -f "$HOME/new_starr/apps/api/.env"
test -f "$HOME/new_starr/apps/web/.env"
test -f "$HOME/new_starr/.env"
cp "$HOME/new_starr/apps/api/.env" apps/api/.env
cp "$HOME/new_starr/apps/web/.env" apps/web/.env
cp "$HOME/new_starr/.env" .env
docker compose up -d --build
docker compose ps
REMOTE
+1 -1
View File
@@ -10,7 +10,7 @@ RUN npm install -g pm2 sequelize-cli
# Typst — compiles certificate.typ into the downloadable PDF certificate. # Typst — compiles certificate.typ into the downloadable PDF certificate.
# Not available as an apk package, so lift the binary out of pandoc/typst. # Not available as an apk package, so lift the binary out of pandoc/typst.
COPY --from=typst /usr/bin/typst /usr/local/bin/typst COPY --from=typst /usr/local/bin/typst /usr/local/bin/typst
WORKDIR /app WORKDIR /app
+1
View File
@@ -1,5 +1,6 @@
packages: packages:
- "apps/*" - "apps/*"
allowBuilds: allowBuilds:
"@parcel/watcher": true
unrs-resolver: true unrs-resolver: true
msw: true msw: true