class Dpl::Providers::Ecr

Attributes

endpoints[R]

Public Instance Methods

deploy() click to toggle source
# File lib/dpl/providers/ecr.rb, line 50
def deploy
  info :deploy, regions: regions.join(', '), targets: targets.join(', ')
  regions.product(targets).each do |region, target|
    push(region, target)
  end
end
login() click to toggle source
# File lib/dpl/providers/ecr.rb, line 41
def login
  info :login
  auth_regions
end
validate() click to toggle source
# File lib/dpl/providers/ecr.rb, line 46
def validate
  # TODO: validate the image exists locally
end

Private Instance Methods

auth_region(region) click to toggle source
# File lib/dpl/providers/ecr.rb, line 70
def auth_region(region)
  token = auth_token(region)
  user, pass = parse_auth(token.authorization_token)
  url = token.proxy_endpoint
  shell :login, user:, pass:, url:, echo: false, silent: true
  info(:auth_region, url:)
  strip_protocol(url)
end
auth_regions() click to toggle source
# File lib/dpl/providers/ecr.rb, line 66
def auth_regions
  @endpoints = regions.map { |region| [region, auth_region(region)] }.to_h
end
auth_token(region) click to toggle source
# File lib/dpl/providers/ecr.rb, line 79
def auth_token(region)
  ecr(region).get_authorization_token(registry_ids).authorization_data[0]
end
creds() click to toggle source
# File lib/dpl/providers/ecr.rb, line 97
def creds
  @creds ||= only(opts, :access_key_id, :secret_access_key)
end
ecr(region) click to toggle source
# File lib/dpl/providers/ecr.rb, line 101
def ecr(region)
  Aws::ECR::Client.new(region:, **creds)
end
parse_auth(str) click to toggle source
# File lib/dpl/providers/ecr.rb, line 105
def parse_auth(str)
  user, pass = Base64.decode64(str).split(':')
  [user, pass.chomp]
end
progress(events) click to toggle source
# File lib/dpl/providers/ecr.rb, line 114
def progress(events)
  events.split("\r\n").each do |event|
    event = JSON.parse(event)
    if e = event['error']
      error e
    elsif %w[Preparing Pushing].include?(event['status'])
      nil
    elsif event['id']
      info "#{event['status']} [#{event['id']}]"
    elsif event['status']
      info event['status']
    end
  end
end
push(region, target) click to toggle source
# File lib/dpl/providers/ecr.rb, line 59
def push(region, target)
  url, repo, tag = endpoints[region], *target.split(':')
  shell :tag, url:, repo:, tag: tag || 'latest'
  shell(:push, url:, repo:)
  info :image_pushed, region:, target:
end
regions() click to toggle source
# File lib/dpl/providers/ecr.rb, line 87
def regions
  # not sure how this was meant to be normalized when being a YAML list
  region.split(',')
end
registry_ids() click to toggle source
# File lib/dpl/providers/ecr.rb, line 83
def registry_ids
  account_id? ? { registry_ids: [account_id] } : {}
end
strip_protocol(url) click to toggle source
# File lib/dpl/providers/ecr.rb, line 110
def strip_protocol(url)
  url.sub(%r{^https?://}, '')
end
targets() click to toggle source
# File lib/dpl/providers/ecr.rb, line 92
def targets
  # not sure how this was meant to be normalized when being a YAML list
  target.split(',')
end