Skip to content

Instantly share code, notes, and snippets.

@prog
Created December 14, 2017 07:30
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save prog/b716b815ed4ec05d8ca57adc90be9e97 to your computer and use it in GitHub Desktop.
Save prog/b716b815ed4ec05d8ca57adc90be9e97 to your computer and use it in GitHub Desktop.
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/
@Wingjam
Copy link

Wingjam commented May 3, 2020

Thanks for your gist! Now composer has its own image on Docker Hub.
Thus, I suggest this little modification:

image: composer:1

@bertalanimre
Copy link

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

@bftanase
Copy link

bftanase commented Feb 1, 2022

probably because ~/.composer is somewhere in the container that has the composer command

@pixelbrackets
Copy link

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