Files
uiogaming.no/.github/workflows/deploy.yml
T
leanderandClaude Opus 5.5 773d21b709 Shorten deploy downtime and limit workflow permissions
Build the new image before replacing the running container instead of
stopping the site first, prune old images, prevent overlapping deploys,
and drop the unused pull-requests permission.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 22:40:21 +01:00

35 lines
1.0 KiB
YAML

name: Deploy
on:
push:
branches:
- main
# Let a running deploy finish before the next one starts
concurrency:
group: deploy
cancel-in-progress: false
jobs:
run_pull:
runs-on: ubuntu-latest
steps:
- name: Set up SSH
run: |
install -m 600 -D /dev/null ~/.ssh/id_ed25519
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519 # This should be redundant but seems to do the trick.
ssh-keyscan -H ${{ vars.SSH_HOST }} > ~/.ssh/known_hosts
# up --build builds the new image while the old container keeps serving,
# then swaps the container. Old images are pruned so they don't fill the disk
- name: Connect, pull, build and deploy
run: ssh ${{ secrets.SSH_USER }}@${{ vars.SSH_HOST }} "cd ${{ secrets.WORK_DIR }} && git checkout ${{ vars.MAIN_BRANCH }} && git pull && docker compose up -d --build && docker image prune -f && exit"
- name: Clean up
run: rm -rf ~/.ssh
permissions:
contents: read