ping-pong #1
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: Container Images - Build | |
on: | |
push: | |
branches: [ 'main' ] | |
paths: [ 'containers/**' ] | |
tags: [ '**-v**' ] | |
pull_request: | |
paths: [ 'containers/**'] | |
workflow_call: | |
workflow_dispatch: | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.buildMatrix.outputs.matrix }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
persist-credentials: true | |
- id: buildMatrix | |
run: | | |
DIRS="$(./bin/gh-matrix-builder list-container-dirs)" | |
echo "matrix=$(jq -cn --argjson environments "$DIRS" '{directory: $environments, platform: [ "linux/amd64,linux/arm64" ]}')" | tee -a "$GITHUB_OUTPUT" | |
buildx: | |
needs: setup | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJson(needs.setup.outputs.matrix) }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
persist-credentials: true | |
- name: Set build status for containers/${{ matrix.directory }} folder | |
id: changed-files | |
continue-on-error: true | |
run: | | |
set +e | |
if [[ ${{ github.ref }} == "refs/tags/${{ matrix.directory }}-v"* ]]; then | |
export RETURN=0 | |
elif [[ ${{ github.ref }} == 'refs/heads/main' ]]; then | |
git --no-pager diff --name-only HEAD~1 | grep containers/${{ matrix.directory }} | |
export RETURN=${?} | |
else | |
git --no-pager diff --name-only origin/main | grep containers/${{ matrix.directory }} | |
export RETURN=${?} | |
fi | |
if [[ ${RETURN} != 0 ]]; then | |
echo "TRIGGER_BUILD=false" >> $GITHUB_ENV | |
else | |
echo "TRIGGER_BUILD=true" >> $GITHUB_ENV | |
fi | |
- uses: actions-tools/yaml-outputs@v2 | |
id: metadata | |
if: env.TRIGGER_BUILD == 'true' | |
with: | |
file-path: 'containers/${{ matrix.directory }}/metadata.yaml' | |
- name: Docker meta | |
id: image-metadata | |
if: env.TRIGGER_BUILD == 'true' | |
uses: docker/metadata-action@v5 | |
env: | |
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index | |
with: | |
images: | | |
docker.io/superorbital/${{ matrix.directory }},enable=${{ steps.metadata.outputs.image__visibility == 'public' }} | |
tags: | | |
type=raw,value=latest,enable={{is_default_branch}} | |
type=sha,enable={{is_default_branch}} | |
type=schedule,pattern={{date 'YYYYMMDD-hhmmss' tz='UTC'}},enable={{is_default_branch}} | |
type=match,pattern=${{ matrix.directory }}-v(\d.\d.\d),group=1,prefix=v,enable=${{ startsWith(github.ref, format('refs/tags/{0}-v', matrix.directory)) }} | |
type=match,pattern=${{ matrix.directory }}-v(\d.\d).\d,group=1,prefix=v,enable=${{ startsWith(github.ref, format('refs/tags/{0}-v', matrix.directory)) }} | |
type=match,pattern=${{ matrix.directory }}-v(\d).\d.\d,group=1,prefix=v,enable=${{ startsWith(github.ref, format('refs/tags/{0}-v', matrix.directory)) }} | |
type=ref,event=pr,suffix=-alpha,enable=${{ endsWith(github.ref, '/merge') }} | |
type=sha,suffix=-alpha,enable=${{ endsWith(github.ref, '/merge') }} | |
labels: | | |
org.opencontainers.image.licenses=LicenseRef-Proprietary | |
org.opencontainers.image.authors=SuperOrbital, LLC | |
org.opencontainers.image.description=${{ steps.metadata.outputs.image__description }} | |
org.opencontainers.image.documentation=https://github.com/superorbital/${{ github.event.repository.name }}/tree/${{ github.sha }}/containers/${{ matrix.directory }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.source=https://github.com/superorbital/${{ github.event.repository.name }}/tree/${{ github.sha }}/containers/${{ matrix.directory }} | |
org.opencontainers.image.title=${{ matrix.directory }} | |
org.opencontainers.image.url=https://github.com/superorbital/${{ github.event.repository.name }}/tree/${{ github.sha }}/containers/${{ matrix.directory }} | |
org.opencontainers.image.vendor=SuperOrbital, LLC | |
annotations: | | |
org.opencontainers.image.licenses=LicenseRef-Proprietary | |
org.opencontainers.image.authors=SuperOrbital, LLC | |
org.opencontainers.image.description=${{ steps.metadata.outputs.image__description }} | |
org.opencontainers.image.documentation=https://github.com/superorbital/${{ github.event.repository.name }}/tree/${{ github.sha }}/containers/${{ matrix.directory }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.source=https://github.com/superorbital/${{ github.event.repository.name }}/tree/${{ github.sha }}/containers/${{ matrix.directory }} | |
org.opencontainers.image.title=${{ matrix.directory }} | |
org.opencontainers.image.url=https://github.com/superorbital/${{ github.event.repository.name }}/tree/${{ github.sha }}/containers/${{ matrix.directory }} | |
org.opencontainers.image.vendor=SuperOrbital, LLC | |
- name: Set up QEMU | |
if: env.TRIGGER_BUILD == 'true' | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
id: buildx | |
if: env.TRIGGER_BUILD == 'true' | |
uses: docker/setup-buildx-action@v3 | |
- name: Available platforms | |
if: env.TRIGGER_BUILD == 'true' | |
run: echo ${{ steps.buildx.outputs.platforms }} | |
- name: Login to Docker Hub (public images) | |
if: ${{ env.TRIGGER_BUILD == 'true' && steps.metadata.outputs.image__visibility == 'public' }} | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push PUBLIC container/${{ matrix.directory }} | |
id: docker_build_public | |
if: ${{ env.TRIGGER_BUILD == 'true' && steps.metadata.outputs.image__visibility == 'public' }} | |
uses: docker/build-push-action@v5 | |
with: | |
provenance: false | |
sbom: false | |
build-args: | | |
BUILDTIME=${{ fromJSON(steps.image-metadata.outputs.json).labels['org.opencontainers.image.created'] }} | |
VERSION=${{ fromJSON(steps.image-metadata.outputs.json).labels['org.opencontainers.image.version'] }} | |
REVISION=${{ fromJSON(steps.image-metadata.outputs.json).labels['org.opencontainers.image.revision'] }} | |
context: containers/${{ matrix.directory }} | |
file: containers/${{ matrix.directory }}/Dockerfile | |
platforms: ${{ matrix.platform }} | |
# Since these are public, let's only push them from the default branch or a tagged version. | |
push: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, format('refs/tags/{0}-v', matrix.directory)) }} | |
tags: ${{ steps.image-metadata.outputs.tags }} | |
labels: ${{ steps.image-metadata.outputs.labels }} | |
annotations: ${{ steps.image-metadata.outputs.annotations }} |