Created
February 11, 2016 19:04
-
-
Save benton/df78dadf4bd2bff8b7d1 to your computer and use it in GitHub Desktop.
Get Docker image metadata from ECR - ruby version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'aws-sdk' | |
REPO_NAME = 'mdsol/mauth/distro' | |
REGION = 'us-east-1' | |
ecr = Aws::ECR::Client.new(region: REGION) | |
# get list of image tags in the repo | |
resp = ecr.list_images(repository_name: REPO_NAME) | |
tags = resp.image_ids.map{|id| id.image_tag} | |
# get manifests for all tags at once | |
resp = ecr.batch_get_image(repository_name: REPO_NAME, | |
image_ids: tags.map{|t| {image_tag: t}}) | |
# The manifest is encoded as JSON in the JSON response - :-/ | |
manifest = JSON.parse(resp.images.first.image_manifest) | |
# ... and THEN, each layer's metadata is encoded within THAT! >-{ | |
image_metadata = JSON.parse(manifest['history'].first['v1Compatibility']) | |
labels = image_metadata['config']['Labels'] | |
image_command = ( | |
image_metadata['config']['Entrypoint'] + | |
image_metadata['config']['Cmd'] | |
).join(' ') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment