Skip to content

Commit

Permalink
Allow to override build date with SOURCE_DATE_EPOCH
Browse files Browse the repository at this point in the history
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 kubernetes#3005
  • Loading branch information
bmwiedemann authored and dlorenc committed Jul 24, 2018
1 parent 703f76d commit 3c0dd23
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion hack/get_k8s_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
"This package gets the LD flags used to set the version of kubernetes."

import json
import os
import re
import subprocess
import sys
import time
from datetime import datetime

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

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

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

0 comments on commit 3c0dd23

Please sign in to comment.