We have a CI&CD process that have a dockerfile within for deploying to laravel vapor environments via bitbucket pipeline which consists of 4 basic steps:
- Install
- Build
- Test
- Deploy
The interesting point is that, we’re passing 3 steps without any problems.
We can run the same command on the 4th step on our local environment and deploy to any environments without any problems.
But when we’re trying to deploy it via Bitbucket Pipeline (which was already working 10 days ago but broken now) we’re failing with an error message of
In ClassLoader.php line 571:
include(/opt/atlassian/pipelines/agent/build/.vapor/build/app/vendor/compos
er/../composer/composer/src/Composer/Console/GithubActionError.php): Failed
to open stream: No such file or directory
on composer install command.
Our current pipeline configuration:
image: lorisleiva/laravel-docker:8.0
definitions:
steps:
- step: &Install
name: Install
script:
- npm ci
- composer install
- composer dump-autoload
artifacts:
- node_modules/**
- vendor/**
- step: &Build
name: Build
script:
- npm run prod
artifacts:
- public/**
- vendor/**
- step: &Test
name: Test & Lint
script:
- php -d memory_limit=4G vendor/bin/phpstan
- vendor/bin/phplint ./ --exclude=vendor
- vendor/bin/phpunit --coverage-text --colors=never
caches:
node: node_modules
composer: vendor
public: public
pipelines:
branches:
release/test:
- step: *Install
- step: *Build
- step: *Test
- step:
name: Release to Vapor [test]
services:
- docker
script:
- COMMIT_MESSAGE=`git log --format=%B -n 1 $BITBUCKET_COMMIT`
- vendor/bin/vapor deploy test --commit="$BITBUCKET_COMMIT" --message="$COMMIT_MESSAGE"
our test dockerfile for vapor
FROM laravelphp/vapor:php80
COPY . /var/task
and our vapor configuration:
build:
- "COMPOSER_MIRROR_PATH_REPOS=1 composer install --no-dev"
- "php artisan event:cache"
- "npm ci && npm run prod && rm -rf node_modules"
deploy:
- "php artisan migrate"
- "php artisan lighthouse:clear-cache"
Tried to remove composer cache on bitbucket pipeline config.
Read composer cache not working on bitbucket pipeline build and https://github.com/lorisleiva/laravel-docker/issues/67 but still have no idea why it is happening so any help or suggestions are more than welcome.
3
Answers
I’m having the same issue.
Is working fine if I remove on vapor.yaml file " –no-dev" in this line.
Of course is not a solution, but maybe it helps to identify the issue.
TLDR: Run
rm -rf ./vendor
before your composer install before deploying.Now to our analysis 👇🏼
We run all our tests and deploys in GitLab CI (thanks to @lorisleiva 🤗 ). And we have 3 jobs in 3 stages:
composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
COMPOSER_MIRROR_PATH_REPOS=1 composer install --prefer-dist --no-ansi --no-interaction --no-progress --optimize-autoloader --no-dev
So, in the composer job we install our dev dependencies because we need them to test the app. The resulting
./vendor
directory gets cached by GitLab’s CI system and it’s automatically made available for the subsequent stages.That’s great, cause it means we install dependencies once and then we can re use that in the testing and deploying stages. So we "deploy the same thing that we tested"…
But that’s actually false, cause for production we don’t want to install the development dependencies. That’s why we use the
--no-dev
flag in composer in the deploy stage. Keep in mind, we do need those development dependencies to run phpunit.And when we run it we see a message like:
That makes sense, we already have access to the cached
./vendor
directory from the composer job and now we only need to remove the development dependencies.That’s when things fall apart. I’ve no idea if this is a bug in composer itself, in a dependency, in our codebase, etc… but composer errors out with the
...GithubActionError.php
error when trying to remove the development dependencies. If we remove the--no-dev
it works perfectly, but That’s A NoNo.Long story short, our solution is to embrace the fact that composer.lock exists and that this job runs in CI (where the download speed is insanely fast). So we nuke the
./vendor
directory runningrm -rf ./vendor
right before the deployablecomposer install ... --no-dev
.In the end, I think this is perfectly acceptable.
I’m sure there’s a way to tell GitLab to avoid downloading the cached
./vendor
directory, or an overall better way to do this. But we’ve spent way to much time today trying to understand and fix this… so, it’s going to stay like this. And, no, it doesn’t seen to be related tolorisleiva/laravel-docker:x.x
docker images.I hope this is helpful or at least interesting 🙂
Please do let me know if anyone finds a better approach.
Source here https://github.com/lorisleiva/laravel-docker/issues/67#issuecomment-1009419913
I was having same issue but finally fixed.
I am using gitlab pipeline with same
lorisleiva/laravel-docker:8.0
image. Further investigation i foundcomposer self-update
givesCommand "self-update" is not defined.
so i thought it is about composer.So i change .gitlab.ci.yml file like this;
So i download new composer.phar file and used that instead of default composer command and it is worked.