diff --git a/Jenkinsfile.aws-test b/Jenkinsfile.aws-test index c634b962b..d82c4ca22 100644 --- a/Jenkinsfile.aws-test +++ b/Jenkinsfile.aws-test @@ -69,17 +69,18 @@ node(NODE) { aws ec2 modify-image-attribute \ --image-id ${ami_intermediate} \ --launch-permission '{"Add":[{"Group":"all"}]}' - # And upload elsewhere - for region in ${OTHER_AWS_REGIONS}; do - aws ec2 copy-image --source-region ${AWS_REGION} \ + # And upload to more regions + ./scripts/ami-copy-regions --source-region ${AWS_REGION} \ + --name rhcos_dev_${version} \ --source-image-id ${ami_intermediate} \ - --region \${region} > ${WORKSPACE}/\${region}.json - done + --regions ${OTHER_AWS_REGIONS.join(',')} \ + --out ${WORKSPACE}/aws-tested.json - # Upload the json file to a public location - aws s3 cp --acl public-read \ - ${WORKSPACE}/aws-${AWS_REGION}-tested.json \ - s3://${S3_PUBLIC_BUCKET}/aws-${AWS_REGION}-tested.json + # Upload the json files to a public location + for k in aws-${AWS_REGION}-tested.json aws-tested.json; do + aws s3 cp --acl public-read ${WORKSPACE}/\${k} \ + s3://${S3_PUBLIC_BUCKET}/\${k} + done """ } } diff --git a/scripts/ami-copy-regions b/scripts/ami-copy-regions new file mode 100755 index 000000000..dde3960f3 --- /dev/null +++ b/scripts/ami-copy-regions @@ -0,0 +1,50 @@ +#!/usr/bin/python3 +# Copy an AMI to multiple regions, generating an "AMI JSON" +# file matching the Container Linux schema: +# https://alpha.release.core-os.net/amd64-usr/current/coreos_production_ami_all.json +# Note this assumes the images are HVM. + +import os,sys,argparse,subprocess,io,time,re,multiprocessing +import tempfile, json + +def fatal(msg): + print('error: {}'.format(msg), file=sys.stderr) + raise SystemExit(1) + +def csv_list(string): + return string.split(',') + +parser = argparse.ArgumentParser() +parser.add_argument("--source-region", help="Source region", + action='store', required=True) +parser.add_argument("--source-image-id", help="Source AMI", + action='store', required=True) +parser.add_argument("--name", help="AMI name", + action='store', required=True) +parser.add_argument("--regions", help="Name", + action='store', required=True, + type=csv_list) +parser.add_argument("--out", help="Store output in FILE", + action='store', metavar='FILE', + required=True) + +args = parser.parse_args() + +amis = [] + +for region in args.regions: + print("Uploading to: {}".format(region)) + res = json.loads(subprocess.check_output(['aws', '--output', 'json', 'ec2', 'copy-image', + '--source-region', args.source_region, + '--source-image-id', args.source_image_id, + '--name', args.name, + '--region', region])) + iid = res['ImageId'] + print("Complete, ImageId={}".format(iid)) + amis.append({'name': region, + 'hvm': iid}) + +amis.sort(key=lambda x: x['name']) + +with open(args.out, 'w') as f: + json.dump({'amis': amis}, f)