Skip to content

Instantly share code, notes, and snippets.

@benton
Created February 11, 2016 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benton/df78dadf4bd2bff8b7d1 to your computer and use it in GitHub Desktop.
Save benton/df78dadf4bd2bff8b7d1 to your computer and use it in GitHub Desktop.
Get Docker image metadata from ECR - ruby version
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