|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["build.yml"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + |
| 9 | +jobs: |
| 10 | + deploy: |
| 11 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Set deployment variables |
| 19 | + id: vars |
| 20 | + # set to feature/continuous for now, must be staging |
| 21 | + run: | |
| 22 | + if [[ "${{ github.event.workflow_run.head_branch }}" == "feature/continuous" ]]; then |
| 23 | + echo "target_dir=~/ladder-staging-new" >> "$GITHUB_OUTPUT" |
| 24 | + echo "compose_file=docker-compose.yml" >> "$GITHUB_OUTPUT" |
| 25 | + elif [[ "${{ github.event.workflow_run.head_branch }}" == "main" ]]; then |
| 26 | + echo "target_dir=~/ladder" >> "$GITHUB_OUTPUT" |
| 27 | + echo "compose_file=docker-compose.yml" >> "$GITHUB_OUTPUT" |
| 28 | + else |
| 29 | + echo "Unsupported branch" |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | +
|
| 33 | + - name: Copy compose file to server |
| 34 | + uses: appleboy/scp-action@v0.1.7 |
| 35 | + with: |
| 36 | + host: ${{ secrets.SSH_HOST }} |
| 37 | + username: ${{ secrets.SSH_USER }} |
| 38 | + key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 39 | + source: ${{ steps.vars.outputs.compose_file }} |
| 40 | + target: ${{ steps.vars.outputs.target_dir }} |
| 41 | + |
| 42 | + - name: Stop and start app on server |
| 43 | + uses: appleboy/ssh-action@v1.2.1 |
| 44 | + with: |
| 45 | + host: ${{ secrets.SSH_HOST }} |
| 46 | + username: ${{ secrets.SSH_USER }} |
| 47 | + key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 48 | + script: | |
| 49 | + cd ${{ steps.vars.outputs.target_dir }} |
| 50 | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin |
| 51 | + docker compose -f ${{ steps.vars.outputs.compose_file }} down |
| 52 | + docker compose -f ${{ steps.vars.outputs.compose_file }} pull |
| 53 | + docker compose -f ${{ steps.vars.outputs.compose_file }} up -d |
0 commit comments