Skip to content

Commit

Permalink
chore: replace buildah-build action with commands
Browse files Browse the repository at this point in the history
  • Loading branch information
p5 committed Jan 6, 2025
1 parent 788cc52 commit d6ead7c
Showing 1 changed file with 39 additions and 24 deletions.
63 changes: 39 additions & 24 deletions .github/actions/build-image/action.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,72 @@
name: Build Image
description: "Builds a container image using Podman or Docker"

inputs:
context:
description: 'The build context directory'
description: "The build context directory"
required: false
default: '.'
default: "."
dockerfile:
description: 'The path to the Dockerfile to build'
description: "The path to the Dockerfile to build"
required: false
default: 'Containerfile'
default: "Containerfile"
image-name:
description: 'The name of the image to build'
description: "The name of the image to build"
required: true
image-tags:
description: 'The tags to apply to the image'
description: "The tags to apply to the image"
required: true
build-args:
description: 'Build arguments to pass to the Docker build'
description: "Build arguments to pass to the Docker build"
required: false
default: ''
default: ""
builder:
description: 'The name of the builder to use (docker or podman)'
description: "The name of the builder to use (docker or podman)"
required: false
default: 'podman'
default: "podman"

outputs:
image:
description: 'The name of the built image'
description: "The name of the built image"
value: ${{ steps.set-outputs.outputs.image }}
tags:
description: 'The tags applied to the built image'
description: "The tags applied to the built image"
value: ${{ steps.set-outputs.outputs.tags }}
digest:
description: 'The digest of the built image'
description: "The digest of the built image"
value: ${{ steps.set-outputs.outputs.digest }}
builder:
description: 'The builder used to build the image'
description: "The builder used to build the image"
value: ${{ inputs.builder }}

runs:
using: 'composite'
using: "composite"
steps:
- name: Build (Podman)
if: ${{ inputs.builder == 'podman' }}
id: build-podman
uses: redhat-actions/buildah-build@7a95fa7ee0f02d552a32753e7414641a04307056 # v2
with:
context: ${{ inputs.context }}
containerfiles: ${{ inputs.dockerfile }}
image: ${{ inputs.image-name }}
tags: ${{ inputs.image-tags }}
build-args: ${{ inputs.build-args }}
shell: bash
run: |
BUILD_ARG_FLAGS=""
if [ -n "${{ inputs.build-args }}" ]; then
IFS=' ' read -r -a build_args_array <<< "${{ inputs.build-args }}"
for build_arg in "${build_args_array[@]}"; do
BUILD_ARG_FLAGS+="--build-arg $build_arg "
done
fi
TAGS_FLAGS=""
IFS=' ' read -r -a tag_array <<< "${{ inputs.image-tags }}"
for tag in "${tag_array[@]}"; do
TAGS_FLAGS+="--tag ${{ inputs.image-name }}:$tag "
done
podman build \
$BUILD_ARG_FLAGS \
$TAGS_FLAGS \
${{ inputs.context }}
digest=$(podman image inspect ${{ inputs.image-name }}:${tag_array[0]} --format "{{.Digest}}")
echo "digest=$digest" >> $GITHUB_OUTPUT
- name: Generate Tags (Docker)
if: ${{ inputs.builder == 'docker' }}
Expand Down Expand Up @@ -93,8 +109,7 @@ runs:
single_tag="${tag_array[0]}"
echo "tags=${{ inputs.image-tags }}" >> $GITHUB_OUTPUT
digest=$(podman image inspect ${{ inputs.image-name }}:$single_tag --format '{{.Digest}}')
echo "digest=$digest" >> $GITHUB_OUTPUT
echo "digest=${{ steps.build-podman.outputs.digest }}" >> $GITHUB_OUTPUT
else
echo "tags=${{ inputs.image-tags }}" >> $GITHUB_OUTPUT
echo "digest=${{ steps.build-docker.outputs.digest }}" >> $GITHUB_OUTPUT
Expand Down

0 comments on commit d6ead7c

Please sign in to comment.