diff --git a/check_if_image_tag_exists/Dockerfile b/check_if_image_tag_exists/Dockerfile index 5164b23f44..86718a7c0d 100644 --- a/check_if_image_tag_exists/Dockerfile +++ b/check_if_image_tag_exists/Dockerfile @@ -15,6 +15,7 @@ FROM gcr.io/cloud-builders/gcloud COPY main.py / +RUN ln -s /usr/local/bin/python /usr/bin/python # Since we're inheriting from the gcloud container, overwrite the entrypoint so we don't start in a gcloud command. -ENTRYPOINT [] +ENTRYPOINT ["/main.py"] diff --git a/check_if_image_tag_exists/README.md b/check_if_image_tag_exists/README.md index f653500885..32db2b90c9 100644 --- a/check_if_image_tag_exists/README.md +++ b/check_if_image_tag_exists/README.md @@ -11,6 +11,4 @@ prevent users from unintentionally overwriting a tag in a remote repository. ``` - name: gcr.io/gcp-runtimes/check_if_tag_exists:latest args: - - 'python' - - '/main.py' - '--image='``` diff --git a/check_if_image_tag_exists/main.py b/check_if_image_tag_exists/main.py old mode 100644 new mode 100755 index e5c79849f7..f7eb6e32f9 --- a/check_if_image_tag_exists/main.py +++ b/check_if_image_tag_exists/main.py @@ -28,8 +28,7 @@ def check_if_tag_exists(raw_image_path, force_build): else: image_tag = 'latest' - p = subprocess.Popen(["/builder/google-cloud-sdk/bin/gcloud " - + "alpha container images list-tags " + p = subprocess.Popen(["gcloud alpha container images list-tags " + "--format='value(tags)' --no-show-occurrences {0}" .format(image_path)], shell=True, stdout=subprocess.PIPE, @@ -37,11 +36,11 @@ def check_if_tag_exists(raw_image_path, force_build): output, error = p.communicate() if p.returncode != 0: - sys.exit("Error encountered when retrieving existing image tags! " - + "Full log: \n\n" + output) + sys.exit('Error encountered when retrieving existing image tags! ' + + 'Full log: \n\n' + output) existing_tags = set(tag.rstrip() for tag in output.split('\n')) - print "Existing tags for image {0}:".format(image_path) + print 'Existing tags for image {0}:'.format(image_path) for tag in existing_tags: print tag @@ -49,7 +48,7 @@ def check_if_tag_exists(raw_image_path, force_build): print "Tag '{0}' already exists in remote repository!" \ .format(image_tag) if not force_build: - sys.exit("Exiting build.") + sys.exit('Exiting build.') else: print "Forcing build. Tag '{0}' " \ "will be overwritten!".format(image_tag) @@ -66,6 +65,10 @@ def main(): parser .add_argument('--force', action='store_true', default=False) args = parser.parse_args() + if args.image is None: + sys.exit('Please provide fully qualified remote path for the ' + 'target image.') + check_if_tag_exists(args.image, args.force) diff --git a/structure_tests/cloudbuild.yaml.in b/structure_tests/cloudbuild.yaml.in index d7d15b1014..9114af12e4 100644 --- a/structure_tests/cloudbuild.yaml.in +++ b/structure_tests/cloudbuild.yaml.in @@ -4,5 +4,7 @@ steps: env: ['PROJECT_ROOT=github.com/GoogleCloudPlatform/runtimes-common'] - name: gcr.io/cloud-builders/docker args: ['build', '-t', '${IMAGE}', './structure_tests'] + - name: gcr.io/gcp-runtimes/check_if_tag_exists + args: ['--image=${IMAGE}'] images: - '${IMAGE}'