49 lines
1.8 KiB
YAML
49 lines
1.8 KiB
YAML
name: Deploy Backend
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
defaults:
|
|
run:
|
|
shell: sh
|
|
steps:
|
|
- name: Install SSH client
|
|
run: |
|
|
V=$(cut -d'.' -f1-2 /etc/alpine-release)
|
|
echo "https://dl-cdn.alpinelinux.org/alpine/v$V/main" > /etc/apk/repositories
|
|
echo "https://dl-cdn.alpinelinux.org/alpine/v$V/community" >> /etc/apk/repositories
|
|
apk add --no-cache openssh-client
|
|
- name: Setup SSH key
|
|
env:
|
|
SSH_KEY: ${{ secrets.DEPLOY_KEY }}
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
echo "$SSH_KEY" > ~/.ssh/id_ed25519
|
|
chmod 600 ~/.ssh/id_ed25519
|
|
ssh-keyscan -p 2234 -H 172.17.0.1 >> ~/.ssh/known_hosts
|
|
- name: Reconcile reviewed deployment wrapper and deploy
|
|
env:
|
|
RELEASE_SHA: ${{ gitea.sha }}
|
|
run: |
|
|
case "$RELEASE_SHA" in ''|*[!0-9a-f]*) exit 1;; esac
|
|
test "${#RELEASE_SHA}" = 40
|
|
ssh -p 2234 devops@172.17.0.1 "bash -s -- $RELEASE_SHA" <<'REMOTE'
|
|
set -euo pipefail
|
|
expected=$1
|
|
cd /opt/services/parsa/backend/repo
|
|
test -z "$(git status --porcelain --untracked-files=normal)"
|
|
export GIT_SSH_COMMAND='ssh -i /home/devops/.ssh/deploy_key -o StrictHostKeyChecking=no'
|
|
git fetch origin main
|
|
test "$(git rev-parse origin/main)" = "$expected"
|
|
git merge --ff-only "$expected"
|
|
test "$(git rev-parse HEAD)" = "$expected"
|
|
python3 tests/deploy_fixture.py
|
|
bash -n ops/deploy-backend.sh
|
|
# CI owns the host wrapper; never execute the old untracked implementation.
|
|
sudo install -m 0755 ops/deploy-backend.sh /opt/services/parsa/backend/deploy.sh
|
|
bash /opt/services/parsa/backend/deploy.sh "$expected"
|
|
REMOTE
|