|
| 1 | +#!/usr/bin/python |
| 2 | +# |
| 3 | +# Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights |
| 4 | +# Reserved. |
| 5 | +# |
| 6 | +# Additional copyrights may follow |
| 7 | +# |
| 8 | +# This script is used to upload new release artifacts to the Open MPI |
| 9 | +# organization's S3 release bucket. See ./upload-release-to-s3.py |
| 10 | +# --help for more information on command line arguments. |
| 11 | +# |
| 12 | +# In general, the usage flow looks something like: |
| 13 | +# * Log into aws.open-mpi.org |
| 14 | +# * Clone https://github.com/bwbarrett/ompi-www.git somewhere in |
| 15 | +# your ~/www directory |
| 16 | +# * Go to https://aws.open-mpi.org/~[your userid]/<clone location>/ and |
| 17 | +# make sure it is working |
| 18 | +# * Use upload-release-to-s3.py to push release artifacts |
| 19 | +# * Edit software/<project>/<release branch>/version.inc to make |
| 20 | +# the release "live" |
| 21 | +# * Visit the web site and make sure the right things appeared. |
| 22 | +# * Commit web page changes. The HostGator site syncs from GitHub |
| 23 | +# every 15 minutes. |
| 24 | +# |
| 25 | + |
| 26 | +import argparse |
| 27 | +import boto3 |
| 28 | +import botocore |
| 29 | +import urlparse |
| 30 | +import sys |
| 31 | +import re |
| 32 | +import os |
| 33 | +import dateutil |
| 34 | +import time |
| 35 | +import uploadutils |
| 36 | + |
| 37 | + |
| 38 | +default_s3_base = 's3://open-mpi-release/release' |
| 39 | +default_region = 'us-west-2' |
| 40 | + |
| 41 | + |
| 42 | +def arg_check_copy(target, source, name): |
| 43 | + if not name in source: |
| 44 | + print('%s not specified but is required either because --yes was specified' % (name)) |
| 45 | + print('or one of --project, --branch, --version, or --date was specified.') |
| 46 | + exit(1) |
| 47 | + target[name] = source[name] |
| 48 | + |
| 49 | + |
| 50 | +parser = argparse.ArgumentParser(description='Upload project release to S3', |
| 51 | + epilog='If any of --project, --base, --version, ' + |
| 52 | + 'or --date are specified, all 4 options must be ' + |
| 53 | + 'specified. If none are specified, the script ' + |
| 54 | + 'will attempt to guess the options.') |
| 55 | +parser.add_argument('--region', |
| 56 | + help='Default AWS region', |
| 57 | + type=str, required=False, default=default_region) |
| 58 | +parser.add_argument('--s3-base', |
| 59 | + help='S3 base URL. Optional, defaults to s3://open-mpi-release/release', |
| 60 | + type=str, required=False, default=default_s3_base) |
| 61 | +parser.add_argument('--project', |
| 62 | + help='Project (open-mpi, hwloc, etc.) for release being pushed', |
| 63 | + type=str, required=False) |
| 64 | +parser.add_argument('--branch', |
| 65 | + help='Release branch for release', |
| 66 | + type=str, required=False) |
| 67 | +parser.add_argument('--version', |
| 68 | + help='Version for release', |
| 69 | + type=str, required=False) |
| 70 | +parser.add_argument('--date', |
| 71 | + help='Specify release date, in the local timezone', |
| 72 | + type=str, required=False) |
| 73 | +parser.add_argument('--yes', |
| 74 | + help='Assume yes to go/no go question. Note that you must ' + |
| 75 | + 'specify --s3-base, --project, --branch, and --date ' + |
| 76 | + 'explicitly when using --yes and --yes will cause the upload ' + |
| 77 | + 'to fail if files would be overwritten.', |
| 78 | + action='store_true', required=False) |
| 79 | +parser.add_argument('--files', |
| 80 | + help='space separated list of files to upload', |
| 81 | + type=str, required=True, nargs='*') |
| 82 | +args = parser.parse_args() |
| 83 | +args_dict = vars(args) |
| 84 | + |
| 85 | +# split the s3 URL into bucket and path, which is what Boto3 expects |
| 86 | +parts = urlparse.urlparse(args_dict['s3_base']) |
| 87 | +if parts.scheme != 's3': |
| 88 | + print('unexpected URL format for s3-base. Expected scheme s3, got %s' % parts.scheme) |
| 89 | + exit(1) |
| 90 | +bucket_name = parts.netloc |
| 91 | +key_prefix = parts.path.lstrip('/') |
| 92 | + |
| 93 | +if len(args_dict['files']) < 1: |
| 94 | + print('No files specified. Stopping.') |
| 95 | + exit(1) |
| 96 | + |
| 97 | +if (args_dict['project'] == None and args_dict['branch'] == None |
| 98 | + and args_dict['version'] == None) and args_dict['date'] == None: |
| 99 | + if args_dict['yes']: |
| 100 | + print('Can not use --yes option unless --project, --branch, --version, ' + |
| 101 | + 'and --date are also set.') |
| 102 | + exit(1) |
| 103 | + releaseinfo = uploadutils.parse_versions(args_dict['files']) |
| 104 | +else: |
| 105 | + releaseinfo = {} |
| 106 | + |
| 107 | + arg_check_copy(releaseinfo, args_dict, 'project') |
| 108 | + arg_check_copy(releaseinfo, args_dict, 'branch') |
| 109 | + arg_check_copy(releaseinfo, args_dict, 'version') |
| 110 | + arg_check_copy(releaseinfo, args_dict, 'date') |
| 111 | + |
| 112 | + # add the basename based on the project name (because we screwed |
| 113 | + # up the name of the project in S3 for Open MPI) |
| 114 | + if releaseinfo['project'] == 'open-mpi': |
| 115 | + releaseinfo['basename'] = 'openmpi' |
| 116 | + else: |
| 117 | + releaseinfo['basename'] = releaseinfo['project'] |
| 118 | + |
| 119 | + # convert the date into a unix time |
| 120 | + release_timetuple = dateutil.parser.parse(releaseinfo['date']).timetuple() |
| 121 | + releaseinfo['build_unix_time'] = int(time.mktime(release_timetuple)) |
| 122 | + |
| 123 | +prompt = 'ALWAYS_PROMPT' |
| 124 | +if args_dict['yes']: |
| 125 | + prompt = 'NO_OVERWRITE' |
| 126 | + |
| 127 | +s3_client = boto3.client('s3', args_dict['region']) |
| 128 | +uploadutils.upload_files(s3_client, bucket_name, key_prefix, |
| 129 | + releaseinfo, args_dict['files'], prompt) |
0 commit comments