Skip to content

Publish Images

Publish Images #5

Workflow file for this run

name: Publish Images
on:
workflow_run:
workflows:
- CI
branches:
- main
types:
- completed
concurrency:
group: publish-${{ github.event.workflow_run.head_sha }}
cancel-in-progress: false
permissions:
contents: read
packages: write
jobs:
publish:
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.name == 'CI' &&
github.event.workflow_run.head_branch == 'main' &&
github.event.workflow_run.event == 'push'
runs-on: ubuntu-latest
steps:
- name: Resolve SHA
id: sha
run: |
sha="${{ github.event.workflow_run.head_sha }}"
if [[ ! "$sha" =~ ^[0-9a-fA-F]{40}$ ]]; then
echo "invalid full commit SHA: $sha" >&2
exit 1
fi
echo "value=$sha" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
ref: ${{ steps.sha.outputs.value }}
- name: Compute image names
id: image
run: |
repo="${GITHUB_REPOSITORY,,}"
echo "backend=ghcr.io/${repo}-backend" >> "$GITHUB_OUTPUT"
echo "frontend=ghcr.io/${repo}-frontend" >> "$GITHUB_OUTPUT"
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and publish backend
uses: docker/build-push-action@v6
with:
context: ./server
file: ./server/Dockerfile
push: true
tags: ${{ steps.image.outputs.backend }}:${{ steps.sha.outputs.value }}
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.revision=${{ steps.sha.outputs.value }}
cache-from: type=gha,scope=backend
cache-to: type=gha,mode=max,scope=backend
- name: Build and publish frontend
uses: docker/build-push-action@v6
with:
context: ./frontend
file: ./frontend/Dockerfile
push: true
tags: ${{ steps.image.outputs.frontend }}:${{ steps.sha.outputs.value }}
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.revision=${{ steps.sha.outputs.value }}
cache-from: type=gha,scope=frontend
cache-to: type=gha,mode=max,scope=frontend