Skip to content
Merged
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
89 changes: 89 additions & 0 deletions .github/workflows/.test-bake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,92 @@ jobs:
username: ${{ vars.DOCKERHUB_OIDC_USERNAME }}
connection_id: ${{ vars.DOCKERHUB_OIDC_CONNECTIONID }}
scope: 'dhi.io@pull'

bake-source-date-epoch:
strategy:
matrix:
epoch:
- '0'
- '1704067200'
- 'commit'
output:
- image
- local
uses: ./.github/workflows/bake.yml
permissions:
contents: read
id-token: write
packages: write
with:
output: ${{ matrix.output }}
push: ${{ matrix.output == 'image' && github.event_name != 'pull_request' }}
source-date-epoch: ${{ matrix.epoch }}
set-meta-labels: true
set-meta-annotations: true
meta-images: ghcr.io/docker/github-builder-test
meta-tags: |
type=raw,value=bake-epoch-${{ matrix.epoch }}-${{ github.run_id }}-${{ github.run_attempt }}
meta-labels: |
org.opencontainers.image.created=2000-01-01T00:00:00Z
meta-annotations: |
org.opencontainers.image.created=2000-01-01T00:00:00Z
context: test
target: source-date-epoch
set: |
*.args.SOURCE_DATE_EPOCH=1
*.args.EXPECTED_EPOCH=${{ matrix.epoch }}
secrets:
registry-auths: |
- registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

bake-source-date-epoch-verify:
if: ${{ github.event_name != 'pull_request' }}
needs:
- bake-source-date-epoch
runs-on: ubuntu-26.04
permissions:
packages: read
strategy:
matrix:
epoch:
- '0'
- '1704067200'
- 'commit'
steps:
-
name: Login to GHCR
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Check image file timestamp
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
IMAGE: ghcr.io/docker/github-builder-test:bake-epoch-${{ matrix.epoch }}-${{ github.run_id }}-${{ github.run_attempt }}
with:
script: |
const assert = require('node:assert/strict');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');

const image = process.env.IMAGE;
await exec.exec('docker', ['pull', '--platform', 'linux/amd64', image]);
const {stdout} = await exec.getExecOutput('docker', ['create', '--platform', 'linux/amd64', image, '/unused']);
const container = stdout.trim();
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'source-date-epoch-'));
try {
const file = path.join(directory, 'epoch');
await exec.exec('docker', ['cp', `${container}:/epoch`, file]);
const epoch = Number(fs.readFileSync(file, 'utf8').trim());
const mtime = fs.statSync(file).mtimeMs / 1000;
assert.equal(mtime, epoch, `Expected image file timestamp ${epoch}, got ${mtime}`);
core.info(`Image file timestamp matches SOURCE_DATE_EPOCH=${epoch}`);
} finally {
await exec.exec('docker', ['rm', container]);
fs.rmSync(directory, {recursive: true, force: true});
}
89 changes: 89 additions & 0 deletions .github/workflows/.test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -759,3 +759,92 @@ jobs:
username: ${{ vars.DOCKERHUB_OIDC_USERNAME }}
connection_id: ${{ vars.DOCKERHUB_OIDC_CONNECTIONID }}
scope: 'dhi.io@pull'

build-source-date-epoch:
strategy:
matrix:
epoch:
- '0'
- '1704067200'
- 'commit'
output:
- image
- local
uses: ./.github/workflows/build.yml
permissions:
contents: read
id-token: write
packages: write
with:
output: ${{ matrix.output }}
push: ${{ matrix.output == 'image' && github.event_name != 'pull_request' }}
platforms: linux/amd64
source-date-epoch: ${{ matrix.epoch }}
set-meta-labels: true
set-meta-annotations: true
meta-images: ghcr.io/docker/github-builder-test
meta-tags: |
type=raw,value=build-epoch-${{ matrix.epoch }}-${{ github.run_id }}-${{ github.run_attempt }}
meta-labels: |
org.opencontainers.image.created=2000-01-01T00:00:00Z
meta-annotations: |
org.opencontainers.image.created=2000-01-01T00:00:00Z
file: test/source-date-epoch.Dockerfile
build-args: |
SOURCE_DATE_EPOCH=1
EXPECTED_EPOCH=${{ matrix.epoch }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test something that relies on rewrite-timestamps?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

secrets:
registry-auths: |
- registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

build-source-date-epoch-verify:
if: ${{ github.event_name != 'pull_request' }}
needs:
- build-source-date-epoch
runs-on: ubuntu-26.04
permissions:
packages: read
strategy:
matrix:
epoch:
- '0'
- '1704067200'
- 'commit'
steps:
-
name: Login to GHCR
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Check image file timestamp
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
IMAGE: ghcr.io/docker/github-builder-test:build-epoch-${{ matrix.epoch }}-${{ github.run_id }}-${{ github.run_attempt }}
with:
script: |
const assert = require('node:assert/strict');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');

const image = process.env.IMAGE;
await exec.exec('docker', ['pull', '--platform', 'linux/amd64', image]);
const {stdout} = await exec.getExecOutput('docker', ['create', '--platform', 'linux/amd64', image, '/unused']);
const container = stdout.trim();
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'source-date-epoch-'));
try {
const file = path.join(directory, 'epoch');
await exec.exec('docker', ['cp', `${container}:/epoch`, file]);
const epoch = Number(fs.readFileSync(file, 'utf8').trim());
const mtime = fs.statSync(file).mtimeMs / 1000;
assert.equal(mtime, epoch, `Expected image file timestamp ${epoch}, got ${mtime}`);
core.info(`Image file timestamp matches SOURCE_DATE_EPOCH=${epoch}`);
} finally {
await exec.exec('docker', ['rm', container]);
fs.rmSync(directory, {recursive: true, force: true});
}
40 changes: 35 additions & 5 deletions .github/workflows/bake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ on:
description: "Sign attestation manifest for image output or artifacts for local output, can be one of auto, true or false. The auto mode will enable signing if push is enabled for pushing the image or if artifact-upload is enabled for uploading the local build output as GitHub Artifact"
required: false
default: auto
source-date-epoch:
type: string
description: "Reproducible timestamp: commit or a non-negative Unix timestamp (empty disables)"
required: false
target:
type: string
description: "Bake target to build"
Expand Down Expand Up @@ -219,6 +223,8 @@ jobs:
include:
- name: ${{ inputs.job-name-prefix }}
outputs:
sourceDateEpoch: ${{ steps.set.outputs.sourceDateEpoch }}
sourceDateCreated: ${{ steps.set.outputs.sourceDateCreated }}
includes: ${{ steps.set.outputs.includes }}
metaImages: ${{ steps.set.outputs.metaImages }}
sign: ${{ steps.set.outputs.sign }}
Expand Down Expand Up @@ -330,6 +336,7 @@ jobs:
INPUT_SBOM: ${{ inputs.sbom }}
INPUT_SET: ${{ inputs.set }}
INPUT_SIGN: ${{ inputs.sign }}
INPUT_SOURCE-DATE-EPOCH: ${{ inputs.source-date-epoch }}
INPUT_TARGET: ${{ inputs.target }}
INPUT_VARS: ${{ inputs.vars }}
INPUT_GITHUB-TOKEN: ${{ secrets.github-token || github.token }}
Expand All @@ -341,6 +348,7 @@ jobs:
const { Build } = require('@docker/github-builder-runtime/lib/buildx/build');
const { GitHub } = require('@docker/github-builder-runtime/lib/github/github');
const { MetaImages } = require('@docker/github-builder-runtime/lib/github-builder/meta-images');
const { SourceDateEpoch } = require('@docker/github-builder-runtime/lib/github-builder/source-date-epoch');
const { RunnerMapping } = require('@docker/github-builder-runtime/lib/github-builder/runner-mapping');
const { BakeTargets } = require('@docker/github-builder-runtime/lib/github-builder/bake-targets');
const { BakeVars } = require('@docker/github-builder-runtime/lib/github-builder/bake-vars');
Expand All @@ -364,10 +372,17 @@ jobs:
const inpSbom = core.getBooleanInput('sbom');
const inpSet = Util.getInputList('set', {ignoreComma: true, quote: false});
const inpSign = core.getInput('sign');
const inpSourceDateEpoch = core.getInput('source-date-epoch');
const inpTarget = core.getInput('target');
const inpGitHubToken = core.getInput('github-token');
const inpProxyNetwork = core.getBooleanInput('buildkit-proxy-network');

if (inpSourceDateEpoch !== '') {
const {epoch, created} = await SourceDateEpoch.resolve(inpSourceDateEpoch, {token: inpGitHubToken});
core.setOutput('sourceDateEpoch', epoch);
core.setOutput('sourceDateCreated', created);
}

let runnerConfig;
try {
runnerConfig = RunnerMapping.parse(inpRunner);
Expand Down Expand Up @@ -595,8 +610,12 @@ jobs:
images: ${{ needs.prepare.outputs.metaImages }}
tags: ${{ inputs.meta-tags }}
flavor: ${{ inputs.meta-flavor }}
labels: ${{ inputs.meta-labels }}
annotations: ${{ inputs.meta-annotations }}
labels: |
${{ inputs.meta-labels }}
${{ needs.prepare.outputs.sourceDateCreated != '' && format('org.opencontainers.image.created={0}', needs.prepare.outputs.sourceDateCreated) || '' }}
annotations: |
${{ inputs.meta-annotations }}
${{ needs.prepare.outputs.sourceDateCreated != '' && format('org.opencontainers.image.created={0}', needs.prepare.outputs.sourceDateCreated) || '' }}
bake-target: ${{ inputs.meta-bake-target }}
-
name: Set up QEMU
Expand Down Expand Up @@ -822,6 +841,7 @@ jobs:
id: prepare
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
INPUT_SOURCE-DATE-EPOCH: ${{ needs.prepare.outputs.sourceDateEpoch }}
INPUT_PLATFORM: ${{ matrix.platform }}
INPUT_SBOM-IMAGE: ${{ env.SBOM_IMAGE }}
INPUT_LOCAL-EXPORT-DIR: ${{ env.LOCAL_EXPORT_DIR }}
Expand Down Expand Up @@ -856,6 +876,9 @@ jobs:
const { GitHub } = require('@docker/github-builder-runtime/lib/github/github');
const { Util } = require('@docker/github-builder-runtime/lib/util');

const inpSourceDateEpoch = core.getInput('source-date-epoch');
const rewriteTimestamp = inpSourceDateEpoch !== '' ? ',rewrite-timestamp=true' : '';

const inpPlatform = core.getInput('platform');
const platformPairSuffix = inpPlatform ? `-${inpPlatform.replace(/\//g, '-')}` : '';
core.setOutput('platform-pair-suffix', platformPairSuffix);
Expand Down Expand Up @@ -954,7 +977,7 @@ jobs:
core.setFailed('meta-images is required when output is image');
return;
}
outputOverride = `*.output=type=image,"name=${inpMetaImages.join(',')}",oci-artifact=true,push-by-digest=true,name-canonical=true,push=${inpPush}`;
outputOverride = `*.output=type=image,"name=${inpMetaImages.join(',')}",oci-artifact=true,push-by-digest=true,name-canonical=true,push=${inpPush}${rewriteTimestamp}`;
break;
case 'local':
outputOverride = `*.output=type=local,platform-split=true,dest=${inpLocalExportDir}`;
Expand All @@ -972,6 +995,9 @@ jobs:
return;
}
await core.group(`Set bake overrides`, async () => {
if (inpSourceDateEpoch !== '') {
bakeOverrides.push(`*.args.SOURCE_DATE_EPOCH=${inpSourceDateEpoch}`);
}
bakeOverrides.push(outputOverride);
bakeOverrides.push('*.tags=');
if (GitHub.context.payload.repository?.private ?? false) {
Expand Down Expand Up @@ -1254,8 +1280,12 @@ jobs:
images: ${{ needs.prepare.outputs.metaImages }}
tags: ${{ inputs.meta-tags }}
flavor: ${{ inputs.meta-flavor }}
labels: ${{ inputs.meta-labels }}
annotations: ${{ inputs.meta-annotations }}
labels: |
${{ inputs.meta-labels }}
${{ needs.prepare.outputs.sourceDateCreated != '' && format('org.opencontainers.image.created={0}', needs.prepare.outputs.sourceDateCreated) || '' }}
annotations: |
${{ inputs.meta-annotations }}
${{ needs.prepare.outputs.sourceDateCreated != '' && format('org.opencontainers.image.created={0}', needs.prepare.outputs.sourceDateCreated) || '' }}
bake-target: ${{ inputs.meta-bake-target }}
-
name: Configure AWS credentials
Expand Down
Loading
Loading