|
| 1 | +# Ship every merge to dev2, where pairux.com runs since it left Railway (which |
| 2 | +# deployed on merge by itself). The box pulls the merged commit, rebuilds the |
| 3 | +# image(s) from this repo and restarts the compose stack under |
| 4 | +# /home/anthony/www/pairux.com. Generated by cli-tools/dev2/dev2-site scaffold. |
| 5 | +name: Deploy to dev2 |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: [master] |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + ref: |
| 13 | + description: Git ref to deploy (defaults to the pushed commit) |
| 14 | + required: false |
| 15 | + type: string |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: deploy-dev2 |
| 19 | + cancel-in-progress: false |
| 20 | + |
| 21 | +jobs: |
| 22 | + deploy: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + timeout-minutes: 45 |
| 25 | + steps: |
| 26 | + # ${{ }} values go through env, never straight into a run: body. |
| 27 | + - name: Resolve target revision |
| 28 | + id: rev |
| 29 | + env: |
| 30 | + REF: ${{ inputs.ref || github.sha }} |
| 31 | + run: echo "sha=$REF" >> "$GITHUB_OUTPUT" |
| 32 | + |
| 33 | + - name: Set up ssh |
| 34 | + env: |
| 35 | + SSH_KEY: ${{ secrets.DEV2_SSH_KEY }} |
| 36 | + KNOWN_HOSTS: ${{ secrets.DEV2_KNOWN_HOSTS }} |
| 37 | + run: | |
| 38 | + install -d -m 700 ~/.ssh |
| 39 | + printf '%s\n' "$SSH_KEY" > ~/.ssh/id_ed25519 |
| 40 | + chmod 600 ~/.ssh/id_ed25519 |
| 41 | + printf '%s\n' "$KNOWN_HOSTS" > ~/.ssh/known_hosts |
| 42 | + chmod 644 ~/.ssh/known_hosts |
| 43 | +
|
| 44 | + - name: Deploy |
| 45 | + env: |
| 46 | + DEV2_USER: ${{ secrets.DEV2_USER }} |
| 47 | + DEV2_HOST: ${{ secrets.DEV2_HOST }} |
| 48 | + SHA: ${{ steps.rev.outputs.sha }} |
| 49 | + run: | |
| 50 | + ssh -o BatchMode=yes "$DEV2_USER@$DEV2_HOST" \ |
| 51 | + /home/anthony/www/pairux.com/deploy-app.sh "$SHA" |
| 52 | +
|
| 53 | + - name: Verify the site answers |
| 54 | + run: | |
| 55 | + for i in $(seq 1 10); do |
| 56 | + code=$(curl -s -o /dev/null -w '%{http_code}' "https://pairux.com/api/health" || true) |
| 57 | + case "$code" in 2*|3*|401|403) echo "pairux.com $code"; exit 0;; esac |
| 58 | + echo "attempt $i: $code"; sleep 10 |
| 59 | + done |
| 60 | + echo "pairux.com never answered"; exit 1 |
0 commit comments