Skip to content

Commit

Permalink
cosalib/gcp: attach to image family in separate API call
Browse files Browse the repository at this point in the history
Currently we create an image and attach it to an image family in a
single API call. We'd like to attach it to an image family *after*
the image has been deprecated (deprecated images won't be given
to users who are trying to retrieve the latest image for an image
family). However, you can't create an image AND deprecate it in
the same API call so there is a split second of opportunity for
a user to get the newer GCP image before we've officially released
it.

This change breaks it up so that we can:

1. create the image (not part of a image family)
2. deprecate the image
3. attach the image to an image family

The new flow means there is no opportunity for a user to get an
image that has yet to be released.
  • Loading branch information
dustymabe committed May 14, 2020
1 parent b2a9e1a commit eb92096
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions src/cosalib/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,56 @@ def gcp_run_ore(build, args):
if args.project is None:
raise Exception(arg_exp_str.format("project", "GCP_PROJECT"))

ore_args = ['ore']
if args.log_level == "DEBUG":
ore_args.extend(['--log-level', "DEBUG"])

gcp_name = re.sub(r'[_\.]', '-', build.image_name_base)
if not re.fullmatch(GCP_NAMING_RE, gcp_name):
raise Exception(f"{gcp_name} does match the naming rule: file a bug")

urltmp = os.path.join(build.tmpdir, "gcp-url")
ore_args.extend([

ore_common_args = [
'ore',
'gcloud',
'--project', args.project,
'--basename', build.build_name,
'--json-key', args.json_key,

]
if args.log_level == "DEBUG":
ore_common_args.extend(['--log-level', "DEBUG"])

ore_upload_cmd = ore_common_args + [
'upload',
'--basename', build.build_name,
'--force', # We want to support restarting the pipeline
'--bucket', f'{args.bucket}',
'--json-key', args.json_key,
'--name', gcp_name,
'--file', f"{build.image_path}",
'--write-url', urltmp,
])

if args.family:
ore_args.extend(['--family', args.family])
]
if args.description:
ore_args.extend(['--description', args.description])
ore_upload_cmd.extend(['--description', args.description])
if not args.create_image:
ore_args.extend(['--create-image=false'])
ore_upload_cmd.extend(['--create-image=false'])
run_verbose(ore_upload_cmd)

# Run deprecate image to deprecate if requested
if args.deprecated:
ore_deprecate_cmd = ore_common_args + [
'deprecate-image',
'--image', gcp_name,
'--state', 'DEPRECATED'
]
run_verbose(ore_deprecate_cmd)

# Run update-image to add to an image family if requested.
# We run this as a separate API call because we want to run
# it AFTER the deprecation if the user passed --deprecated
if args.family:
ore_update_cmd = ore_common_args + [
'update-image',
'--image', gcp_name,
'--family', args.family
]
run_verbose(ore_update_cmd)

run_verbose(ore_args)
build.meta['gcp'] = {
'image': gcp_name,
'url': open(urltmp).read().strip()
Expand Down Expand Up @@ -119,4 +139,8 @@ def gcp_cli(parser):
type=boolean_string,
help="Whether or not to create an image in GCP after upload.",
default=True)
parser.add_argument("--deprecated",
action="store_true",
default=False,
help="If the image should be marked as deprecated")
return parser

0 comments on commit eb92096

Please sign in to comment.