Rebuild image #19
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 | |
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 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: linux/amd64 | |
build-args: ${{ steps.build-args.outputs.value }} | |
push: ${{ inputs.push }} | |
load: ${{ ! inputs.push }} | |
tags: ${{ steps.build-args.outputs.target_image }} | |