brefphp / laravel-bridge

Package to use Laravel on AWS Lambda with Bref
https://bref.sh/docs/frameworks/laravel.html
MIT License
314 stars 63 forks source link

[v2] Issues with Build Server #115

Open deleugpn opened 1 year ago

deleugpn commented 1 year ago

While upgrading to Bref 2, I looked over at the Laravel bridge improvements and I decided to retire my own bridge.

I use AWS CodeBuild to build the project before releasing. That entails

When Composer Installs without dev dependencies, it crashes with errors such as [...] CollisionServiceProvider not found. This seems to be caused by the fact that composer install will generate a cache of packages.php and services.php. It might also be relevant that on the first run, BrefServiceProvider has not been downloaded yet and it's likely that the cache files are written down in bootstrap/cache/ standard folder.

I managed to fix this by doing two things: defining environment variables for the cache files and creating the storage directories outside of Lambda.

      - LAMBDA_TASK_ROOT=/var/task
      - APP_SERVICES_CACHE=/tmp/storage/bootstrap/cache/services.php
      - APP_PACKAGES_CACHE=/tmp/storage/bootstrap/cache/packages.php

These are the variables I added to my docker-compose setup for the build process.

image

The change to the original bootstrap/app.php seemed necessary because 1) the /tmp/storage folder does not exist by default and 2) the bref-init.php file is not being executed when running outside of Lambda (i.e. build server).

I'm not sure what recommendation/documentation/suggestion should be made to accommodate this usecase, so I thought I'd at least open a issue to allow folks to read through my approach to solving this.

georgeboot commented 1 year ago

This seems like a build pipeline issue, not so much one in this package. Or am I missing something? I can successfully run a composer install --no-dev on my projects.