From 32d58669c58a7a6c5e75b4e9457d92783c55c5b1 Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Wed, 19 Jun 2024 14:31:24 +0100 Subject: [PATCH] Deploy every commit --- .github/workflows/ci.yml | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d3820d2..638dc20 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,3 +63,69 @@ jobs: - name: 'Run formatter' run: npx prettier --ignore-unknown --check '**' + + push: + name: 'Push image' + runs-on: ubuntu-22.04 + timeout-minutes: 30 + if: github.ref == 'refs/heads/main' + outputs: + image: ${{ steps.image.outputs.image }} + needs: + - build-image + - format + + steps: + - name: 'Set up flyctl' + uses: superfly/flyctl-actions/setup-flyctl@1.5 + + - name: 'Log in to the registry' + run: flyctl auth docker + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} + + - name: 'Download image' + uses: actions/download-artifact@v4.1.7 + with: + name: image + path: /tmp + + - name: 'Load image' + run: docker load --input /tmp/image.tar + + - name: 'Generate image name' + id: image + run: echo "image=registry.fly.io/prereview-stats:${{ github.sha }}" >> $GITHUB_OUTPUT + + - name: 'Tag image' + run: docker tag ${{ needs.build-image.outputs.image }} ${{ steps.image.outputs.image }} + + - name: 'Push image' + run: docker push ${{ steps.image.outputs.image }} + + deploy: + name: 'Deploy (${{ matrix.instance }})' + runs-on: ubuntu-22.04 + timeout-minutes: 30 + if: github.ref == 'refs/heads/main' + needs: + - push + strategy: + fail-fast: false + matrix: + instance: ['prod', 'sandbox'] + + steps: + - name: 'Checkout code' + uses: actions/checkout@v4.1.6 + with: + sparse-checkout: fly.toml + sparse-checkout-cone-mode: false + + - name: 'Set up flyctl' + uses: superfly/flyctl-actions/setup-flyctl@1.5 + + - name: 'Deploy app' + run: flyctl deploy --image ${{ needs.push.outputs.image }} + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}