Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to use composer (php) including cache with gitlab-ci
stage: build
image: <any-image-with-composer>
- composer config -g cache-dir "$(pwd)/.composer-cache"
- composer install --ignore-platform-reqs --no-dev --optimize-autoloader --no-ansi --no-interaction --no-progress
- .composer-cache/
expire_in: 30 min
- vendor/
Copy link

pixelbrackets commented May 9, 2022

I know. this is nothing to do with this, but why can't GitLab simply cache ~/.composer ?

@bertalanimre GitLab CI Caches by definition have the scope of the app aka the Git repository only. The repo resides in the working directory. This directory may be located in different locations depending of the runner setup. Broadly speaking, the CI process does not know anything else about the environment, like the existence of home directories (~ / $HOME) or which tool you use in your jobs (composer). Therefore you need to tell the tool to store its cache files in the working directory. This allows GitLab to pick them up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment