Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to use composer (php) including cache with gitlab-ci
build:install-vendor:
stage: build
image: <any-image-with-composer>
before_script:
- composer config -g cache-dir "$(pwd)/.composer-cache"
script:
- composer install --ignore-platform-reqs --no-dev --optimize-autoloader --no-ansi --no-interaction --no-progress
cache:
paths:
- .composer-cache/
artifacts:
expire_in: 30 min
paths:
- vendor/
@pixelbrackets
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