name: Build Container Image
on:
push:
branches:
- main
tags:
- '*'
workflow_dispatch:
jobs:
build-image:
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v4
- name: Gather information
id: info
run: |
echo "toolchain_version=$(yq '.toolchain.channel' --output-format=yaml rust-toolchain.toml)" >> $GITHUB_OUTPUT
echo "crate_version=$(yq '.workspace.package.version' --output-format=yaml Cargo.toml)" >> $GITHUB_OUTPUT
echo "git_timestamp=$(git log -1 --pretty=%ct)" >> $GITHUB_OUTPUT
echo "## Build information" >> $GITHUB_STEP_SUMMARY
echo "| | |" >> $GITHUB_STEP_SUMMARY
echo "| --- | --- |" >> $GITHUB_STEP_SUMMARY
cat $GITHUB_OUTPUT | sed 's/\(.*\)=\(.*\)/| \1 | \2 |/' >> $GITHUB_STEP_SUMMARY
- uses: docker/setup-buildx-action@v3
with:
driver-opts: network=host
- name: Prepare build environment image
uses: docker/build-push-action@v6
with:
context: ./build/build-image
build-args: RUST_TOOLCHAIN=${{ steps.info.outputs.toolchain_version }}
cache-from: type=gha,scope=build-env
cache-to: type=gha,mode=max,scope=build-env
push: true
tags: localhost:5000/build-env:latest
- name: Gather image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/embarkstudios/quilkin
tags: |
type=ref,event=tag
type=sha,prefix=${{ steps.info.outputs.crate_version }}-
- name: Build container image
uses: docker/build-push-action@v6
with:
build-args: BUILDKIT_CONTEXT_KEEP_GIT_DIR=1
file: image/Dockerfile.ghaction
build-contexts: |
build-env=docker-image://localhost:5000/build-env:latest
cache-from: type=gha,scope=quilkin
cache-to: type=gha,mode=max,scope=quilkin
push: true
tags: ${{ steps.meta.outputs.tags }}
annotations: ${{ steps.meta.outputs.annotations }}
env:
SOURCE_DATE_EPOCH: ${{ steps.info.outputs.git_timestamp }}