scripts/lib: Allow to override build date

Allow to override build date with SOURCE_DATE_EPOCH
in order to make builds reproducible.
See https://reproducible-builds.org/ for why this is good
and https://reproducible-builds.org/specs/source-date-epoch/
for the definition of this variable.

Also use UTC to be independent of timezone.

This date call only works with GNU date.

Without this patch, kata-containers-initrd.img contained
varying var/lib/osbuilder/osbuilder.yaml with
   version: "1.9.0-alpha0"
   -rootfs-creation-time: "2019-08-06T18:40:27.402493939+0000Z"
   +rootfs-creation-time: "2034-09-08T07:57:34.386990704+0000Z"

Fixes #340

Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
This commit is contained in:
Bernhard M. Wiedemann 2019-08-08 12:28:22 +02:00
parent 269d31a9ac
commit dacd2d34b9

View File

@ -170,7 +170,7 @@ create_summary_file()
local -r filename="osbuilder.yaml" local -r filename="osbuilder.yaml"
local file="${dir}/${filename}" local file="${dir}/${filename}"
local -r now=$(date '+%Y-%m-%dT%T.%N%zZ') local -r now=$(date -u -d@${SOURCE_DATE_EPOCH:-$(date +%s.%N)} '+%Y-%m-%dT%T.%N%zZ')
# sanitise package lists # sanitise package lists
PACKAGES=$(echo "$PACKAGES"|tr ' ' '\n'|sort -u|tr '\n' ' ') PACKAGES=$(echo "$PACKAGES"|tr ' ' '\n'|sort -u|tr '\n' ' ')