def main(argv=None): parser = argparse.ArgumentParser() parser.add_argument('--workdir', help='specify the working directory', metavar='DIR', default='docker_work', required=False) args = parser.parse_args() workdir = os.path.realpath(args.workdir) git_dir = join(workdir, 'sapmachine-infrastructure') utils.remove_if_exists(workdir) os.makedirs(workdir) releases = github_api_request('releases', per_page=100) infrastructure_tags = github_api_request( 'tags', repository='SapMachine-infrastructure', per_page=100) lts_release = None lts_release_major = 0 stable_release = None for release in releases: if release['prerelease']: continue version, version_part, major, build_number, sap_build_number, os_ext = utils.sapmachine_tag_components( release['name']) if utils.sapmachine_is_lts(major) and not lts_release: lts_release = release lts_release_major = major else: if not stable_release and major > lts_release_major: stable_release = release if lts_release and stable_release: break if lts_release or stable_release: utils.git_clone('github.com/SAP/SapMachine-infrastructure', 'master', git_dir) if lts_release and not stable_release: stable_release = lts_release if lts_release: print(str.format('found latest LTS release "{0}"', lts_release['name'])) process_release(lts_release, 'lts', infrastructure_tags, git_dir) if stable_release: print( str.format('found latest stable release "{0}"', stable_release['name'])) process_release(stable_release, 'stable', infrastructure_tags, git_dir) utils.remove_if_exists(workdir) return 0
def process_release(release, tags, git_dir): version, version_part, major, update, version_sap, build_number, os_ext = utils.sapmachine_tag_components( release['name']) tag_name = version_part skip_tag = False dockerfile_dir = join(git_dir, 'dockerfiles', 'official', major) for tag in tags: if tag['name'] == tag_name: print( str.format('tag "{0}" already exists for release "{1}"', tag_name, release['name'])) skip_tag = True break if not skip_tag: utils.remove_if_exists(dockerfile_dir) os.makedirs(dockerfile_dir) dockerfile_path = join(dockerfile_dir, 'Dockerfile') with open(dockerfile_path, 'w+') as dockerfile: dockerfile.write( Template(dockerfile_template).substitute(version=str.format( 'sapmachine-{0}-jdk={1}', major, version_part), major=major)) if utils.sapmachine_is_lts(major): what = 'long term support' docker_tag = major else: what = 'stable' docker_tag = 'stable' readme_path = join(dockerfile_dir, 'README.md') with open(readme_path, 'w+') as readmefile: readmefile.write( Template(readmefile_template).substitute(docker_tag=docker_tag, what=what, major=major, version=version_part)) utils.git_commit(git_dir, 'updated Dockerfile', [dockerfile_path, readme_path]) utils.git_tag(git_dir, tag_name) utils.git_push(git_dir) utils.git_push_tag(git_dir, tag_name)
def main(argv=None): parser = argparse.ArgumentParser() parser.add_argument('-t', '--tag', help='the SapMachine git tag', metavar='TAG') parser.add_argument('-b', '--build', help='the build number to use, overrules any value from tag(s)', metavar='BUILD_NR') parser.add_argument('-r', '--release', help='set if this is a release build', action='store_true', default=False) parser.add_argument('-g', '--branch', help='the SapMachine git branch', metavar='BRANCH') args = parser.parse_args() configure_opts = [] # parse tag, if given tag = None if args.tag: tag = SapMachineTag.from_string(args.tag) if tag is None: print(str.format("Passed tag {0} not recognized as SapMachine tag, handling as snapshot build", args.tag), file=sys.stderr) # parse major from SapMachine branch, if given major_from_branch = 0 if args.branch: branch_pattern = re.compile(utils.sapmachine_branch_pattern()) match = branch_pattern.match(args.branch) if match is not None: if match.group(1) is not None: major_from_branch = int(match.group(1)) else: major_from_branch = 9999 # determine and set version date release_date = None if tag is not None: releases = utils.get_github_releases() if releases is not None: for release in releases: if release['tag_name'] == tag.as_string(): release_date = release['published_at'].split('T')[0] print(str.format("Set date to release date of {0}: {1}", tag.as_string(), release_date), file=sys.stderr) break if release_date is None: print(str.format("Tag {0} does not seem to exist or data could not be loaded from GitHub", tag.as_string()), file=sys.stderr) if release_date is None: release_date = date.today().strftime("%Y-%m-%d") print(str.format("Set date to today: {0}", release_date), file=sys.stderr) configure_opts.append(VERSION_DATE_ARG.format(release_date)) # determine and set build number build_number = None if args.build is not None: build_number = args.build print(str.format("Set build number from parameter: {0}", build_number), file=sys.stderr) if build_number is None and tag is not None: build_number = tag.get_build_number() if build_number is not None: print(str.format("Set build number from tag: {0}", build_number), file=sys.stderr) else: latest_non_ga_tag = tag.get_latest_non_ga_tag() if latest_non_ga_tag is not None: build_number = latest_non_ga_tag.get_build_number() if build_number is not None: print(str.format("Tag seems to be a ga tag, using build number from latest non-ga tag {0}: {1}", latest_non_ga_tag.as_string(), build_number), file=sys.stderr) if build_number is not None: configure_opts.append(VERSION_BUILD_ARG.format(build_number)) # set version pre version_pre = '' if not args.release: if tag is None: version_pre = 'snapshot' else: version_pre = 'ea' if utils.get_arch().startswith('aarch64'): if not version_pre: version_pre = 'beta' else: version_pre += '-beta' configure_opts.append(VERSION_PRE_ARG.format(version_pre)) # set version opt if tag is None: configure_opts.append(VERSION_OPT_ARG.format(release_date)) else: if args.release and utils.sapmachine_is_lts(tag.get_major()): if tag.get_major() < 15: configure_opts.append(VERSION_OPT_ARG.format('LTS-sapmachine')) else: configure_opts.append(VERSION_OPT_ARG.format('LTS')) else: if tag.get_major() < 15: configure_opts.append(VERSION_OPT_ARG.format('sapmachine')) else: configure_opts.append(VERSION_OPT_ARG.format('')) # set version extra1 arg (= sap version) if tag is not None and tag.get_version_sap() is not None: configure_opts.append(VERSION_EXTRA1_ARG.format(tag.get_version_sap())) # set vendor version string if (tag is None or (tag.get_major() > 14) or (tag.get_major() == 14 and tag.get_update() > 1) or (tag.get_major() == 11 and tag.get_update() > 7)): configure_opts.append(VENDOR_VERSION_STRING_ARG) # set other vendor options configure_opts.append(VENDOR_NAME_ARG) configure_opts.append(VENDOR_URL_ARG) configure_opts.append(VENDOR_BUG_URL_ARG) configure_opts.append(VENDOR_VM_BUG_URL_ARG) # set getest option if 'GTEST_DIR' in os.environ: if (tag is not None and tag.get_major() >= 15) or major_from_branch >= 15: configure_opts.append(GTEST_OPT.format(os.environ['GTEST_DIR'])) print(' '.join(configure_opts)) return 0
def main(argv=None): parser = argparse.ArgumentParser() parser.add_argument('--workdir', help='specify the working directory', metavar='DIR', default='docker_work', required=False) args = parser.parse_args() workdir = os.path.realpath(args.workdir) git_dir = join(workdir, 'sapmachine-infrastructure') utils.remove_if_exists(workdir) os.makedirs(workdir) releases = github_api_request('releases', per_page=100) infrastructure_tags = utils.get_github_infrastructure_tags() docker_releases = {} stable_release = None for release in releases: if release['prerelease']: continue version, version_part, major, update, version_sap, build_number, os_ext = utils.sapmachine_tag_components( release['name']) if utils.sapmachine_is_lts(major): if major in docker_releases: _, _, _, lts_update, _, _, _ = utils.sapmachine_tag_components( docker_releases[major]['name']) if int(lts_update) < int(update): docker_releases[major] = release else: docker_releases[major] = release if stable_release == None: stable_release = release else: _, _, stable_major, stable_update, _, _, _ = utils.sapmachine_tag_components( stable_release['name']) if int(major) > int(stable_major) or ( int(major) == int(stable_major) and int(update) > int(stable_update)): stable_release = release print('Determined the following versions for processing:') for release in docker_releases: version, _, _, _, _, _, _ = utils.sapmachine_tag_components( docker_releases[release]['name']) print(str.format('LTS {1}: {0}', version, release)) stable_version, _, stable_major, _, _, _, _ = utils.sapmachine_tag_components( stable_release['name']) print(str.format('stable: {0}', stable_version)) if not (stable_version in docker_releases): docker_releases[stable_major] = stable_release utils.git_clone('github.com/SAP/SapMachine-infrastructure', 'master', git_dir) versions_dir = join(git_dir, 'dockerfiles', 'official') removed = [] for f in os.listdir(versions_dir): if not f in docker_releases: utils.remove_if_exists(join(versions_dir, f)) removed.append(join(versions_dir, f)) if removed != []: utils.git_commit(git_dir, 'remove discontinued versions', removed) for release in docker_releases: process_release(docker_releases[release], infrastructure_tags, git_dir) utils.remove_if_exists(workdir) return 0
def main(argv=None): token = utils.get_github_api_accesstoken() org = 'SAP' repository = 'SapMachine' asset_pattern = re.compile(utils.sapmachine_asset_pattern()) major_dict = {} release_dict = {} image_dict = {} latest_link_dict = {} releases = utils.github_api_request('releases', per_page=100) for release in releases: version, version_part, major, build_number, sap_build_number, os_ext = utils.sapmachine_tag_components( release['name']) is_prerelease = release['prerelease'] if version is None or os_ext: continue if major in major_dict: if not is_prerelease and major_dict[major]: # this is not a pre-release but the release before this was a pre-release # remove all assets if major in release_dict: release_dict[major].clear_assets() # remove entry in the image dictionary if major in image_dict: del image_dict[major] else: if not major_dict[major]: # the release before this was a release # skip, we only keep the latest release version continue major_dict[major] = is_prerelease assets = release['assets'] if is_prerelease is not True and major not in latest_link_dict: latest_link_dict[major] = Template(latest_template).substitute( major=major, url=release['html_url']) has_dmg = False for asset in assets: match = asset_pattern.match(asset['name']) if match is not None: asset_image_type = match.group(1) if asset_image_type == 'jdk': asset_os = match.group(3) file_type = match.group(4) if asset_os == 'windows-x64' and file_type == '.msi': asset_os = 'windows-x64-installer' if asset_os == 'osx-x64': if file_type == '.dmg': has_dmg = True elif has_dmg: continue tag = release['name'] image_is_lts = utils.sapmachine_is_lts( major) and not release['prerelease'] if major not in image_dict: image_dict[major] = { 'label': str.format('SapMachine {0}', major), 'lts': image_is_lts, 'ea': release['prerelease'] } if major in release_dict: releases = release_dict[major] else: releases = Releases(major) release_dict[major] = releases release_dict[major].add_asset( asset['browser_download_url'], asset_os, tag) latest_lts_version = 0 latest_non_lts_version = 0 for major in image_dict: if image_dict[major]['lts'] and int(major) > latest_lts_version: latest_lts_version = int(major) if not image_dict[major]['lts'] and not image_dict[major][ 'ea'] and int(major) > latest_non_lts_version: latest_non_lts_version = int(major) json_root = {'imageTypes': [], 'os': [], 'assets': {}} for major in sorted(image_dict): add = False if image_dict[major]['lts']: if int(major) >= latest_lts_version: add = True else: if int(major) >= latest_non_lts_version and int( major) >= latest_lts_version: add = True if add: json_root['imageTypes'].append({ 'id': major, 'label': image_dict[major]['label'], 'lts': image_dict[major]['lts'], 'ea': image_dict[major]['ea'] }) else: del image_dict[major] def get_os_key(os): return os_description[os]['ordinal'] for os in sorted(os_description, key=get_os_key): json_root['os'].append({ 'key': os, 'value': os_description[os]['name'], 'ordinal': os_description[os]['ordinal'] }) for major in release_dict: if major in image_dict: json_root['assets'].update(release_dict[major].transform()) files = [{ 'location': join('assets', 'data', 'sapmachine_releases.json'), 'data': json.dumps(json_root, indent=4), 'commit_message': 'Updated release data.' }] for major in latest_link_dict: files.append({ 'location': join('latest', major, 'index.md'), 'data': latest_link_dict[major], 'commit_message': str.format('Updated latest link for SapMachine {0}', major) }) push_to_git(files) return 0
def __init__(self, major): self.major = major self.lts = utils.sapmachine_is_lts(major) self.release = None self.prerelease = None
def main(argv=None): parser = argparse.ArgumentParser() parser.add_argument('-d', '--directory', help='the directory containing the Dockerfiles', metavar='DIR', required=True) parser.add_argument( '-m', '--manifest', help='the manifest file output directory and file name', metavar='FILE', required=True) args = parser.parse_args() dockerfiles_dir = args.directory manifest = args.manifest images = '' latest_lts = '00' latest = '00' releases = [] for root, dirs, files in os.walk(dockerfiles_dir, topdown=False): for dir in dirs: if re.match(r"\d\d\d?", dir): releases.append(dir) if int(dir) > int(latest): latest = dir if utils.sapmachine_is_lts(dir) and int(dir) > int(latest_lts): latest_lts = dir for release in releases: directory = join(root, release) with open(join(directory, 'Dockerfile'), 'r') as dockerfile: version_match = dockerfile_version_pattern.search( dockerfile.read()) major = version_match.group(1) version = version_match.group(2) retcode, git_commit, err = utils.run_cmd([ 'git', 'log', '-n', '1', '--pretty=format:%H', '--', join(directory, 'Dockerfile') ], std=True) tags = major if major != version: tags += str.format(', {}', version) if release == latest: tags += ', latest' if release == latest_lts: tags += ', lts' if images: images += '\n\n' images += Template(template_image).substitute( tags=tags, git_commit=git_commit, directory=directory) with open(manifest, 'w') as manifest_file: manifest_file.write( Template(template_manifest).substitute(images=images))
def main(argv=None): parser = argparse.ArgumentParser() parser.add_argument('-t', '--tag', help='the SapMachine git tag', metavar='TAG') parser.add_argument( '-m', '--major', help='the SapMachine major version, overrules any value from tag(s)', metavar='MAJOR') parser.add_argument( '-b', '--build', help='the build number, overrules any value from tag(s)', metavar='BUILD_NR') parser.add_argument('-r', '--release', help='set if this is a release build', action='store_true', default=False) args = parser.parse_args() configure_opts = [] # initialize major from args major = args.major if major is not None: major = int(major) # initialize build number from args build_number = args.build if args.build is not None: print(str.format("Set build number from parameter: {0}", build_number), file=sys.stderr) # parse tag, if given, and determine major tag = None if args.tag: tag = SapMachineTag.from_string(args.tag) if tag is None: print(str.format("Tag {0} not recognized as SapMachine tag", args.tag), file=sys.stderr) else: if (major is not None and tag.get_major() != major): print(str.format( "Warning: Using major version {0}, given by parameter. Major version from tag would be {1}.", major, tag.get_major()), file=sys.stderr) else: major = tag.get_major() # determine build number from tag if build_number is None: build_number = tag.get_build_number() if build_number is not None: print(str.format("Set build number from tag: {0}", build_number), file=sys.stderr) else: latest_non_ga_tag = tag.get_latest_non_ga_tag() if latest_non_ga_tag is not None: build_number = latest_non_ga_tag.get_build_number() if build_number is not None: print(str.format( "Tag seems to be a ga tag, using build number from latest non-ga tag {0}: {1}", latest_non_ga_tag.as_string(), build_number), file=sys.stderr) # if major could not be determined, use default if major is None: major = utils.sapmachine_default_major() # set build number if build_number is not None: configure_opts.append(VERSION_BUILD_ARG.format(build_number)) # determine and set version date in non-release builds # in release builds we rely on DEFAULT_VERSION_DATE in version-numbers.conf if not args.release: release_date = None if tag is not None: releases = utils.get_github_releases() if releases is not None: for release in releases: if release['tag_name'] == tag.as_string(): release_date = release['created_at'].split('T')[0] print(str.format( "Set date to release date of {0}: {1}", tag.as_string(), release_date), file=sys.stderr) break if release_date is None: print(str.format( "Tag {0} does not seem to exist or data could not be loaded from GitHub", tag.as_string()), file=sys.stderr) if release_date is None: release_date = date.today().strftime("%Y-%m-%d") print(str.format("Set date to today: {0}", release_date), file=sys.stderr) configure_opts.append(VERSION_DATE_ARG.format(release_date)) # set version pre version_pre = '' if not args.release: if tag is None: version_pre = 'snapshot' else: version_pre = 'ea' if utils.get_system(major) == 'linux' and utils.get_arch().startswith( 'aarch64'): if not version_pre: version_pre = 'beta' else: version_pre += '-beta' configure_opts.append(VERSION_PRE_ARG.format(version_pre)) # set version opt if tag is None: configure_opts.append(VERSION_OPT_ARG.format(release_date)) else: if args.release and utils.sapmachine_is_lts(major): if major < 15: configure_opts.append(VERSION_OPT_ARG.format('LTS-sapmachine')) else: configure_opts.append(VERSION_OPT_ARG.format('LTS')) else: if major < 15: configure_opts.append(VERSION_OPT_ARG.format('sapmachine')) else: configure_opts.append(VERSION_OPT_ARG.format('')) # set version extra1 arg (= sap version) if tag is not None and tag.get_version_sap() is not None: configure_opts.append(VERSION_EXTRA1_ARG.format(tag.get_version_sap())) # set vendor version string if (tag is None or (major > 14) or (major == 14 and tag.get_update() > 1) or (major == 11 and tag.get_update() > 7)): configure_opts.append(VENDOR_VERSION_STRING_ARG) # set other vendor options configure_opts.append(VENDOR_NAME_ARG) configure_opts.append(VENDOR_URL_ARG) configure_opts.append(VENDOR_BUG_URL_ARG) configure_opts.append(VENDOR_VM_BUG_URL_ARG) # set getest option if 'GTEST_DIR' in os.environ: if major >= 15: configure_opts.append(GTEST_OPT.format(os.environ['GTEST_DIR'])) print(' '.join(configure_opts)) return 0