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

Unable to cache composer while running a docker instance

Naveed Zahoor
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 18, 2023

I have setup custom composer cache and its working fine and it looks something like this.


definitions:
services:
docker:
memory: 3072
caches:
sonar: ~/.sonar/cache
composer-custom: /composer/cache


and my build step looks something like this 

- step: &build-api-docker-test-image
name: Build API docker test image
services:
- docker
caches:
- composer-custom
- docker
script:
- export DOCKER_BUILDKIT=1
- export IMAGE_TAG=$BITBUCKET_COMMIT
- export API_IMAGE_NAME=$API_DOCKER_IMAGE_NAME:latest
- docker build --file .docker/test/Dockerfile -t $API_IMAGE_NAME --build-arg BITBUCKET_KEY=${BITBUCKET_USERNAME} --build-arg BITBUCKET_SECRET=${BITBUCKET_READ_ACCESS_SECRET} .
- docker save --output tmp-api-image.test.docker $API_DOCKER_IMAGE_NAME
artifacts:
- tmp-api-image.test.docker


now when i try and run pipeline composer custom is always not found. because my composer install is creating files in my container. I am unable to use mount either due to restrictions. 

1 answer

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 19, 2023

Hello Naveed,

Thank you for reaching out to Atlassian Community!

As you mentioned, since you are doing the composer install inside your docker build command, the composer dependencies are being downloaded to a layer of docker build, and not to the pipelines build container, so this is the reason why the custom cache is not finding the composer files in the path 

~/.sonar/cache

If you were downloading the dependencies outside of the docker build, the cache should work as usual.

That said, I see you have also configured the cache for docker. This should cache the docker layers (a layer is generated for every command in the Dockerfile) that have not changed since the last build, so the layers where you are installing the composer dependencies in your docker build should be cached as part of the docker cache.

Hope that helps!

Thank you, @Naveed Zahoor !

Patrik S

Suggest an answer

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

Atlassian Community Events