Skip to content

Additional labels, vars, and image types #45

Additional labels, vars, and image types

Additional labels, vars, and image types #45

Workflow file for this run

name: "Build and push images."
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
schedule:
- cron: '45 16 * * 4' # Every Thursday at 16:45 UTC.
push:
branches:
- '*'
pull_request:
branches:
- '*'
workflow_dispatch:
env:
PUSH_IMAGES: ${{ github.ref == 'refs/heads/trunk' }}
PROVENANCE: true
jobs:
build-base-images:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
images:
- context: base/al2023
image_name: ${{ github.repository_owner }}/al2023
description: "Amazon Linux 2023"
supported_platforms:
- linux/amd64
- linux/arm64
- linux/arm64/v8
- context: base/alpine
image_name: ${{ github.repository_owner }}/alpine
description: "Alpine Linux"
supported_platforms:
- linux/amd64
- linux/arm64
- linux/arm/v7
- linux/arm/v8
- linux/arm64/v8
- context: base/debian
image_name: ${{ github.repository_owner }}/debian
description: "Debian Linux (Slim)"
supported_platforms:
- linux/amd64
- linux/arm64
- linux/arm/v7
- linux/arm/v8
- linux/arm64/v8
outputs:
digests: ${{ steps.build-push-image.outputs.digest }}
steps:
- name: "Checkout repository."
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: "Set up Docker Buildx."
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ join(matrix.images.supported_platforms, ',') }}
- name: "Login: ghcr.io"
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: "Login: Docker Hub"
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: "Build and push image."
id: build-push-image
uses: docker/build-push-action@v5
if:
with:
context: ${{ matrix.images.context }}
file: ${{ matrix.images.context }}/Dockerfile
push: ${{ env.PUSH_IMAGES }}
provenance: ${{ env.PROVENANCE }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
${{ matrix.images.image_name }}:latest
ghcr.io/${{ matrix.images.image_name }}:latest
platforms: ${{ join(matrix.images.supported_platforms, ',') }}
labels: |-
org.opencontainers.image.vendor=${{ github.repository_owner }}
org.opencontainers.image.source=https://github.com/${{ github.repository}}
org.opencontainers.image.description=${{ matrix.images.description }}
build-tool-images:
needs: build-base-images
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
images:
- context: tools/opentofu
image_name: ${{ github.repository_owner }}/opentofu
description: "OpenTofu is an open source IaC tool that allows management of infrastructure as code."
supported_platforms:
- linux/amd64
- linux/arm64
- linux/arm/v7
- linux/arm/v8
- linux/arm64/v8
- context: tools/kubectl
image_name: ${{ github.repository_owner }}/kubectl
description: "Kubectl is a CLI tool for running commands against Kubernetes clusters."
supported_platforms:
- linux/amd64
- linux/arm64
outputs:
digests: ${{ steps.push-image.outputs.digest }}
steps:
- name: "Checkout repository."
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: "Set up Docker Buildx."
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ join(matrix.images.supported_platforms, ',') }}
- name: "Login: ghcr.io"
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: "Login: Docker Hub"
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: "Build and push image."
id: push-image
uses: docker/build-push-action@v5
with:
context: ${{ matrix.images.context }}
file: ${{ matrix.images.context }}/Dockerfile
push: ${{ env.PUSH_IMAGES}}
provenance: ${{ env.PROVENANCE }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
${{ matrix.images.image_name }}:latest
ghcr.io/${{ matrix.images.image_name }}:latest
platforms: ${{ join(matrix.images.supported_platforms, ',') }}
labels: |-
org.opencontainers.image.vendor=${{ github.repository_owner }}
org.opencontainers.image.source=https://github.com/${{ github.repository}}
org.opencontainers.image.description=${{ matrix.images.description }}