Skip to content

Commit 8c15e31

Browse files
committed
test: add test case for buildkitd-config-inline
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent 8906424 commit 8c15e31

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

.github/workflows/__test-action-docker-build-image.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,98 @@ jobs:
250250
exit 1
251251
fi
252252
253+
tests-with-buildkitd-config-inline:
254+
name: Test for "docker/build-image" action with BuildKit daemon config
255+
runs-on: ubuntu-latest
256+
permissions:
257+
contents: read
258+
packages: write
259+
steps:
260+
- name: Arrange - Checkout
261+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
262+
with:
263+
persist-credentials: false
264+
265+
- name: Arrange - Ensure token is set
266+
run: |
267+
if [ -z "${{ github.token }}" ]; then
268+
echo "GitHub token is not set"
269+
exit 1
270+
fi
271+
272+
- name: Act - Build image
273+
id: build-image
274+
uses: ./actions/docker/build-image
275+
with:
276+
oci-registry: ghcr.io
277+
oci-registry-password: ${{ github.token }}
278+
context: "."
279+
dockerfile: "./tests/application/Dockerfile"
280+
target: "prod"
281+
platform: "linux/amd64"
282+
image: application-test
283+
buildkitd-config-inline: |
284+
debug = true
285+
[worker.oci]
286+
max-parallelism = 2
287+
288+
- name: Assert - Check BuildKit daemon config
289+
run: |
290+
BUILDKIT_CONTAINER=$(docker ps --filter 'name=buildx_buildkit_' --format '{{.Names}}' | head -n 1)
291+
if [ -z "$BUILDKIT_CONTAINER" ]; then
292+
echo "Failed to find BuildKit container"
293+
docker ps -a
294+
exit 1
295+
fi
296+
297+
BUILDKIT_CONFIG=$(docker exec "$BUILDKIT_CONTAINER" cat /etc/buildkit/buildkitd.toml)
298+
printf '%s\n' "$BUILDKIT_CONFIG"
299+
300+
echo "$BUILDKIT_CONFIG" | grep -F 'debug = true'
301+
echo "$BUILDKIT_CONFIG" | grep -F '[worker.oci]'
302+
echo "$BUILDKIT_CONFIG" | grep -F 'max-parallelism = 2'
303+
304+
- name: Assert - Check built image output
305+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
306+
with:
307+
script: |
308+
const assert = require("assert");
309+
310+
const builtImageOutput = ${{ toJSON(steps.build-image.outputs.built-image) }};
311+
assert(builtImageOutput, `"built-image" output is empty`);
312+
313+
let builtImage;
314+
try {
315+
builtImage = JSON.parse(builtImageOutput);
316+
} catch (error) {
317+
assert.fail(`Failed to parse built image output: ${error}`);
318+
}
319+
320+
assert(builtImage, `"built-image" output is empty`);
321+
assert.equal(builtImage.name, "application-test", `"name" output is not valid`);
322+
assert.match(
323+
builtImage.digest,
324+
/^sha256:[a-f0-9]{64}$/,
325+
`"digest" output is not valid`
326+
);
327+
328+
- uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0
329+
with:
330+
registry: ghcr.io
331+
username: ${{ github.repository_owner }}
332+
password: ${{ github.token }}
333+
334+
- name: Assert - Check docker image
335+
run: |
336+
IMAGE=$(echo '${{ steps.build-image.outputs.built-image }}' | jq -r '.image')
337+
if ! docker pull "$IMAGE"; then
338+
echo "Failed to pull $IMAGE"
339+
exit 1
340+
fi
341+
342+
if ! docker manifest inspect "$IMAGE"; then
343+
echo "Failed to inspect $IMAGE"
344+
exit 1
345+
fi
346+
253347
# jscpd:ignore-end

0 commit comments

Comments
 (0)