It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

aws-ecr-push-image pipe doesn't use TAGS argument

 

I call this pipe with "TAGS" but it always defaults to "latest".

As per below I'm using tag 1.1.1. Same problem with 1.1.0.

- pipe: atlassian/aws-ecr-push-image:1.1.1
variables:
TAGS: mytag
IMAGE_NAME: "${IMAGE}"

 

INFO: Executing the aws-ecr-push-image pipe...INFO: Found credentials in environment variables.INFO: Successfully logged in to https://xxx.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com✖ Image not found: 404 Client Error: Not Found ("no such image: myimage: No such image: myimage:latest")

2 answers

1 vote

Hi @michael_hart , it seems like the docker daemon can't find the image with the name 'myimage:latest' when running the pipe. You need to build this image in the same step before executing the pipe so it's available to docker. 

Hi,

I don't want to push "myimage:latest", I want to push "myimage:mytag"

Right, the pipe will tag the myimage:latest with myimage:mytag and push the tagged image. But for this the pipe expects the myimage to be available for tagging. Here is an example 

script:

  # build the image
  - docker build -t my-docker-image .

  # use the pipe to push to AWS ECR
  - pipe: atlassian/aws-ecr-push-image:0.2.0
    variables:
      AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
IMAGE_NAME: my-docker-image
TAGS: '${BITBUCKET_TAG} latest'

In the above example, we build the image with the my-docker-image name and the pipe will tag it with two tags: ${BITBUCKET_TAG} (which might be something like 1.0.0 or other version) and latest. 

Yes, I already build my image with this for example

docker build -t my-docker-image .

 After which, I want to retag the image with "mytag" and only push my-docker-image:mytag to ECR. So in your example I'm doing the equivalent of this:

  # use the pipe to push to AWS ECR
  - pipe: atlassian/aws-ecr-push-image:0.2.0
    variables:
      AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
IMAGE_NAME: my-docker-image
TAGS: '${BITBUCKET_TAG}'

However you'll find that, no matter what I put in "TAGS", it will always try to push "latest".

(in your example code, does that actually work?)

@Alexander Zhukov I also seem to be having this issue. My script is as follows:

script:
- docker build -t my-image .
- pipe: atlassian/aws-ecr-image-push:1.1.3
variable:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
IMAGE_NAME: my-image
TAGS: '${BITBUCKET_BUILD_NUMBER}'

No matter what I seem to put in TAGS when it pushes my image it only ever tags it with 'latest'. I even tried something like `TAGS: "hi latest"` and I can see in the logs of the pipeline that the following is being set:


--env=TAG="hi latest"

But the image is still just tagged as `latest` in ECR. Am I missing something? 

Right, the pipe will tag the myimage:latest with myimage:mytag and push the tagged image.

Why would you do this? I provide the tag to be pushed but the pipe still expects to find a tag "latest" just to re-tag it to my provided tag? This just leads to confusion in the end. It's also not documented that the tag "latest" must be present even when pushing another tag.

The same for the image name. I have to build my image as "foo" just to get it pushed as `xxx.dkr.ecr.us-east-1.amazonaws.com/foo`. This breaks usual Makefiles for no reason. I don't think it's smart for this pipe trying to be "smart". I can figure out and provide image names by myself.

It's weird.

@Alexander Zhukov 

Like michael_hart likes this
0 votes
レスタ I'm New Here Jun 08, 2020

Alexander's answer actually works.

I happened to have the same issue with the following script. No matter what I put in the TAGS, it always tried to push the image with "latest" tag.

- docker build -t $DOCKER_IMAGE_NAME:$BITBUCKET_COMMIT .
- docker tag $DOCKER_IMAGE_NAME:$BITBUCKET_COMMIT $DOCKER_ECR_REPO_URL/$DOCKER_IMAGE_NAME:$BITBUCKET_COMMIT
- pipe: atlassian/aws-ecr-push-image:1.1.2
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID # Optional if already defined in the context.
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY # Optional if already defined in the context.
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION # Optional if already defined in the context.
IMAGE_NAME: $DOCKER_IMAGE_NAME
TAGS: '${BITBUCKET_COMMIT}' # Optional

However,  Once I remove the tagging part, everything works like a charm. In the ECR, it tagged as expected.

- docker build -t $DOCKER_IMAGE_NAME .
- pipe: atlassian/aws-ecr-push-image:1.1.2
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID # Optional if already defined in the context.
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY # Optional if already defined in the context.
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION # Optional if already defined in the context.
IMAGE_NAME: $DOCKER_IMAGE_NAME
TAGS: '${BITBUCKET_COMMIT}' # Optional

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket Pipelines

What We Learned When We Researched Open Source Vulnerabilities in 7 Popular Coding Languages

...hey are a part of us, shaping how we interact with the world around us. The same holds true for programming languages when we think about how different kinds of vulnerabilities raise their heads in t...

1,051 views 0 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you