Skip to content

Commit c179c50

Browse files
authored
feat: Add build-container-image action (#3)
* feat: Add build-container-image action for generic container builds * chore: Correct the input description
1 parent e878116 commit c179c50

File tree

3 files changed

+124
-1
lines changed

3 files changed

+124
-1
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,41 @@ particular step in a workflow.
1717
| Image Repo Digest | `docker.stackable.tech/stackable/kafka@sha256:917f800259ef4915f976...` |
1818
| Digest | `sha256:917f800259ef4915f976e93987b752fd64debf347568610d7f685d2022...` |
1919

20+
## `build-container-image`
21+
22+
> Manifest: [build-container-image/action.yml][build-container-image]
23+
24+
This action builds a *single* container image using `docker buildx build`. It does the following work:
25+
26+
1. Free disk space to avoid running out of disk space during larger builds.
27+
2. Build the image using `docker buildx build`, outputting the architecture specific tag.
28+
29+
This action is considered to be the **single** source of truth regarding the image manifest tag.
30+
All subsequent tasks must use this value to ensure consistency.
31+
32+
### Inputs and Outputs
33+
34+
> [!TIP]
35+
> For descriptions of the inputs and outputs, see the complete [build-container-image] action.
36+
37+
#### Inputs
38+
39+
- `image-name`
40+
- `image-index-manifest-tag`
41+
- `container-file` (defaults to `Dockerfile`)
42+
- `build-context` (defaults to `.`)
43+
<!--
44+
TODO (@NickLarsenNZ): Allow optional buildx cache
45+
- `build-cache-username`
46+
- `build-cache-password`
47+
-->
48+
49+
#### Outputs
50+
51+
- `image-manifest-tag`
52+
53+
[build-container-image]: ./build-container-image/action.yml
54+
2055
## `build-product-image`
2156

2257
> Manifest: [build-product-image/action.yml][build-product-image]

build-container-image/action.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
name: Build Product Image
3+
description: This action builds a product Docker image with a specific version
4+
inputs:
5+
image-name:
6+
description: |
7+
The local name of the built image, for example: `kafka` or
8+
`csi-provisioner`
9+
required: true
10+
image-index-manifest-tag:
11+
description: |
12+
Human-readable tag (usually the version) without architecture information,
13+
for example: `3.4.1-stackable0.0.0-dev`
14+
container-file:
15+
description: Path to Containerfile (or Dockefile)
16+
default: Dockerfile
17+
build-context:
18+
description: Path to the build-context
19+
default: .
20+
# TODO (@NickLarsenNZ): Allow optional buildx cache
21+
# build-cache-username:
22+
# description: Build cache username
23+
# default: github
24+
# build-cache-password:
25+
# description: Build cache password
26+
# required: true
27+
outputs:
28+
image-manifest-tag:
29+
description: |
30+
Human-readable tag (usually the version) with architecture information,
31+
for example: `3.4.1-stackable0.0.0-dev-amd64`
32+
value: ${{ steps.build-image.outputs.IMAGE_MANIFEST_TAG }}
33+
runs:
34+
using: composite
35+
steps:
36+
- name: Free Disk Space (Ubuntu)
37+
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
38+
with:
39+
# This might remove tools that are actually needed, if set to "true" but
40+
# frees about 6 GB.
41+
tool-cache: false
42+
43+
# All of these default to true, but feel free to set to "false" if
44+
# necessary for your workflow.
45+
android: true
46+
dotnet: true
47+
haskell: true
48+
large-packages: true
49+
docker-images: true
50+
swap-storage: true
51+
52+
- name: Setup Docker Buildx
53+
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1
54+
55+
# TODO (@NickLarsenNZ): Allow optional buildx cache
56+
# # Needed if you pass the --cache argument to the bake command below
57+
# - name: Login to the docker build cache registry
58+
# uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
59+
# with:
60+
# registry: build-repo.stackable.tech:8083
61+
# username: ${{ inputs.build-cache-username }}
62+
# password: ${{ inputs.build-cache-password }}
63+
64+
- name: Build ${{ inputs.image-name }}:${{ inputs.image-index-manifest-tag }}
65+
id: build-image
66+
env:
67+
IMAGE_NAME: ${{ inputs.image-name }}
68+
IMAGE_INDEX_MANIFEST_TAG: ${{ inputs.image-index-manifest-tag }}
69+
CONTAINER_FILE: ${{ inputs.container-file }}
70+
BUILD_CONTEXT: ${{ inputs.build-context }}
71+
shell: bash
72+
run: |
73+
set -euo pipefail
74+
75+
IMAGE_ARCH="$(uname -m | sed -e 's#x86_64#amd64#' | sed -e 's#aarch64#arm64#')"
76+
echo "IMAGE_ARCH=${IMAGE_ARCH}" | tee -a "$GITHUB_ENV"
77+
78+
IMAGE_MANIFEST_TAG="${IMAGE_INDEX_MANIFEST_TAG}-${IMAGE_ARCH}"
79+
echo "IMAGE_MANIFEST_TAG=${IMAGE_MANIFEST_TAG}" | tee -a $GITHUB_OUTPUT
80+
81+
docker buildx build \
82+
--file "${CONTAINER_FILE}" \
83+
--platform "linux/${IMAGE_ARCH}" \
84+
--tag "localhost/${IMAGE_NAME}:${IMAGE_MANIFEST_TAG}" \
85+
# TODO (@NickLarsenNZ): Allow optional buildx cache
86+
# --cache-to ... \
87+
# --cache-from ... \
88+
"${BUILD_CONTEXT}"

publish-image/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ inputs:
1313
required: true
1414
image-repository:
1515
description: |
16-
Last segment of the path, for example `stackable/kafka` or
16+
Path to the image, for example `stackable/kafka` or
1717
`k8s/sig-storage/csi-provisioner`
1818
required: true
1919
image-manifest-tag:

0 commit comments

Comments
 (0)