Skip to content

Commit

Permalink
Add: Allow to override build-args for container build 2nd gen
Browse files Browse the repository at this point in the history
The calling workflow should be able to specify the build-args. For
example it should be possible to use whatever gvm-libs base image
version the calling workflow needs and shouldn't limit to oldstable and
oldstable-edge.

The change tries to be backwards compatible to still provide the old
values if no build-args are passed.
  • Loading branch information
bjoernricks committed Jan 21, 2025
1 parent 5fa1440 commit 4901c58
Showing 1 changed file with 39 additions and 22 deletions.
61 changes: 39 additions & 22 deletions .github/workflows/container-build-push-2nd-gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
service:
description: "The image related compose service name."
type: string
build-args:
description: "Additional build arguments for the container image."
type: string
build-context:
description: "Path to image build context. Default is ."
default: .
Expand Down Expand Up @@ -107,15 +110,25 @@ jobs:
# It looks like the action doesn't use its default value even when an empty input is set.
tag-name: ${{ inputs.ref-name || github.ref_name }}

- name: Set container build options
- name: Set container build args
id: container-opts
run: |
if [[ "${{ github.ref_type }}" = 'tag' ]]; then
echo "version=stable" >> $GITHUB_OUTPUT
echo "gvm-libs-version=oldstable" >> $GITHUB_OUTPUT
else
echo "version=edge" >> $GITHUB_OUTPUT
echo "gvm-libs-version=oldstable-edge" >> $GITHUB_OUTPUT
if [[ -z "${{ inputs.build-args}}" ]]; then
if [[ "${{ github.ref_type }}" = 'tag' ]]; then
echo 'build-args<<EOF' >> $GITHUB_OUTPUT
echo "VERSION=stable" >> $GITHUB_OUTPUT
echo "GVM_LIBS_VERSION=oldstable" >> $GITHUB_OUTPUT
echo "IMAGE_REGISTRY=${{ vars.IMAGE_REGISTRY }}" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
else
echo 'build-args<<EOF' >> $GITHUB_OUTPUT
echo "VERSION=edge" >> $GITHUB_OUTPUT
echo "GVM_LIBS_VERSION=oldstable-edge" >> $GITHUB_OUTPUT
echo "IMAGE_REGISTRY=${{ vars.IMAGE_REGISTRY }}" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
fi
else:
echo "build-args=${{ inputs.build-args }}" >> $GITHUB_OUTPUT
fi
- name: Container build and push 2nd gen
Expand All @@ -124,10 +137,7 @@ jobs:
with:
build-context: ${{ inputs.build-context }}
build-docker-file: ${{ inputs.build-docker-file }}
build-args: |
VERSION=${{ steps.container-opts.outputs.version }}
GVM_LIBS_VERSION=${{ steps.container-opts.outputs.gvm-libs-version }}
IMAGE_REGISTRY=${{ vars.IMAGE_REGISTRY }}
build-args: ${{ steps.container-opts.outputs.build-args }}
image-url: ${{ inputs.image-url }}
image-labels: ${{ inputs.image-labels }}
image-tags: raw,value=${{ inputs.ref-name || github.ref_name }}-amd64 # temporary tag that will be overwritten with the manifest upload
Expand Down Expand Up @@ -160,15 +170,25 @@ jobs:
name: ${{ inputs.artifact-name }}
path: ${{ inputs.artifact-path }}

- name: Set container build options
- name: Set container build args
id: container-opts
run: |
if [[ "${{ github.ref_type }}" = 'tag' ]]; then
echo "version=stable" >> $GITHUB_OUTPUT
echo "gvm-libs-version=oldstable" >> $GITHUB_OUTPUT
else
echo "version=edge" >> $GITHUB_OUTPUT
echo "gvm-libs-version=oldstable-edge" >> $GITHUB_OUTPUT
if [[ -z "${{ inputs.build-args}}" ]]; then
if [[ "${{ github.ref_type }}" = 'tag' ]]; then
echo 'build-args<<EOF' >> $GITHUB_OUTPUT
echo "VERSION=stable" >> $GITHUB_OUTPUT
echo "GVM_LIBS_VERSION=oldstable" >> $GITHUB_OUTPUT
echo "IMAGE_REGISTRY=${{ vars.IMAGE_REGISTRY }}" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
else
echo 'build-args<<EOF' >> $GITHUB_OUTPUT
echo "VERSION=edge" >> $GITHUB_OUTPUT
echo "GVM_LIBS_VERSION=oldstable-edge" >> $GITHUB_OUTPUT
echo "IMAGE_REGISTRY=${{ vars.IMAGE_REGISTRY }}" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
fi
else:
echo "build-args=${{ inputs.build-args }}"" >> $GITHUB_OUTPUT
fi
- name: Container build and push 2nd gen
Expand All @@ -177,10 +197,7 @@ jobs:
with:
build-context: ${{ inputs.build-context }}
build-docker-file: ${{ inputs.build-docker-file }}
build-args: |
VERSION=${{ steps.container-opts.outputs.version }}
GVM_LIBS_VERSION=${{ steps.container-opts.outputs.gvm-libs-version }}
IMAGE_REGISTRY=${{ vars.IMAGE_REGISTRY }}
build-args: ${{ steps.container-opts.outputs.build-args }}
image-url: ${{ inputs.image-url }}
image-labels: ${{ inputs.image-labels }}
image-tags: raw,value=${{ inputs.ref-name || github.ref_name }}-arm64 # temporary tag that will be overwritten with the manifest upload
Expand Down

0 comments on commit 4901c58

Please sign in to comment.