Deploy #104
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: Deploy | |
| on: | |
| workflow_run: | |
| workflows: ["CI"] | |
| types: [completed] | |
| branches: [main] | |
| workflow_dispatch: | |
| concurrency: | |
| group: deploy-production | |
| cancel-in-progress: false | |
| env: | |
| IMAGE_NAME: registry.dokku.djbender.com/lizard | |
| GIT_SHA: ${{ github.sha }} | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.runner }} | |
| if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' | |
| environment: production | |
| strategy: | |
| matrix: | |
| include: | |
| - arch: amd64 | |
| runner: ubuntu-24.04 | |
| - arch: arm64 | |
| runner: ubuntu-24.04-arm | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_sha || github.sha }} | |
| - name: Set short SHA | |
| run: echo "GIT_SHA_SHORT=${GIT_SHA::7}" >> "$GITHUB_ENV" | |
| - uses: docker/setup-buildx-action@v4 | |
| - uses: docker/login-action@v4 | |
| with: | |
| registry: registry.dokku.djbender.com | |
| username: ${{ secrets.REGISTRY_USERNAME }} | |
| password: ${{ secrets.REGISTRY_PASSWORD }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| platforms: linux/${{ matrix.arch }} | |
| push: true | |
| tags: ${{ env.IMAGE_NAME }}:${{ env.GIT_SHA_SHORT }}-${{ matrix.arch }} | |
| build-args: | | |
| GIT_SHA=${{ env.GIT_SHA_SHORT }} | |
| cache-from: type=gha,scope=build-${{ matrix.arch }} | |
| cache-to: type=gha,scope=build-${{ matrix.arch }},mode=max | |
| merge: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| environment: production | |
| steps: | |
| - name: Set short SHA | |
| run: echo "GIT_SHA_SHORT=${GIT_SHA::7}" >> "$GITHUB_ENV" | |
| - uses: docker/setup-buildx-action@v4 | |
| - uses: docker/login-action@v4 | |
| with: | |
| registry: registry.dokku.djbender.com | |
| username: ${{ secrets.REGISTRY_USERNAME }} | |
| password: ${{ secrets.REGISTRY_PASSWORD }} | |
| - name: Create multi-arch manifest | |
| run: | | |
| docker buildx imagetools create \ | |
| -t ${{ env.IMAGE_NAME }}:${{ env.GIT_SHA_SHORT }} \ | |
| -t ${{ env.IMAGE_NAME }}:latest \ | |
| ${{ env.IMAGE_NAME }}:${{ env.GIT_SHA_SHORT }}-amd64 \ | |
| ${{ env.IMAGE_NAME }}:${{ env.GIT_SHA_SHORT }}-arm64 | |
| - name: Remove intermediate arch tags | |
| run: | | |
| for arch in amd64 arm64; do | |
| skopeo delete "docker://${{ env.IMAGE_NAME }}:${{ env.GIT_SHA_SHORT }}-$arch" || true | |
| done | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: merge | |
| environment: production | |
| steps: | |
| - name: Set short SHA | |
| run: echo "GIT_SHA_SHORT=${GIT_SHA::7}" >> "$GITHUB_ENV" | |
| - uses: webfactory/ssh-agent@v0.10.0 | |
| with: | |
| ssh-private-key: ${{ secrets.DOKKU_SSH_PRIVATE_KEY }} | |
| - name: Add Dokku to known_hosts | |
| run: ssh-keyscan -p ${{ secrets.DOKKU_PORT }} -H ${{ secrets.DOKKU_HOST }} >> ~/.ssh/known_hosts | |
| - name: Deploy to Dokku | |
| run: | | |
| output=$(ssh -p ${{ secrets.DOKKU_PORT }} dokku@${{ secrets.DOKKU_HOST }} git:from-image lizard ${{ env.IMAGE_NAME }}:${{ env.GIT_SHA_SHORT }} 2>&1 | tee /dev/stderr) && exit 0 | |
| if echo "$output" | grep -q "No changes detected"; then | |
| exit 0 | |
| else | |
| exit 1 | |
| fi |