diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 784e5ed..f27203f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -8,13 +8,79 @@ on: - main jobs: + Docker: + if: ${{ github.repository_owner == 'elixirschool' }} + runs-on: ubuntu-latest + + outputs: + image: ${{ steps.outputs.outputs.image }} + tag: ${{ steps.outputs.outputs.tag }} + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - id: metadata + name: Get Metadata + uses: docker/metadata-action@v5 + with: + flavor: | + latest=auto + github-token: ${{ secrets.GITHUB_TOKEN }} + images: | + ghcr.io/${context.repo.owner}/${context.repo.repo} + tags: | + type=sha + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=ref,event=branch + type=ref,event=pr + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - id: build + name: Build + uses: docker/build-push-action@v6 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + labels: ${{ steps.metadata.outputs.labels }} + platforms: linux/amd64 + push: true + tags: ${{ steps.metadata.outputs.tags }} + + - id: outputs + name: Get Outputs + uses: actions/github-script@v7 + env: + BUILD_OUTPUT: ${{ steps.metadata.outputs.json }} + with: + script: | + const metadata = JSON.parse(process.env.BUILD_OUTPUT) + const shaUrl = metadata.tags.find((t) => t.includes(':sha-')) + + if (shaUrl == null) { + core.error('Unable to find sha tag of image') + } else { + const [image, tag] = shaUrl.split(':') + core.setOutput('image', image) + core.setOutput('tag', tag) + } + Deploy: if: ${{ github.repository_owner == 'elixirschool' }} runs-on: ubuntu-latest + needs: [Docker] steps: - - uses: actions/checkout@v3 - - uses: superfly/flyctl-actions/setup-flyctl@master - - run: flyctl deploy --local-only + - name: Checkout + uses: actions/checkout@v3 + + - name: Install (flyctl) + uses: superfly/flyctl-actions/setup-flyctl@master + + - run: flyctl deploy --yes --image "${{ needs.Docker.outputs.image }}:${{ needs.Docker.outputs.tag }}" env: FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}