Build containers #15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: 'Build containers' | |
on: | |
workflow_dispatch: | |
pull_request: | |
branches: | |
- master | |
paths-ignore: | |
- COPYING | |
- README.md | |
push: | |
branches: | |
- master | |
paths-ignore: | |
- COPYING | |
- README.md | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
libc: | |
- 'glibc' | |
- 'musl' | |
variant: | |
- '' | |
- '-full' | |
- '-busybox' | |
steps: | |
- name: Checkout | |
uses: classabbyamp/treeless-checkout-action@v1 | |
- name: Get image release | |
id: release | |
run: | | |
# gets the list of all date-shaped tags for the image, finds the most recent one | |
tag="$(skopeo list-tags "docker://ghcr.io/${{ github.repository_owner }}/void-${{ matrix.libc }}${{ matrix.variant }}" | \ | |
jq -r '.Tags | sort | reverse | map(select(test("^[0-9]{8}(R[0-9]+)?$")))[0]')" | |
# tags from a different day or pre-YYYYMMDDRN | |
if [ "${tag%R*}" != "$(date -u +%Y%m%d)" ] || [ "${tag%R*}" = "${tag}" ]; then | |
rel=1 | |
else | |
rel=$(( ${tag##*R} + 1 )) | |
fi | |
echo "rel=${rel}" >> "${GITHUB_OUTPUT}" | |
- name: Docker metadata | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: | | |
ghcr.io/${{ github.repository_owner }}/void-${{ matrix.libc }}${{ matrix.variant }} | |
tags: | | |
type=sha,prefix= | |
type=raw,value=latest,enable={{is_default_branch}} | |
type=raw,value={{date 'YYYYMMDD'}}R${{ steps.release.outputs.rel }},enable={{is_default_branch}},priority=1000 | |
flavor: latest=false | |
labels: | | |
org.opencontainers.image.authors=Void Linux team and contributors | |
org.opencontainers.image.url=https://voidlinux.org | |
org.opencontainers.image.documentation=https://docs.voidlinux.org | |
org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
org.opencontainers.image.vendor=Void Linux | |
org.opencontainers.image.title=Void Linux | |
org.opencontainers.image.description=general-purpose image based on Void Linux | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to GCHR | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push images | |
id: build_and_push | |
uses: docker/bake-action@v3 | |
with: | |
push: ${{ github.event_name != 'pull_request' }} | |
targets: void-${{ matrix.libc }}${{ matrix.variant }} | |
files: | | |
docker-bake.hcl | |
${{ steps.meta.outputs.bake-file }} | |
set: | | |
_common.cache-to=type=gha | |
_common.cache-from=type=gha |