Stand ec2c26174f253857f5e9e86d7f1cfce063ca4b66 #5
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: Stand Stack | |
| run-name: Stand ${{ github.sha }} | |
| on: | |
| workflow_dispatch: | |
| env: | |
| REGISTRY: ghcr.io | |
| SERVER_IMAGE_NAME: ${{ github.repository }}/server | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.run_attempt == 1 }} | |
| permissions: | |
| contents: read | |
| packages: write | |
| deployments: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: rlespinasse/github-slug-action@v5 | |
| ################################################################ | |
| # Server Build | |
| - uses: docker/setup-buildx-action@v3 #https://github.com/marketplace/actions/docker-setup-buildx | |
| - uses: docker/login-action@v3 #https://github.com/marketplace/actions/docker-login | |
| if: github.event_name != 'pull_request' | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: docker/metadata-action@v5 #https://github.com/marketplace/actions/docker-metadata-action | |
| id: meta | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.SERVER_IMAGE_NAME }} | |
| tags: | | |
| type=sha | |
| - uses: docker/build-push-action@v6 #https://github.com/marketplace/actions/build-and-push-docker-images | |
| with: | |
| context: . | |
| file: src/Server/Dockerfile | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| #TODO: sign the published docker image | |
| ################################################################ | |
| # Stand Deploy (custom docker stack deploy step much faster than docker-stack-deploy action) | |
| - uses: ./.github/composites/deploy-begin | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| environment: stand-${{ env.GITHUB_REF_POINT_SLUG }} | |
| - uses: ./.github/composites/remote-deploy | |
| env: | |
| # environment variables that are used for compose | |
| STAND_NAME: ${{ env.GITHUB_REF_POINT_SLUG }} | |
| STACK_NAME: stand-${{ env.GITHUB_REF_POINT_SLUG }} | |
| SERVER_NAME: ${{ secrets.REMOTE_HOST }} | |
| SERVER_IMAGE: ${{ steps.meta.outputs.tags }} | |
| TURN_USERNAME: ${{ secrets.TURN_USERNAME }} | |
| TURN_PASSWORD: ${{ secrets.TURN_PASSWORD }} | |
| with: | |
| ssh_user: ${{ secrets.REMOTE_USER }} | |
| ssh_host: ${{ secrets.REMOTE_HOST }} | |
| ssh_private_key: ${{ secrets.REMOTE_PRIVATE_KEY }} | |
| step_name: Deploy Stand Stack STAND_NAME=${{ env.STAND_NAME }} STACK_NAME=${{ env.STACK_NAME }} | |
| step_run: | | |
| #### stand stack deploy | |
| set -x | |
| clean_deployment_id ${{ env.STACK_NAME }} | |
| docker stack deploy \ | |
| --with-registry-auth \ | |
| -c compose.yaml \ | |
| -c compose.release.yaml \ | |
| ${{ env.STACK_NAME }} | |
| save_deployment_id ${{ env.STACK_NAME }} | |
| # deploy test pages | |
| COMMIT_SHA=$GITHUB_SHA_SHORT #${COMMIT_SHA:0:7} | |
| COMMIT_DATETIME=$(git log -1 --format=%cd "--date=format:%Y-%m-%d %H:%M:%S") #$(date -u +"%Y-%m-%d %H:%M:%S") | |
| sed -i "s/\$COMMIT_SHA/${COMMIT_SHA}/g" pages/index.html | |
| sed -i "s/\$COMMIT_DATETIME/${COMMIT_DATETIME}/g" pages/index.html | |
| scp -r pages/ $SSH_TARGET:. | |
| - uses: ./.github/composites/deploy-status | |
| if: always() | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| state: ${{ job.status }} | |
| ################################################################ | |
| # Stand Stop | |
| stop: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.run_attempt > 1 }} | |
| permissions: | |
| deployments: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| sparse-checkout: .github/ | |
| - uses: rlespinasse/github-slug-action@v5 | |
| - uses: ./.github/composites/remote-deploy | |
| env: | |
| STACK_NAME: stand-${{ env.GITHUB_REF_POINT_SLUG }} | |
| with: | |
| ssh_user: ${{ secrets.REMOTE_USER }} | |
| ssh_host: ${{ secrets.REMOTE_HOST }} | |
| ssh_private_key: ${{ secrets.REMOTE_PRIVATE_KEY }} | |
| step_name: Stop Stand Stack STACK_NAME=${{ env.STACK_NAME }} | |
| step_run: | | |
| #### stop deployment | |
| set -x | |
| load_deployment_id ${{ env.STACK_NAME }} | |
| docker stack rm ${{ env.STACK_NAME }} | |
| - uses: ./.github/composites/deploy-status | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| state: 'inactive' |