Skip to content

Commit 3c0dd23

Browse files
bmwiedemanndlorenc
authored andcommitted
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. Fixes #3005
1 parent 703f76d commit 3c0dd23

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

hack/get_k8s_version.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
"This package gets the LD flags used to set the version of kubernetes."
1818

1919
import json
20+
import os
2021
import re
2122
import subprocess
2223
import sys
24+
import time
2325
from datetime import datetime
2426

2527
K8S_PACKAGE = 'k8s.io/kubernetes/'
@@ -63,7 +65,8 @@ def get_tree_state():
6365
return 'gitTreeState=%s' % result
6466

6567
def get_build_date():
66-
return 'buildDate=%s' % datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ')
68+
build_date = datetime.utcfromtimestamp(int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))
69+
return 'buildDate=%s' % build_date.strftime('%Y-%m-%dT%H:%M:%SZ')
6770

6871
def main():
6972
if len(sys.argv) > 1 and sys.argv[1] == "--k8s-version-only":

0 commit comments

Comments
 (0)