Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

use Cache of make build

image: shreysway07/srijan-alpine:latest

pipelines:
default:

- step:
name: Build Docker images & push to ECR
services:
- docker

script:
- make build
- aws configure set default.region ${ECR_REGION}
- aws configure set aws_access_key_id ${ECR_KEY}
- aws configure set aws_secret_access_key ${ECR_SECRET}
- docker login ${ECR_URL} --username AWS --password $(aws ecr get-login-password --region ${ECR_REGION})
- bash image-scanning.sh
- step:
name: Force Deploy Image To ECR
trigger: manual
services:
- docker
script:
- aws configure set default.region ${ECR_REGION}
- aws configure set aws_access_key_id ${ECR_KEY}
- aws configure set aws_secret_access_key ${ECR_SECRET}
- docker login ${ECR_URL} --username AWS --password $(aws ecr get-login-password --region ${ECR_REGION})
#- make build
- make push_image_1
- make push_image_2


Hey team I want to use cache of make build command in step 2 which am using in step 1 . How can I use that. Any help is highly appreciated .

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Mar 15, 2023

Hi @Shrey,

Does the command make build from the first step build a Docker image that you want to use on the second step? If so, you can do this with cache, if these two steps are part of the same pipeline and if they are not parallel. In order to do this, you can add the following to both of the two steps you posted here (Caches documentation):

caches:
- docker

I would suggest including the command make build in the second step as well. Caches get cleared automatically 1 week after they are created. It is also possible for users to manually remove the cache from the Pipelines page of the repo. The second step you shared here is manual, so if any of these two things happen before you trigger the second step and the cache is not present, the second step will fail. Adding the command make build in the second step will ensure that the step doesn't fail because of a missing cache. If the cache is present, then the make build command in the second step will use the existing cache and the build will be faster.

If you have any questions, please feel free to reach out.

Kind regards,
Theodora

I tried using using cache docker previously but the commit ID in ECR is being committed twice for eg for 1st time commit is 1234 it pushes to ECR with image:1234
but when I commit 2nd time is how image:1234,567 .Commit ID logic written inside make build

due to cache 1234 is also coming in next push

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Mar 17, 2023

Hi @Shrey,

Thank you for reaching out. I'm not sure I understand what is happening, as I don't know what exactly your make commands are doing.

There is another option, you could use artifacts instead of cache. An example:

pipelines:
default:
- step:
name: Build docker image
services:
- docker
script:
- docker build -t repo/imagename .
- docker save --output tmp-image.docker repo/imagename
artifacts:
- tmp-image.docker
- step:
name: Deploy docker image
services:
- docker
script:
- docker load --input ./tmp-image.docker
- docker images

In this example, I have added the docker build and docker save commands in the script of my first step, but you can include them both in the Makefile that the make command is using.

In the first step, I have defined as an artifact the file that the docker save command produces. Files defined as artifacts will be available for the next steps (as long as the steps are not parallel).

Then, in the second step, the docker load command will load the image from the artifact produced in the first step. With this approach, you don't have to build the image again in the second step.

Please feel free to let me know if this works for you.

 

If you still experience issues, it would be useful to have the build log from both steps and a description of what is the undesired behavior in this build log. You can download the build log for each step from our website: while viewing the build log for each step, there is an option to download it at the top right corner. Please make sure to sanitize any private/sensitive data prior to sharing here.

If you don't feel comfortable sharing build logs here, you can create a ticket with the support team (which will be visible only to you and Atlassian staff), and share more details and the build URL there. You can create a ticket via https://support.atlassian.com/contact/#/, in "What can we help you with?" select "Technical issues and bugs" and then Bitbucket Cloud as product.

Please feel free to let me know if you have any questions.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events