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

How to configure caching for custom base image

oguzhan December 31, 2020

Hi,

I've a Bitbucket Pipeline that is using an custom docker image as a base. Pulling it from the ECR. Also, I'm using this image to build dockerized Golang apps in the first step with make commands. I want to cache Golang modules that is being downloaded in the make build process. But when I read the examples, People are using golang base images to make caching work. How can I activate caching while using base image other than Go image itself? Related parts of my pipeline is on below. I defined it like this but it doesn't work.

Thank you.

image: 
name: <ECR Image>
aws:
access-key: $AWS_ACCESS_KEY_ID
secret-key: $AWS_SECRET_ACCESS_KEY

definitions:
caches:
go: $GOPATH/pkg

pipelines:
- step
:
name: "Image Build & Push"
services:
    -docker
caches:
-go
script:
- export ENVIRONMENT=beta
- echo "Environment is ${ENVIRONMENT}"
- export DOCKER_IMAGE_BUILDER="${BITBUCKET_REPO_SLUG}:builder"
- make clean
- make build BUILD_VER=${BITBUCKET_TAG}.${BITBUCKET_BUILD_NUMBER} \ APP_NAME=${BITBUCKET_REPO_SLUG} \
DOCKER_IMAGE_BUILDER=${DOCKER_IMAGE_BUILDER}
- make test

 

1 answer

0 votes
Gonchik Tsymzhitov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 1, 2021

Hi! 

Will it help the next idea of caching? 

...
- step
caches:
- node-custom
script:
- if [ ! -d "node_modules" ]; then npm install; fi
...

definitions:
caches:
node-custom: public/node_modules

 https://community.atlassian.com/t5/Bitbucket-questions/Pipelines-cache-custom-node-modules-folder/qaq-p/771598

 

Because you just want to cache the dependencies. \

If I understood incorrectly, feel free to provide a more info please

Cheers,

Gonchik Tsymzhitov

oguzhan January 5, 2021

Hi Gonchik, thank you for your response, yes I want to cache dependencies. But as you can see, I'm using docker inside another Docker container to build another image. So go or node path may not be able to help in this case, or I couldn't make it work. In theory, is it possible to apply path based caching in my case?

 

Best Regards.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events