Auto-deploy the server image to production over SSH after a build
Adds a deploy job to the existing build-and-push workflow: SSHes into the deploy host as a dedicated espressoframeuser account and runs docker compose pull && up -d. Runs only after build-and-push succeeds, using a key/host pulled from repo secrets (DEPLOY_SSH_KEY, DEPLOY_HOST, optional DEPLOY_PORT).
This commit is contained in:
@@ -52,3 +52,21 @@ jobs:
|
||||
tags: |
|
||||
git.thumeit.com/tfaour/espresso-frame-server:latest
|
||||
git.thumeit.com/tfaour/espresso-frame-server:${{ gitea.sha }}
|
||||
|
||||
deploy:
|
||||
needs: build-and-push
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Deploy over SSH
|
||||
env:
|
||||
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT || '22' }}
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "$DEPLOY_SSH_KEY" > ~/.ssh/deploy_key
|
||||
chmod 600 ~/.ssh/deploy_key
|
||||
ssh-keyscan -p "$DEPLOY_PORT" "$DEPLOY_HOST" >> ~/.ssh/known_hosts 2>/dev/null
|
||||
ssh -i ~/.ssh/deploy_key -p "$DEPLOY_PORT" -o StrictHostKeyChecking=yes \
|
||||
espressoframeuser@"$DEPLOY_HOST" \
|
||||
'cd ~/espresso-frame && docker compose pull && docker compose up -d'
|
||||
|
||||
Reference in New Issue
Block a user