Created
April 15, 2020 19:08
-
-
Save djpadz/27652124a24f508ce85fdd8f3930a341 to your computer and use it in GitHub Desktop.
Log in to a docker repository in AWS ECR using the current profile
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
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
require 'json' | |
require 'base64' | |
require 'open3' | |
puts 'Getting authorization token...' | |
out, status = Open3.capture2 'aws', 'ecr', 'get-authorization-token' | |
exit status.exitstatus unless status.success? | |
token_info = JSON.parse(out)['authorizationData'][0] | |
username, password = Base64.decode64(token_info['authorizationToken']).split(':', 2) | |
endpoint = token_info['proxyEndpoint'] | |
puts "Authenticating as #{username} to #{endpoint}..." | |
out, status = Open3.capture2e 'docker', 'login', '-u', username, '--password-stdin', endpoint, stdin_data: password | |
puts out | |
exit status.exitstatus |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment