Skip to content

Commit 1bba043

Browse files
committed
Support specifying ECR registry IDs
1 parent 5d31f19 commit 1bba043

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

dockercfg-generator/README.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ As per AWS documentation, this dockercfg should be valid for 48 hours.
2626

2727
Codeship supports using custom images to generate dockercfg files during the build process. To use this image to integrate with AWS ECR, simply define a entry in your services file for this image, and reference it from any steps or services which need to interact with ECR repositories with the `dockercfg_service` field. You'll also need to provide the following environment variables using an [encrypted env file](https://codeship.com/documentation/docker/encryption/):
2828

29-
* AWS_REGION - Your selected AWS Region, ensure this is a region suppoing AWS ECR
30-
* AWS_ACCESS_KEY_ID - Your AWS Access Key
31-
* AWS_SECRET_ACCESS_KEY - Your AWS Access Secret
29+
* `AWS_REGION` - Your selected AWS Region, ensure this is a region supporting AWS ECR
30+
* `AWS_ACCESS_KEY_ID` - Your AWS Access Key
31+
* `AWS_SECRET_ACCESS_KEY` - Your AWS Access Secret
3232

3333
Optionally, you can also set the following variables to assume a role across accounts before generating the dockercfg:
3434

35-
* AWS_STS_ROLE - The AWS role to assume
36-
* AWS_STS_ACCOUNT - The AWS account the role exists in
35+
* `AWS_STS_ROLE` - The AWS role to assume
36+
* `AWS_STS_ACCOUNT` - The AWS account the role exists in
37+
38+
If you are using an ECR registry in another AWS account to the IAM user but you aren't using a role, a list of AWS account IDs that correspond to the registries that you want to log in to can be specified:
39+
* `AWS_ECR_REGISTRY_IDS` - A space separated list of AWS account IDs
3740

3841
Here is an example of using and ECR Dockercfg generator to authenticate pushing an image.
3942

@@ -64,4 +67,4 @@ You can also use this authentication to pull images, or use with caching, by def
6467
## Troubleshooting
6568

6669
#### "No basic auth credentials" error on push
67-
Make sure the registry entry in your steps does not contain a trailing slash.
70+
Make sure the registry entry in your steps does not contain a trailing slash.

dockercfg-generator/aws_docker_creds.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ if [[ -n $AWS_STS_ROLE || -n $AWS_STS_ACCOUNT ]]; then
3232
export AWS_SESSION_EXPIRATION=$(cat ${aws_tmp} | jq -r ".Credentials.Expiration")
3333
fi
3434

35+
registry_id=''
36+
if [[ -n $AWS_ECR_REGISTRY_IDS ]]; then
37+
registry_ids="--registry-ids $AWS_ECR_REGISTRY_IDS"
38+
fi
39+
3540
# fetching aws docker login
3641
echo "Logging into AWS ECR"
37-
$(aws ecr get-login --no-include-email)
42+
$(aws ecr get-login --no-include-email ${registry_ids})
3843

3944
# writing aws docker creds to desired path
4045
echo "Writing Docker creds to $1"
4146
chmod 544 ~/.docker/config.json
4247
cp ~/.docker/config.json $1
43-

0 commit comments

Comments
 (0)