From a2af7c4d60f7ea186e28a375a91560c96ddb852c Mon Sep 17 00:00:00 2001 From: Jim Segal Date: Fri, 18 Oct 2024 11:47:59 -0500 Subject: [PATCH] update deploy action to use ghcr (#702) --- .github/workflows/deploy.yml | 83 ++++++++++++++++++++++++++++++++++-- Dockerfile | 4 +- 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b7601569..b5518ad1 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -8,13 +8,90 @@ on: - main jobs: + Docker: + if: ${{ github.repository_owner == 'beam-community' }} + runs-on: ubuntu-latest + + outputs: + image: ${{ steps.outputs.outputs.image }} + tag: ${{ steps.outputs.outputs.tag }} + + permissions: + contents: read + packages: write + + 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/${{ github.repository }} + 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 + + - name: Login (GHCR) + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - 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 == 'beam-community' }} runs-on: ubuntu-latest + needs: [Docker] steps: - - uses: actions/checkout@v3 - - uses: superfly/flyctl-actions/setup-flyctl@master - - run: flyctl deploy --remote-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 }} diff --git a/Dockerfile b/Dockerfile index 9cfc138d..0ce1b624 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,9 +8,9 @@ # This file is based on these images: # # - https://hub.docker.com/r/hexpm/elixir/tags - for the build image -# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20210902-slim - for the release image +# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20240812-slim - for the release image # - https://pkgs.org/ - resource for finding needed packages -# - Ex: hexpm/elixir:1.14.1-erlang-25.0-debian-bullseye-20210902-slim +# - Ex: hexpm/elixir:1.14.1-erlang-25.0-debian-bullseye-20240812-slim # ARG ELIXIR_VERSION=1.17.2 ARG OTP_VERSION=27.0.1