Skip to content

publish-image

publish-image #452

Workflow file for this run

name: publish-image
on:
workflow_dispatch:
# Dockerfile builds again but does not run tests so we only
# run this workflow after successful Go build-test
workflow_run:
workflows: ['build-test']
types: [completed]
branches: ['main']
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-image:
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- module: broker
dockerfile: ./broker/Dockerfile
image: ghcr.io/${{ github.repository }}-broker
- module: illmock
dockerfile: ./illmock/Dockerfile
image: ghcr.io/${{ github.repository }}-illmock
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: stable
cache-dependency-path: |
go.work.sum
${{ matrix.module }}/go.sum
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: xsltproc
version: 1.0
- name : Install sqlc
uses: sqlc-dev/setup-sqlc@v4
with:
sqlc-version: '1.25.0'
- name: Generate sources
run: make generate
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ matrix.image }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles(matrix.dockerfile) }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ${{ matrix.dockerfile }}
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
build-args: |
GOCACHE=/root/.cache/go-build
GOMODCACHE=/go/pkg/mod