Matches the cross-project pattern already applied to authd PR #12, buchinese PR #8, inventory PR #19, and movement PR #16. The pre-emptive `docker compose down` destroyed the running container BEFORE `docker compose up -d --build` had a chance to verify the new image builds — a single npm ci lockfile mismatch (buchinese PR #6, 2026-05-10) was enough to put prod to HTTP 502 for the entire human-intervention turnaround. `docker compose up -d --build` builds first; only on successful build does compose recreate the container. On build failure compose exits non-zero with the previous container still serving traffic. `--remove-orphans` is a drop-in cleanup for renamed/removed services. No test added (no CI-yaml tests exist in this project; matches 4 precedent PRs). Refactor pass expected to be a noop.
56 lines
1.7 KiB
YAML
56 lines
1.7 KiB
YAML
name: "Deploy to birb co. production"
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Check out repository
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Validate required secrets
|
|
run: |
|
|
set -euo pipefail
|
|
: "${SSH_PRIVATE_KEY:?SSH_PRIVATE_KEY secret must be set}"
|
|
: "${JWT_SECRET:?JWT_SECRET secret must be set}"
|
|
env:
|
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
JWT_SECRET: ${{ secrets.JWT_SECRET }}
|
|
|
|
- name: Set up SSH key
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
|
|
chmod 600 ~/.ssh/id_ed25519
|
|
ssh-keyscan ${{ vars.HOST }} >> ~/.ssh/known_hosts
|
|
|
|
- name: Remove directory from server
|
|
run: |
|
|
ssh -i ~/.ssh/id_ed25519 ${{ vars.USERNAME }}@${{ vars.HOST }} << 'EOF'
|
|
rm -rf ~/${{ vars.DIRECTORY_NAME }}
|
|
EOF
|
|
|
|
# Avoid needing to set up SSH access to GitHub for this user
|
|
- name: Transfer repository files to server
|
|
run: |
|
|
scp -i ~/.ssh/id_ed25519 -r ./* ${{ vars.USERNAME }}@${{ vars.HOST }}:~/${{ vars.DIRECTORY_NAME }}
|
|
|
|
- name: Deploy on server with Docker
|
|
run: |
|
|
ssh -i ~/.ssh/id_ed25519 ${{ vars.USERNAME }}@${{ vars.HOST }} << EOF
|
|
cd ~/${{ vars.DIRECTORY_NAME }}
|
|
export JWT_SECRET='${{ secrets.JWT_SECRET }}'
|
|
export TRUST_PROXY=true
|
|
export COOKIE_SECURE=true
|
|
export PORT='${{ vars.PORT }}'
|
|
export BASE_URL='${{ vars.BASE_URL }}'
|
|
export MAX_FILE_SIZE='${{ vars.MAX_FILE_SIZE }}'
|
|
docker compose -f compose.yaml up -d --build --remove-orphans
|
|
EOF
|