skip to Main Content

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


  1. I’m having the same issue.

    Is working fine if I remove on vapor.yaml file " –no-dev" in this line.

     - 'COMPOSER_MIRROR_PATH_REPOS=1 composer install'
    

    Of course is not a solution, but maybe it helps to identify the issue.

    Login or Signup to reply.
  2. 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:

    1. preparation stage runs the "composer" job, which runs composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
    2. testing stage runs the "phpunit" job
    3. deploy stage runs our Vapor deploy script, which runs 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:

    Installing dependencies from lock file
    Verifying lock file contents can be installed on current platform.
    Package operations: 0 installs, 0 updates, 73 removals
    

    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 running rm -rf ./vendor right before the deployable composer 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 to lorisleiva/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

    Login or Signup to reply.
  3. I was having same issue but finally fixed.

     include(/builds/myapp/myapp-api/vendor/composer/../composer/composer/sr  
      c/Composer/Console/GithubActionError.php): Failed to open stream: No such f  
      ile or directory           
    

    I am using gitlab pipeline with same lorisleiva/laravel-docker:8.0 image. Further investigation i found composer self-update gives Command "self-update" is not defined. so i thought it is about composer.

    So i change .gitlab.ci.yml file like this;

    - curl -sS https://getcomposer.org/installer | php
    - ./composer.phar -V
    - ./composer.phar install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts --ignore-platform-reqs
    

    So i download new composer.phar file and used that instead of default composer command and it is worked.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search