include docker tag in build info

This commit is contained in:
Alex Grintsvayg 2020-01-23 12:38:41 -05:00
parent 7fd56e0add
commit fb568768c5
No known key found for this signature in database
GPG key ID: AEB3F089F86A22B5
2 changed files with 24 additions and 20 deletions

View file

@ -1,38 +1,41 @@
"""Set the build version to be 'qa', 'rc', 'release'"""
import sys import sys
import os import os
import re import re
import logging import logging
import lbry.build_info as build_info_mod
log = logging.getLogger() log = logging.getLogger()
log.addHandler(logging.StreamHandler()) log.addHandler(logging.StreamHandler())
log.setLevel(logging.DEBUG) log.setLevel(logging.DEBUG)
def get_build_type(ci_tag=None): def _check_and_set(d: dict, key: str, value: str):
if not ci_tag: try:
return "qa" d[key]
log.debug("getting build type for tag: \"%s\"", ci_tag) except KeyError:
if re.match(r'v\d+\.\d+\.\d+rc\d+$', ci_tag): raise Exception(f"{key} var does not exist in {build_info_mod.__file__}")
return 'rc' d[key] = value
elif re.match(r'v\d+\.\d+\.\d+$', ci_tag):
return 'release'
return 'qa'
def main(): def main():
root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) build_info = {item: build_info_mod.__dict__[item] for item in dir(build_info_mod) if not item.startswith("__")}
build_type_path = os.path.join(root_dir, 'lbry', 'build_type.py')
log.debug("configuring build type file: %s", build_type_path) commit_hash = os.getenv('DOCKER_COMMIT', os.getenv('CI_COMMIT_SHA', os.getenv('TRAVIS_COMMIT')))
commit_hash = os.getenv('CI_COMMIT_SHA', os.getenv('TRAVIS_COMMIT'))
if commit_hash is None: if commit_hash is None:
raise ValueError("Commit hash not found in env vars") raise ValueError("Commit hash not found in env vars")
commit_hash = commit_hash[:6] _check_and_set(build_info, "COMMIT_HASH", commit_hash[:6])
build_type = get_build_type(os.getenv('CI_COMMIT_TAG', os.getenv('TRAVIS_TAG')))
log.debug("setting build type=%s, build commit=%s", build_type, commit_hash) docker_tag = os.getenv('DOCKER_TAG')
with open(build_type_path, 'w') as f: if docker_tag:
f.write(f"BUILD = \"{build_type}\"\nCOMMIT_HASH = \"{commit_hash}\"\n") _check_and_set(build_info, "DOCKER_TAG", docker_tag)
_check_and_set(build_info, "BUILD", "docker")
else:
ci_tag = os.getenv('CI_COMMIT_TAG', os.getenv('TRAVIS_TAG'))
_check_and_set(build_info, "BUILD", "release" if re.match(r'v\d+\.\d+\.\d+$', str(ci_tag)) else "qa")
log.debug("build info: %s", ", ".join([f"{k}={v}" for k, v in build_info.items()]))
with open(build_info_mod.__file__, 'w') as f:
f.write("\n".join([f"{k} = \"{v}\"" for k, v in build_info.items()]) + "\n")
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -1,3 +1,4 @@
# don't touch this. CI server changes this during build/deployment # don't touch this. CI server changes this during build/deployment
BUILD = "dev" BUILD = "dev"
COMMIT_HASH = "none" COMMIT_HASH = "none"
DOCKER_TAG = "none"