cmd-aws-replicate: upload to one region at a time to keep meta.json updated
@@ -68,9 +68,17 @@ def run_ore():
if args.log_level:
ore_args.extend(['--log-level', args.log_level])
ore_args.extend(['aws', 'copy-image', '--image', source_image, '--region', source_region])
- ore_args.extend(region_list)
- print("+ {}".format(subprocess.list2cmdline(ore_args)))
- ore_data = json.loads(subprocess.check_output(ore_args))
+
+ upload_failed_in_regions = []
+ for upload_region in region_list:
+ region_ore_args = ore_args.copy()
+ region_ore_args.append(upload_region)
+ print("+ {}".format(subprocess.list2cmdline(region_ore_args)))
+ try:
+ ore_data = json.loads(subprocess.check_output(region_ore_args))
+ except subprocess.CalledProcessError:
+ upload_failed_in_regions.append(upload_region)
+ continue
# This matches the Container Linux schema:
# https://stable.release.core-os.net/amd64-usr/current/coreos_production_ami_all.json
ami_data = [{'name': region,
@@ -78,9 +86,14 @@ def run_ore():
'snapshot': vals['snapshot']}
for region, vals in ore_data.items()]
buildmeta['amis'].extend(ami_data)
+
write_json(buildmeta_path, buildmeta)
print(f"Updated: {buildmeta_path}")
+ if upload_failed_in_regions:
+ error_msg = ' '.join(upload_failed_in_regions)
+ raise Exception(f"Upload failed in regions {error_msg}")
+
# Do it!
run_ore()
