Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
fix tag check entrypoint (#76)
Browse files Browse the repository at this point in the history
* fix tag check entrypoint

* update docs

* flake
  • Loading branch information
nkubala authored Dec 13, 2016
1 parent 6badaa5 commit a5efef7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion check_if_image_tag_exists/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 0 additions & 2 deletions check_if_image_tag_exists/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<target_image_path>'```
15 changes: 9 additions & 6 deletions check_if_image_tag_exists/main.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,27 @@ 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,
stderr=subprocess.STDOUT)

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

if image_tag in existing_tags:
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)
Expand All @@ -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)


Expand Down
2 changes: 2 additions & 0 deletions structure_tests/cloudbuild.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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}'

0 comments on commit a5efef7

Please sign in to comment.