Skip to content

Commit de59dfd

Browse files
committed
ci: use docker manifest inspect verbose to assert annotations
Signed-off-by: Emilien Escalle <[email protected]>
1 parent c17227b commit de59dfd

File tree

1 file changed

+93
-84
lines changed

1 file changed

+93
-84
lines changed

.github/workflows/__test-workflow-docker-build-images.yml

Lines changed: 93 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -124,101 +124,110 @@ jobs:
124124
password: ${{ github.token }}
125125

126126
- name: Check multi-arch docker image and manifest
127-
run: |
128-
IMAGE="${{ fromJson(needs.act.outputs.built-images).application-multi-arch.images[0] }}"
129-
130-
docker pull "$IMAGE"
131-
132-
if ! MANIFEST=$(docker manifest inspect "$IMAGE"); then
133-
echo "Failed to inspect manifest for image: ${IMAGE}"
134-
exit 1
135-
fi
136-
137-
# Check that there are 3 platforms
138-
if ! PLATFORMS=$(echo "${MANIFEST}" | jq -e '[.manifests[].platform]'); then
139-
echo "Failed to get platforms for image: ${IMAGE}"
140-
echo "${MANIFEST}"
141-
exit 1
142-
fi
143-
144-
NB_PLATFORMS=$(echo "${PLATFORMS}" | jq -e '. | length')
145-
if [ "$NB_PLATFORMS" != "3" ]; then
146-
echo "Expected 3 platforms, got: $NB_PLATFORMS"
147-
echo "${MANIFEST}"
148-
exit 1
149-
fi
150-
151-
# Check if all platforms are valid
152-
153-
## os=linux,architecture=amd64,variant=null
154-
PLATFORM_EXISTS=$(echo "${PLATFORMS}" | jq -e 'any(.architecture == "amd64" and .os == "linux" and .variant == null)')
155-
test "$PLATFORM_EXISTS" = "true" || (echo "Expected platform not found: os=linux,architecture=amd64,variant=null" && echo "$PLATFORMS" && exit 1)
156-
157-
## os=linux,architecture=arm64,variant=null
158-
PLATFORM_EXISTS=$(echo "${PLATFORMS}" | jq -e 'any(.architecture == "arm64" and .os == "linux" and .variant == null)')
159-
test "$PLATFORM_EXISTS" = "true" || (echo "Expected platform not found: os=linux,architecture=arm64,variant=null" && echo "$PLATFORMS" && exit 1)
160-
161-
## os=linux,architecture=arm,variant=v7
162-
PLATFORM_EXISTS=$(echo "${PLATFORMS}" | jq -e 'any(.architecture == "arm" and .os == "linux" and .variant == "v7")')
163-
test "$PLATFORM_EXISTS" = "true" || (echo "Expected platform not found: os=linux,architecture=arm,variant=v7" && echo "$PLATFORMS" && exit 1)
164-
165-
# FIXME: workaround to get manifest annotations
166-
if ! MANIFEST=$(docker buildx imagetools inspect --raw "$IMAGE"); then
167-
echo "Failed to inspect manifest for image: ${IMAGE}"
168-
exit 1
169-
fi
127+
uses: actions/[email protected]
128+
with:
129+
script: |
130+
const assert = require("assert");
170131
171-
# Check annotations
172-
if ! ANNOTATIONS=$(echo "${MANIFEST}" | jq -e '.annotations'); then
173-
echo "Failed to get annotations for image: ${IMAGE}"
174-
echo "${MANIFEST}"
175-
exit 1
176-
fi
132+
const image = `${{ fromJson(needs.act.outputs.built-images).application-multi-arch.images[0] }}`;
177133
178-
# Check expected annotations
134+
await exec.exec('docker', ['pull', image]);
179135
180-
## org.opencontainers.image.source
181-
ANNOTATION_EXISTS=$(echo "${ANNOTATIONS}" | jq -e '.["org.opencontainers.image.source"] == "https://github.com/hoverkraft-tech/ci-github-container"')
182-
test "$ANNOTATION_EXISTS" = "true" || (echo "Expected annotation not found: org.opencontainers.image.source" && echo "$ANNOTATIONS" && exit 1)
136+
let manifestOutput = null;
137+
const {
138+
exitCode,
139+
stdout,
140+
stderr
141+
} = await exec.getExecOutput('docker', ['manifest', 'inspect', '-v', image]);
183142
184-
## org.opencontainers.image.title
185-
ANNOTATION_EXISTS=$(echo "${ANNOTATIONS}" | jq -e '.["org.opencontainers.image.title"] == "ci-github-container"')
186-
test "$ANNOTATION_EXISTS" = "true" || (echo "Expected annotation not found: org.opencontainers.image.title" && echo "$ANNOTATIONS" && exit 1)
143+
if (exitCode !== 0 || stderr) {
144+
throw new Error(`Failed to inspect manifest for image: ${image}: ${stderr || stdout}`);
145+
}
187146
188-
## org.opencontainers.image.url
189-
ANNOTATION_EXISTS=$(echo "${ANNOTATIONS}" | jq -e '.["org.opencontainers.image.url"] == "https://github.com/hoverkraft-tech/ci-github-container"')
190-
test "$ANNOTATION_EXISTS" = "true" || (echo "Expected annotation not found: org.opencontainers.image.url" && echo "$ANNOTATIONS" && exit 1)
147+
manifest = JSON.parse(stdout);
148+
149+
// Check if all platforms are valid
150+
const expectedPlatforms = [
151+
{ os: "linux", architecture: "amd64", variant: undefined },
152+
{ os: "linux", architecture: "arm64", variant: undefined },
153+
{ os: "linux", architecture: "arm", variant: "v7" }
154+
];
155+
156+
assert.equal(manifest.length, expectedPlatforms.length, `Expected ${expectedPlatforms.length} platforms, got: ${manifest.length}`);
157+
158+
expectedPlatforms.forEach(expectedPlatform => {
159+
const platformExists = manifest.some(
160+
platform => (
161+
platform?.Descriptor?.platform?.architecture === expectedPlatform.architecture &&
162+
platform?.Descriptor?.platform?.os === expectedPlatform.os &&
163+
platform?.Descriptor?.platform?.variant === expectedPlatform.variant
164+
)
165+
);
166+
167+
assert(
168+
platformExists,
169+
`Expected platform not found: os=${expectedPlatform.os},architecture=${expectedPlatform.architecture},variant=${expectedPlatform.variant}`
170+
);
171+
});
172+
173+
// Check annotations
174+
const annotations = manifest[0]?.OCIManifest?.annotations;
175+
assert(annotations, `Failed to get annotations for image: ${image}`);
176+
177+
// Check expected annotations
178+
const expectedAnnotations = {
179+
"org.opencontainers.image.source": "https://github.com/hoverkraft-tech/ci-github-container",
180+
"org.opencontainers.image.title": "ci-github-container",
181+
"org.opencontainers.image.url": "https://github.com/hoverkraft-tech/ci-github-container"
182+
};
183+
184+
Object.entries(expectedAnnotations).forEach(([key, value]) => {
185+
assert.equal(annotations[key], value, `Expected annotation not found: ${key}`);
186+
});
191187
192188
- name: Check mono-arch docker image
193-
run: |
194-
IMAGE="${{ fromJson(needs.act.outputs.built-images).application-mono-arch.images[0] }}"
195-
196-
docker pull "$IMAGE"
189+
uses: actions/[email protected]
190+
with:
191+
script: |
192+
const assert = require("assert");
197193
198-
if ! MANIFEST=$(docker manifest inspect "$IMAGE"); then
199-
echo "Failed to inspect manifest for image: ${IMAGE}"
200-
echo "${MANIFEST}"
201-
exit 1
202-
fi
194+
const image = `${{ fromJson(needs.act.outputs.built-images).application-mono-arch.images[0] }}`;
203195
204-
# Check that there is only platforms
205-
if ! PLATFORMS=$(echo "${MANIFEST}" | jq -e '[.manifests[].platform]'); then
206-
echo "Failed to get platforms for image: ${IMAGE}"
207-
echo "${MANIFEST}"
208-
exit 1
209-
fi
196+
await exec.exec('docker', ['pull', image]);
210197
211-
NB_PLATFORMS=$(echo "${PLATFORMS}" | jq -e '. | length')
212-
if [ "$NB_PLATFORMS" != "1" ]; then
213-
echo "Expected 1 platform, got: $NB_PLATFORMS"
214-
echo "${MANIFEST}"
215-
exit 1
216-
fi
198+
let manifestOutput = null;
199+
const {
200+
exitCode,
201+
stdout,
202+
stderr
203+
} = await exec.getExecOutput('docker', ['manifest', 'inspect', '-v', image]);
217204
218-
# Check if platform is valid
205+
if (exitCode !== 0 || stderr) {
206+
throw new Error(`Failed to inspect manifest for image: ${image}: ${stderr || stdout}`);
207+
}
219208
220-
## os=linux,architecture=amd64,variant=null
221-
PLATFORM_EXISTS=$(echo "${PLATFORMS}" | jq -e 'any(.architecture == "amd64" and .os == "linux" and .variant == null)')
222-
test "$PLATFORM_EXISTS" = "true"
209+
manifest = JSON.parse(stdout);
210+
211+
// Check if all platforms are valid
212+
const expectedPlatforms = [
213+
{ os: "linux", architecture: "amd64", variant: undefined }
214+
];
215+
216+
assert.equal(manifest.length, expectedPlatforms.length, `Expected ${expectedPlatforms.length} platforms, got: ${manifest.length}`);
217+
218+
expectedPlatforms.forEach(expectedPlatform => {
219+
const platformExists = manifest.some(
220+
platform => (
221+
platform?.Descriptor?.platform?.architecture === expectedPlatform.architecture &&
222+
platform?.Descriptor?.platform?.os === expectedPlatform.os &&
223+
platform?.Descriptor?.platform?.variant === expectedPlatform.variant
224+
)
225+
);
226+
227+
assert(
228+
platformExists,
229+
`Expected platform not found: os=${expectedPlatform.os},architecture=${expectedPlatform.architecture},variant=${expectedPlatform.variant}`
230+
);
231+
});
223232
224233
# jscpd:ignore-end

0 commit comments

Comments
 (0)