We're pushing to Docker Hub, too! (#18) #2
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 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' && true || false}} | |
jobs: | |
build-base-images: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
strategy: | |
fail-fast: false | |
matrix: | |
images: | |
- dockerfile: base/al2023/Dockerfile | |
directory: base/al2023 | |
image_tags: ${{ github.repository_owner }}/al2023:latest | |
description: "Amazon Linux 2023" | |
- dockerfile: base/alpine/Dockerfile | |
directory: base/alpine | |
image_tags: ${{ github.repository_owner }}/alpine:latest | |
description: "Alpine Linux" | |
supported_platforms: | |
- linux/arm/v7 | |
- linux/arm/v8 | |
- dockerfile: base/debian/Dockerfile | |
directory: base/debian | |
image_tags: ${{ github.repository_owner }}/debian:latest | |
description: "Debian Linux (Slim)" | |
supported_platforms: | |
- linux/arm/v7 | |
- linux/arm/v8 | |
include: | |
- images.supported_platforms: | |
- linux/amd64 | |
- linux/arm64 | |
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 QEMU." | |
uses: docker/setup-qemu-action@v3 | |
- 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: | |
file: ${{ matrix.images.dockerfile }} | |
push: true | |
provenance: false | |
tags: ${{ join(matrix.images.image_tags, ',') }} | |
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: | |
- dockerfile: tools/opentofu/Dockerfile | |
directory: tools/opentofu/Dockerfile | |
image: ${{ github.repository_owner }}/opentofu:latest | |
description: "OpenTofu is an open source IaC tool that allows management of infrastructure as code." | |
supported_platforms: | |
- linux/arm/v7 | |
- linux/arm/v8 | |
- dockerfile: tools/kubectl/Dockerfile | |
directory: tools/kubectl/Dockerfile | |
image: ${{ github.repository_owner }}/kubectl:latest | |
description: "Kubectl is a CLI tool for running commands against Kubernetes clusters." | |
include: | |
- images.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 QEMU." | |
uses: docker/setup-qemu-action@v3 | |
- 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: | |
file: ${{ matrix.images.dockerfile }} | |
push: ${{ env.PUSH_IMAGES}} | |
provenance: false | |
tags: ${{ join(matrix.images.image_tags, ',') }} | |
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 }} |