0

Chef cookbook for docker "https://github.com/chef-cookbooks/docker" provides docker_registry for authentication like below.

docker_registry 'https://index.docker.io/v1/' do
username 'publicme'
password 'hope_this_is_in_encrypted_databag'
email '[email protected]'
end

But if we want to use it for AWS ECR then we need to generate login token before logging.

aws ecr get-login --region us-east-1 #It will generate login token as below. 
docker login -u AWS -p "password token"

but chef cook book does not provide this functionality. Any idea how to get this done in chef ?

2

2 Answers 2

0

Here is a workaround which i am using. But if anyone have more elegant solution then please share.

Setup your access keys to your node. Add this to your recipe. It will simply login to ECR.

cmd = "aws ecr get-login --region us-east-1"
value = #{cmd}
list = value.split(" ")

docker_registry 'AWS ECR registry' do
serveraddress 'https://xyz.ecr.us-east-1.amazonaws.com'
username 'AWS'
password "#{list[5]}"
email 'none'
end

1
  • I think you missed some formatting here, this is not valid Ruby code.
    – coderanger
    Mar 18, 2017 at 18:41
0

You can use a combo of our shell_out helpers and lazy evaluation.

docker_registry 'https://index.docker.io/v1/' do
  username 'AWS'
  password lazy {
    shell_out!("aws ecr get-login --region us-east-1").stdout.split[5]
  }
  email '[email protected]'
end
1
  • It is giving following error ----------------- Docker::Error::AuthenticationError ---------------------------------- AWS failed to authenticate with index.docker.io/v1
    – xs2rashid
    Mar 19, 2017 at 17:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .