Docker の検索・質問

GitHub Actions を使った再現可能なビルド

How to create reproducible builds in GitHub Actions using the SOURCE_EPOCH environment variable

マークダウン参照

SOURCE_DATE_EPOCH は 標準化された環境変数 (standardized environment variable) であり、ビルドツールに対して再現可能なビルドを生成することを指示します。 ビルドの際にこの環境変数を設定しておくと、イメージインデックス、設定情報、ファイルメタデータの中にあるタイムスタンプを、指定された Unix 時間にすることができます。

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 エポックのタイムスタンプ

以下の例では SOURCE_DATE_EPOCH を Unix エポック時間の値 0 に設定します。

Set the epoch with GitHub Builder

Pass the fixed epoch through the Build workflow :

name: ci

on:
  push:

jobs:
  build:
    uses: docker/github-builder/.github/workflows/build.yml@v1
    permissions:
      contents: read
      id-token: write
    with:
      output: image
      build-args: |
        SOURCE_DATE_EPOCH=0
      meta-images: user/app

For the Bake workflow , set *.args.SOURCE_DATE_EPOCH=0 using the set input.

Set the epoch with individual actions

name: ci

on:
  push:

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v4

      - name: Build
        uses: docker/build-push-action@v7
        with:
          tags: user/app:latest
        env:
          SOURCE_DATE_EPOCH: 0
name: ci

on:
  push:

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v4

      - name: Build
        uses: docker/bake-action@v7
        env:
          SOURCE_DATE_EPOCH: 0

Git コミットのタイムスタンプ

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.

name: ci

on:
  push:

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v4

      - name: Get Git commit timestamps
        run: echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV

      - name: Build
        uses: docker/build-push-action@v7
        with:
          tags: user/app:latest
        env:
          SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }}
name: ci

on:
  push:

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v4

      - name: Get Git commit timestamps
        run: echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV

      - name: Build
        uses: docker/bake-action@v7
        env:
          SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }}

Derive the timestamp from a Git context

Set SOURCE_DATE_EPOCH=context to use the Git context's commit timestamp without a separate shell step:

- name: Build
  uses: docker/build-push-action@v7
  with:
    tags: user/app:latest
    build-args: |
      SOURCE_DATE_EPOCH=context

This example uses the action's default Git context. For a checked-out repository passed as context: ., use an explicit timestamp instead. See Derive the timestamp from the build context for other context types, or define a default in the Dockerfile .

さらなる情報

BuildKit における SOURCE_DATE_EPOCH サポートの詳細は BuildKit ドキュメント を参照してください。