Deployment #7
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://blog.benoitblanchon.fr/github-action-run-ssh-commands/ | |
name: Deployment | |
on: | |
push: | |
branches: ['main'] | |
workflow_dispatch: | |
inputs: | |
staging: | |
description: 'Production? (otherwise staging)' | |
type: boolean | |
default: true | |
concurrency: | |
group: 'deployment' | |
cancel-in-progress: true | |
jobs: | |
deploy: | |
name: 'Deploy using SSH' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Configure SSH | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "$SSH_KEY" > ~/.ssh/sshkey.key | |
chmod 600 ~/.ssh/sshkey.key | |
cat >>~/.ssh/config <<END | |
Host sshhost | |
HostName $SSH_HOST | |
User $SSH_USER | |
IdentityFile ~/.ssh/sshkey.key | |
StrictHostKeyChecking no | |
SendEnv TARGET_DIR | |
END | |
env: | |
SSH_USER: ${{ inputs.production == true && secrets.PRODUCTION_SSH_USER || secrets.STAGING_SSH_USER }} | |
SSH_KEY: ${{ inputs.production == true && secrets.PRODUCTION_SSH_KEY || secrets.STAGING_SSH_KEY }} | |
SSH_HOST: ${{ inputs.production == true && secrets.PRODUCTION_SSH_HOST || secrets.STAGING_SSH_HOST }} | |
- name: Run deploy commands on remote server | |
run: | | |
ssh sshhost 'echo "target dir 1: $TARGET_DIR"' | |
ssh sshhost TARGET_DIR=$TARGET_DIR 'echo "target dir 2: $TARGET_DIR"' | |
ssh sshhost TARGET_DIR=$TARGET_DIR 'cd "$TARGET_DIR" && pwd' | |
ssh sshhost 'cd $TARGET_DIR && git fetch && git checkout main && git pull && bash check_env.sh && docker compose up -d --no-deps --build backend' | |
ssh sshhost 'df . | awk "NR==2{if(\$4<=20*1024*1024) { system(\"docker system prune -f\") } else { system(\"echo \\\"Enough space left. No need to prune docker.\\\"\") } }"' | |
env: | |
TARGET_DIR: ${{ inputs.production == true && 'WalletServer-production' || 'WalletServer-staging' }} |