Skip to content

Commit

Permalink
Merge pull request concourse#165 from pushpay/AllowMultipleEcrImagesI…
Browse files Browse the repository at this point in the history
…nDockerfile

Allow multiple ECR images in dockerfile
  • Loading branch information
vito authored Dec 29, 2017
2 parents 656e991 + df03e8e commit 98b1d34
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
19 changes: 11 additions & 8 deletions assets/out
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,18 @@ elif [ -n "$build" ]; then
fi

ECR_REGISTRY_PATTERN='/[a-zA-Z0-9][a-zA-Z0-9_-]*\.dkr\.ecr\.[a-zA-Z0-9][a-zA-Z0-9_-]*\.amazonaws\.com(\.cn)?[^ ]*/'
ecr_image=$(grep '^\s*FROM' ${dockerfile} | \
ecr_images=$(grep '^\s*FROM' ${dockerfile} | \
awk "match(\$0,${ECR_REGISTRY_PATTERN}){print substr(\$0, RSTART, RLENGTH)}" )
if [ -n "$ecr_image" ]; then
# pull will perform an authentication process needed for ECR
# there is an experimental endpoint to support long running sessions
# docker cli does not support it yet though
# see https://github.com/moby/moby/pull/32677
# and https://github.com/awslabs/amazon-ecr-credential-helper/issues/9
docker pull "${ecr_image}"
if [ -n "$ecr_images" ]; then
for ecr_image in $ecr_images
do
# pull will perform an authentication process needed for ECR
# there is an experimental endpoint to support long running sessions
# docker cli does not support it yet though
# see https://github.com/moby/moby/pull/32677
# and https://github.com/awslabs/amazon-ecr-credential-helper/issues/9
docker pull "${ecr_image}"
done
fi

docker build -t "${repository}:${tag_name}" "${expanded_build_args[@]}" -f "$dockerfile" $cache_from "$build"
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/ecr/Dockerfile.multi-ecr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM ubuntu as u

FROM 123123.dkr.ecr.us-west-2.amazonaws.com:443/testing as test

FROM 123123.dkr.ecr.us-west-2.amazonaws.com:443/testing2 as test

17 changes: 16 additions & 1 deletion tests/out_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ var _ = Describe("Out", func() {
Expect(session.Err).To(gbytes.Say(docker("pull 123123.dkr.ecr.us-west-2.amazonaws.com:443/testing")))
})

It("calls docker pull for an ECR images in a multi build docker file", func() {
It("calls docker pull for an ECR image in a multi build docker file", func() {
session := put(map[string]interface{}{
"source": map[string]interface{}{
"repository": "test",
Expand All @@ -178,6 +178,21 @@ var _ = Describe("Out", func() {

Expect(session.Err).To(gbytes.Say(docker("pull 123123.dkr.ecr.us-west-2.amazonaws.com:443/testing")))
})

It("calls docker pull for all ECR images in a multi build docker file", func() {
session := put(map[string]interface{}{
"source": map[string]interface{}{
"repository": "test",
},
"params": map[string]interface{}{
"build": "/docker-image-resource/tests/fixtures/ecr",
"dockerfile": "/docker-image-resource/tests/fixtures/ecr/Dockerfile.multi-ecr",
},
})

Expect(session.Err).To(gbytes.Say(docker("pull 123123.dkr.ecr.us-west-2.amazonaws.com:443/testing")))
Expect(session.Err).To(gbytes.Say(docker("pull 123123.dkr.ecr.us-west-2.amazonaws.com:443/testing2")))
})
})

Context("When all proxy settings are provided with build args", func() {
Expand Down

0 comments on commit 98b1d34

Please sign in to comment.