Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/__test-action-docker-promote-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,44 @@ jobs:
lint: ""
code-ql: '{"languages":"typescript","config-file":".github/codeql/config.yml"}'
test: '{"comment":false,"report-group":"test-action-docker-promote-images"}'

registry-copy:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
services:
source:
image: registry:3.1.2@sha256:82f6ff4a7f982960c8aa51617fea3aabc485df6e55cce80d22deb1de36f1bc3c
ports:
- 5000/tcp
destination:
image: registry:3.1.2@sha256:82f6ff4a7f982960c8aa51617fea3aabc485df6e55cce80d22deb1de36f1bc3c
ports:
- 5000/tcp
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
with:
driver: docker
- uses: regclient/actions/regctl-installer@dd58ad94f76adb73d8ac1bf75ed25f01545d5b32 # v0.2.0
with:
# renovate: datasource=github-releases depName=regclient/regclient
release: v0.11.7
- name: Verify cross-registry manifests and attachments
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
SOURCE_REGISTRY: localhost:${{ job.services.source.ports['5000'] }}
DESTINATION_REGISTRY: localhost:${{ job.services.destination.ports['5000'] }}
REGCTL_CONFIG: ${{ runner.temp }}/regctl-copy-fixture.json
with:
script: |
const { pathToFileURL } = require('node:url');
const { prepare, copyAndVerify } = await import(pathToFileURL(`${process.env.GITHUB_WORKSPACE}/tests/docker-promote-images/registry-fixture.mjs`));
for (const registry of [process.env.SOURCE_REGISTRY, process.env.DESTINATION_REGISTRY]) {
await exec.exec('regctl', ['registry', 'set', registry, '--tls', 'disabled']);
}
const images = await prepare(exec, process.env.RUNNER_TEMP, process.env.SOURCE_REGISTRY, process.env.DESTINATION_REGISTRY);
await copyAndVerify(exec, images);
50 changes: 44 additions & 6 deletions .github/workflows/__test-workflow-docker-build-images-building.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ jobs:
pull-requests: read
with:
job-results: ${{ toJSON(needs) }}
additional-destinations: |
{
"test-candidate-${{ github.run_id }}-${{ github.run_attempt }}-single": [
"ghcr.io/${{ github.repository }}/test-promoted-${{ github.run_id }}-${{ github.run_attempt }}-single:1.2.3"
],
"test-candidate-${{ github.run_id }}-${{ github.run_attempt }}-multi": [
"ghcr.io/${{ github.repository }}/test-promoted-${{ github.run_id }}-${{ github.run_attempt }}-multi:1.2.3"
]
}
secrets:
oci-registry-password: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -305,12 +314,15 @@ jobs:
env:
CANDIDATES: ${{ needs.act-candidates.outputs.built-images }}
PROMOTED: ${{ needs.promote-candidates.outputs.built-images }}
ADDITIONAL: ${{ needs.promote-candidates.outputs.additional-images }}
GH_TOKEN: ${{ github.token }}
with:
script: |
const assert = require('node:assert/strict');
const candidates = JSON.parse(process.env.CANDIDATES);
const promoted = JSON.parse(process.env.PROMOTED);
const additional = JSON.parse(process.env.ADDITIONAL);
assert.deepEqual(Object.keys(additional).sort(), Object.keys(candidates).sort());
assert.deepEqual(Object.keys(promoted).sort(), Object.keys(candidates).sort());
for (const [name, candidate] of Object.entries(candidates)) {
const image = promoted[name];
Expand All @@ -324,9 +336,15 @@ jobs:
const before = await exec.getExecOutput('docker', ['buildx', 'imagetools', 'inspect', '--raw', `${reference}@${candidate.digest}`]);
const after = await exec.getExecOutput('docker', ['buildx', 'imagetools', 'inspect', '--raw', `${reference}:1.2.3`]);
assert.equal(after.stdout, before.stdout, 'Promotion must retain exact manifest bytes');
await exec.exec('gh', ['attestation', 'verify', `oci://${image.images[0]}`, '--repo', process.env.GITHUB_REPOSITORY]);
const extra = `${reference.replace('/test-candidate-', '/test-promoted-')}:1.2.3`;
assert.deepEqual(additional[name], [`${extra}@${candidate.digest}`]);
const copied = await exec.getExecOutput('docker', ['buildx', 'imagetools', 'inspect', '--raw', extra]);
assert.equal(copied.stdout, before.stdout, 'Cross-repository copies must retain exact manifest bytes');
for (const reference of [...image.images, ...additional[name]]) {
await exec.exec('gh', ['attestation', 'verify', `oci://${reference}`, '--repo', process.env.GITHUB_REPOSITORY]);
}
}
core.setOutput('references', JSON.stringify(Object.values(promoted).flatMap(image => image.images)));
core.setOutput('references', JSON.stringify([...Object.values(promoted).flatMap(image => image.images), ...Object.values(additional).flat()]));

- name: Verify retained image signatures
uses: $/actions/docker/verify-images
Expand All @@ -347,6 +365,15 @@ jobs:
pull-requests: read
with:
job-results: ${{ toJSON(needs) }}
additional-destinations: |
{
"test-candidate-${{ github.run_id }}-${{ github.run_attempt }}-single": [
"ghcr.io/${{ github.repository }}/test-promoted-${{ github.run_id }}-${{ github.run_attempt }}-single:1.2.3"
],
"test-candidate-${{ github.run_id }}-${{ github.run_attempt }}-multi": [
"ghcr.io/${{ github.repository }}/test-promoted-${{ github.run_id }}-${{ github.run_attempt }}-multi:1.2.3"
]
}
build-workflow: ${{ github.repository }}/.github/workflows/docker-build-images.yml
secrets:
oci-registry-password: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -362,13 +389,21 @@ jobs:
env:
FIRST: ${{ needs.promote-candidates.outputs.built-images }}
SECOND: ${{ needs.repeat-promotion.outputs.built-images }}
FIRST_ADDITIONAL: ${{ needs.promote-candidates.outputs.additional-images }}
SECOND_ADDITIONAL: ${{ needs.repeat-promotion.outputs.additional-images }}
with:
script: |
const assert = require('node:assert/strict');
const images = JSON.parse(process.env.FIRST);
assert.deepEqual(images, JSON.parse(process.env.SECOND));
const additional = JSON.parse(process.env.FIRST_ADDITIONAL);
assert.deepEqual(additional, JSON.parse(process.env.SECOND_ADDITIONAL));
const destinations = Object.fromEntries(Object.values(images).flatMap(image =>
image.tags.map(tag => [`${image.registry}/${image.repository}:${tag}`, image.digest])));
for (const reference of Object.values(additional).flat()) {
const [destination, digest] = reference.split('@');
destinations[destination] = digest;
}
const records = await github.paginate(github.rest.repos.listDeployments, {
...context.repo, environment: 'ci-image-promotion', task: 'ci-image-promotion', per_page: 100,
});
Expand Down Expand Up @@ -434,8 +469,9 @@ jobs:
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
for (const suffix of ['single', 'multi', 'failed']) {
const name = `test-candidate-${context.runId}-${process.env.GITHUB_RUN_ATTEMPT}-${suffix}`;
for (const suffix of ['candidate-single', 'candidate-multi', 'candidate-failed', 'promoted-single', 'promoted-multi']) {
const [kind, platform] = suffix.split('-');
const name = `test-${kind}-${context.runId}-${process.env.GITHUB_RUN_ATTEMPT}-${platform}`;
try {
await github.rest.packages.deletePackageForOrg({
package_type: 'container', package_name: `${context.repo.repo}/${name}`, org: context.repo.owner,
Expand All @@ -448,12 +484,14 @@ jobs:
const records = await github.paginate(github.rest.repos.listDeployments, {
...context.repo, environment: 'ci-image-promotion', task: 'ci-image-promotion', per_page: 100,
});
const prefix = `ghcr.io/${process.env.GITHUB_REPOSITORY.toLowerCase()}/test-candidate-${context.runId}-${process.env.GITHUB_RUN_ATTEMPT}-`;
const repository = process.env.GITHUB_REPOSITORY.toLowerCase();
const run = `${context.runId}-${process.env.GITHUB_RUN_ATTEMPT}`;
const prefixes = ['candidate', 'promoted'].map(kind => `ghcr.io/${repository}/test-${kind}-${run}-`);
for (const record of records) {
const payload = record.payload;
if (payload?.runId !== String(context.runId) || payload.attempt !== process.env.GITHUB_RUN_ATTEMPT) continue;
const destinations = Object.keys(payload.destinations || {});
if (!destinations.length || !destinations.every(destination => destination.startsWith(prefix))) continue;
if (!destinations.length || !destinations.every(destination => prefixes.some(prefix => destination.startsWith(prefix)))) continue;
await github.rest.repos.createDeploymentStatus({ ...context.repo, deployment_id: record.id, state: 'inactive', auto_inactive: false });
await github.rest.repos.deleteDeployment({ ...context.repo, deployment_id: record.id });
}
Expand Down
Loading
Loading