6.4. 재현 가능한 컨테이너 빌드 작업
ARG SOURCE_DATE_EPOCH 를 ContainerFile에 추가하여 --source-date-epoch 및 --rewrite-timestamp 옵션을 사용하여 재현 가능한 컨테이너 이미지를 빌드할 수 있습니다.
절차
Buildah명령을 실행할 때 이러한 옵션을 설정하려면 다음을 수행합니다. 예를 들어 Containerfile에서 이미지를 빌드하고 모든 타임스탬프를 특정 시점으로 강제 적용하려면 다음을 수행합니다.Use a specific, immutable image. FROM registry.access.redhat.com/ubi9/ubi:9.4 AS builder # Set the SOURCE_DATE_EPOCH for deterministic timestamps ARG SOURCE_DATE_EPOCH ENV SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-1} # Build the image using the build-arg and rewrite-timestamp options buildah bud --build-arg --source-date-epoch=${SOURCE_DATE_EPOCH} \ --rewrite-timestamp \ -f Containerfile \ -t my-reproducible-image .재현 가능한 이미지를 생성하려면 타임스탬프와 함께
podman build명령을 실행합니다.# Set a consistent timestamp using the last Git commit date export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)지정된 타임 스탬프를 사용하여 이미지를 빌드합니다.
podman build --source-date-epoch=${SOURCE_DATE_EPOCH} --rewrite-timestamp -t my-reproducible-app .
검증
빌드 후 재현 가능한 명령을 다시 실행합니다. 빌드가 실제로 재현 가능한 경우
buildah inspect명령에 동일한 이미지 다이제스트가 표시되어야 합니다.buildah bud --build-arg --source-date-epoch=${SOURCE_DATE_EPOCH} \ --rewrite-timestamp \ -f Containerfile \ -t my-reproducible-image-2 .다이제스트를 비교합니다.
buildah inspect --format '{{.Digest}}' my-reproducible-image buildah inspect --format '{{.Digest}}' my-reproducible-image-2