Context
My goal is to create a CI “job cache” for a composer, but only the “dev” part,
not the global composer for a production environment.
This will allow me to add some testing during the CI with require-dev vendors.
My thought process is to:
- Download the dev vendors (composer install).
- Push them into the cache.
- In other jobs, pull this cache.
- Use the vendor cache.
Config
Here’s my gitlab-ci.yml:
variables:
GIT_STRATEGY: fetch
GIT_SUBMODULE_STRATEGY: recursive
GIT_SUBMODULE_DEPTH: 1
GIT_DEPTH: "5"
GET_SOURCES_ATTEMPTS: "3"
RESTORE_CACHE_ATTEMPTS: "3"
ARTIFACT_DOWNLOAD_ATTEMPTS: "3"
FF_USE_FASTZIP: "true"
ARTIFACT_COMPRESSION_LEVEL: "fast"
CACHE_SHARED: "true"
CACHE_COMPRESSION_LEVEL: "fast"
SENTRY_LOG_LEVEL: info
DOCKER_DRIVER: overlay
default:
image: allsoftware/symfony:5-php-8.1-v10
interruptible: true
tags:
- allsoftware-deployment
stages:
- setup
- build
- tests
.vendor-dev-cache: &vendor_dev_cache
key:
files:
- composer.lock
prefix: dev
paths:
- vendor/
policy: pull
composer_dev_install:
stage: setup
cache:
- <<: *vendor_dev_cache
policy: pull-push
needs: [ ]
variables:
APP_ENV: dev
APP_DEBUG: 1
script:
- cp .env.gitlab-runner .env.local
- composer install --no-scripts --no-interaction --prefer-dist --optimize-autoloader
phpstan:
stage: tests
cache:
- <<: *vendor_dev_cache
needs:
- composer_dev_install
variables:
APP_ENV: dev
APP_DEBUG: 1
script:
- ls -lah vendor # <---- crash HERE
- php bin/console cache:clear --no-warmup
- php -d memory_limit=4G vendor/bin/phpstan analyse -c phpstan.neon
translations_lint:
stage: tests
cache:
- <<: *vendor_dev_cache
needs:
- composer_dev_install
variables:
APP_ENV: dev
APP_DEBUG: 1
script:
- ls -lah vendor
- php bin/console lint:yaml translations
- php bin/console lint:xliff translations
Error
When using this config, phpstan
job doesn’t get the vendor/
directory, and fail on the ls
command.
OR the translation_lint
has succeed!
Weird behavior
Switching job places between phpstan
and translations_lint
allows the phpstan
job to run but fail on the translations_lint
.
# [...]
.vendor-dev-cache: &vendor_dev_cache
key:
files:
- composer.lock
prefix: dev
paths:
- vendor/
policy: pull
composer_dev_install:
stage: setup
cache:
- <<: *vendor_dev_cache
policy: pull-push
needs: [ ]
variables:
APP_ENV: dev
APP_DEBUG: 1
script:
- cp .env.gitlab-runner .env.local
- composer install --no-scripts --no-interaction --prefer-dist --optimize-autoloader
translations_lint:
stage: tests
cache:
- <<: *vendor_dev_cache
needs:
- composer_dev_install
variables:
APP_ENV: dev
APP_DEBUG: 1
script:
- ls -lah vendor # <--- Now crash HERE
- php bin/console lint:yaml translations
- php bin/console lint:xliff translations
phpstan:
stage: tests
cache:
- <<: *vendor_dev_cache
needs:
- composer_dev_install
variables:
APP_ENV: dev
APP_DEBUG: 1
script:
- ls -lah vendor
- php bin/console cache:clear --no-warmup
- php -d memory_limit=4G vendor/bin/phpstan analyse -c phpstan.neon
What is the problem???
I assumed that it comes from needs
behavior, so I ended up putting phpstan
IN the needs
of translations_lint
, but it doesn’t help.
From:
To:
Or the inverse:
Version
- GitLab:
16.1.2-ee
- Runner:
16.1.0 (865283c5)