Skip to content

Deploy

Deploy #507

Workflow file for this run

---
name: Deploy
on:
workflow_dispatch:
push:
branches:
- main
jobs:
Docker:
if: ${{ github.repository_owner == 'elixirschool' }}
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 == 'elixirschool' }}
runs-on: ubuntu-latest
needs: [Docker]
steps:
- 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 }}