Skip to content

Commit

Permalink
update deploy action to use ghcr (#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsegal205 authored Oct 18, 2024
1 parent a44c38d commit a2af7c4
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 5 deletions.
83 changes: 80 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a2af7c4

Please sign in to comment.