Rebuild image #37
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: Rebuild image | |
on: | |
workflow_dispatch: | |
inputs: | |
directory: | |
description: 'Name of the directory for image - e.g. kube-oidc-proxy' | |
type: string | |
required: true | |
build-args: | |
description: 'Arguments for generating build args e.g. SOURCE_IMAGE_VERSION=1.0.6' | |
type: string | |
required: false | |
platforms: | |
description: 'Comma separated list of platforms to build the image for. A multi-platform image will be built if more than one platform is specified.' | |
type: string | |
default: linux/amd64 | |
push: | |
description: 'Push the image to GHCR' | |
type: boolean | |
default: false | |
permissions: | |
packages: write | |
jobs: | |
build_image: | |
runs-on: | |
- self-hosted | |
- small | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_READ_ONLY_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_READ_ONLY_PASSWORD }} | |
- name: Login to GHCR | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Gather build args | |
shell: bash | |
id: build-args | |
working-directory: ./${{ inputs.directory }} | |
run: | | |
BUILD_ARGS=$(make build-args ${{ inputs.build-args }}) | |
{ | |
echo 'value<<EOF' | |
echo "$BUILD_ARGS" | |
echo 'EOF' | |
} >> "$GITHUB_OUTPUT" | |
export $(echo "$BUILD_ARGS" | xargs) | |
echo "target_image=$TARGET_IMAGE" >> "$GITHUB_OUTPUT" | |
- name: Build and push image | |
id: build | |
uses: docker/[email protected] | |
with: | |
context: ./${{ inputs.directory }} | |
platforms: ${{ inputs.platforms }} | |
build-args: ${{ steps.build-args.outputs.value }} | |
push: ${{ inputs.push }} | |
load: ${{ ! inputs.push }} | |
tags: ${{ steps.build-args.outputs.target_image }} | |