Deployment #82
This file contains hidden or 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
| name: Deployment | |
| concurrency: | |
| group: staging | |
| cancel-in-progress: true | |
| on: | |
| workflow_run: | |
| workflows: [CI] | |
| branches: | |
| - main | |
| types: | |
| - completed | |
| workflow_dispatch: | |
| jobs: | |
| deployment: | |
| runs-on: ubuntu-latest | |
| # only run if CI workflow completed successfully | |
| # https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#running-a-workflow-based-on-the-conclusion-of-another-workflow | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| environment: staging | |
| steps: | |
| - name: Deploy | |
| env: | |
| SSH_HOST: ${{ secrets.SSH_HOST }} | |
| SSH_PORT: ${{ secrets.SSH_PORT }} | |
| SSH_USER: ${{ secrets.SSH_USER }} | |
| SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
| shell: bash | |
| run: | | |
| mkdir ~/.ssh | |
| echo "Launching SSH agent..." | |
| eval "$(ssh-agent -s)" | |
| echo "Adding private key..." | |
| echo "$SSH_PRIVATE_KEY" | ssh-add - | |
| echo "Adding SSH host to known hosts..." | |
| ssh-keyscan -p "$SSH_PORT" "$SSH_HOST" >> ~/.ssh/known_hosts 2> /dev/null | |
| echo "Connecting via SSH and executing commands" | |
| ssh -p "$SSH_PORT" "$SSH_USER@$SSH_HOST" "cd website && git fetch && git reset --hard origin/main && docker compose -f compose.production.yaml build app && docker compose -f compose.production.yaml up -d" |