Reproducible builds with GitHub Actions
Docker Docs · نسخهٔ 747e4c7528c7 · CC BY 4.0 برای مستندات و مجوزهای همراه
SOURCE_DATE_EPOCH is a [standardized environment variable][source_date_epoch] for instructing build tools to produce a reproducible output. Setting the environment variable for a build makes the timestamps in the image index, config, and file metadata reflect the specified Unix time.
[source_date_epoch]: https://reproducible-builds.org/docs/source-date-epoch/
With Docker GitHub Builder, pass SOURCE_DATE_EPOCH as a build argument. With individual actions, use the built-in env property on the build step.
Unix epoch timestamps
The following example sets the SOURCE_DATE_EPOCH variable to 0, Unix epoch.
Set the epoch with GitHub Builder {#set-the-epoch-with-builder}
Pass the fixed epoch through the Build workflow:
name: ci
on:
push:
jobs:
build:
uses: docker/github-builder/.github/workflows/build.yml@{{% param "github_builder_version" %}}
permissions:
contents: read
id-token: write
with:
output: image
build-args: |
SOURCE_DATE_EPOCH=0
meta-images: user/appFor the Bake workflow, set *.args.SOURCE_DATE_EPOCH=0 using the set input.
Set the epoch with individual actions
{{< tabs group="action" >}} {{< tab name="docker/build-push-action" >}}
name: ci
on:
push:
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@{{% param "setup_buildx_action_version" %}}
- name: Build
uses: docker/build-push-action@{{% param "build_push_action_version" %}}
with:
tags: user/app:latest
env:
SOURCE_DATE_EPOCH: 0{{< /tab >}} {{< tab name="docker/bake-action" >}}
name: ci
on:
push:
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@{{% param "setup_buildx_action_version" %}}
- name: Build
uses: docker/bake-action@{{% param "bake_action_version" %}}
env:
SOURCE_DATE_EPOCH: 0{{< /tab >}} {{< /tabs >}}
Git commit timestamps
The following individual-action examples set SOURCE_DATE_EPOCH to the Git commit timestamp. Keep timestamp generation in the caller when it depends on a workflow step. A reusable workflow call cannot reference earlier steps in the same job.
{{< tabs group="action" >}} {{< tab name="docker/build-push-action" >}}
name: ci
on:
push:
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@{{% param "setup_buildx_action_version" %}}
- name: Get Git commit timestamps
run: echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV
- name: Build
uses: docker/build-push-action@{{% param "build_push_action_version" %}}
with:
tags: user/app:latest
env:
SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }}{{< /tab >}} {{< tab name="docker/bake-action" >}}
name: ci
on:
push:
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@{{% param "setup_buildx_action_version" %}}
- name: Get Git commit timestamps
run: echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV
- name: Build
uses: docker/bake-action@{{% param "bake_action_version" %}}
env:
SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }}{{< /tab >}} {{< /tabs >}}
Additional information
For more information about the SOURCE_DATE_EPOCH support in BuildKit, see BuildKit documentation.