Skip to content

Commit ca017db

Browse files
authored
feat(build-container-image): Support Docker build arguments (#70)
1 parent 8165858 commit ca017db

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
# Splits comma-separated values, prepends them with --build-arg, and prints
4+
# them out separated by newlines.
5+
echo "$1" | awk '{ split($0, args, ","); for (i in args) { printf "--build-arg \"%s\" ", args[i] }}'

build-container-image/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ All subsequent tasks must use this value to ensure consistency.
1717
1818
### Inputs
1919

20-
- `image-name` (eg: `kafka`)
21-
- `image-index-manifest-tag` (eg: `3.4.1-stackable0.0.0-dev`)
20+
- `image-name` (required, eg: `kafka`)
21+
- `image-index-manifest-tag` (required, eg: `3.4.1-stackable0.0.0-dev`)
2222
- `container-file` (defaults to `Dockerfile`)
2323
- `build-context` (defaults to `.`)
24+
- `build-arguments`
2425

2526
### Outputs
2627

build-container-image/action.yaml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
name: Build Product Image
3-
description: This action builds a product Docker image with a specific version
2+
name: Build Container Image
3+
description: This action builds a container image with a specific version
44
inputs:
55
image-name:
66
description: |
@@ -12,11 +12,14 @@ inputs:
1212
Human-readable tag (usually the version) without architecture information,
1313
for example: `3.4.1-stackable0.0.0-dev`
1414
container-file:
15-
description: Path to Containerfile (or Dockefile)
15+
description: Path to Containerfile (or Dockerfile)
1616
default: Dockerfile
1717
build-context:
1818
description: Path to the build-context
1919
default: .
20+
build-arguments:
21+
description: |
22+
A comma-separated list of KEY=VALUE pairs provided as build arguments
2023
outputs:
2124
image-repository-uri:
2225
description: |
@@ -45,10 +48,13 @@ runs:
4548
IMAGE_INDEX_MANIFEST_TAG: ${{ inputs.image-index-manifest-tag }}
4649
CONTAINER_FILE: ${{ inputs.container-file }}
4750
BUILD_CONTEXT: ${{ inputs.build-context }}
51+
BUILD_ARGUMENTS: ${{ inputs.build-arguments }}
4852
shell: bash
4953
run: |
5054
set -euo pipefail
5155
56+
DOCKER_BUILD_ARGUMENTS=$("$GITHUB_ACTION_PATH/../.scripts/actions/get_build_arguments.sh" "$BUILD_ARGUMENTS")
57+
5258
IMAGE_ARCH=$("$GITHUB_ACTION_PATH/../.scripts/actions/get_architecture.sh")
5359
echo "IMAGE_ARCH=${IMAGE_ARCH}" | tee -a "$GITHUB_ENV"
5460
@@ -64,11 +70,12 @@ runs:
6470
echo "::group::docker buildx build"
6571
# TODO (@NickLarsenNZ): Allow optional buildx cache
6672
docker buildx build \
67-
--file "${CONTAINER_FILE}" \
68-
--platform "linux/${IMAGE_ARCH}" \
69-
--tag "${IMAGE_MANIFEST_URI}" \
70-
--load \
71-
"${BUILD_CONTEXT}"
73+
--file "${CONTAINER_FILE}" \
74+
--platform "linux/${IMAGE_ARCH}" \
75+
--tag "${IMAGE_MANIFEST_URI}" \
76+
--load \
77+
$DOCKER_BUILD_ARGUMENTS \
78+
"${BUILD_CONTEXT}"
7279
echo "::endgroup::"
7380
7481
echo "::group::docker images"

0 commit comments

Comments
 (0)