Deploying to Laravel Vapor
Laravel Vapor has its own CLI command that will let you deploy your various Vapor environments.
Chipper CI does not install the vapor command globally. We assume instead that most projects include Vapor as a composer dependency.
For most projects, this means that you can simply use the vapor command as it's likely present at ./vendor/bin/vapor (remember, ./vendor/bin is set in $PATH).
Deploying from Vapor in Chipper CI has two steps:
- Set a
VAPOR_API_TOKENenvironment variable in the project settings- This can be generated within the Vapor API settings dashboard
- Within your build pipeline, run one of the following commands
# Most simply, deploy your "production" environment
vapor deploy production
# Optionally, add some related data to the deployment
vapor deploy production --commit="${CI_COMMIT_SHA}" --message="${CI_COMMIT_MESSAGE}"
Deploying Environments
If you would like to deploy to different Vapor environments depending on the branch, tag, or even commit message you can use some custom logic within your pipeline.
For example, here's a way to deploy to production versus staging:
# Deploy to a different environment depending on the branch
if [[ $CI_COMMIT_BRANCH == 'master' ]]; then
vapor deploy production
fi
if [[ $CI_COMMIT_BRANCH == 'develop' ]]; then
vapor deploy staging
fi
Check out the other build environment variables available. For example, you can test the value of the CI_COMMIT_TAG variable to decide to deploy based on a tag instead of a branch.
Docker Runtime
If you use Vapor's Docker runtime, Docker is needed to deploy to Vapor.
Docker is available only in paid teams in Chipper CI. You must enable Docker in each project that you'd like to use it in.
Deployment Issues
There are 2 common deployment issues we see:
Error: Failed opening required...
A common issue can arise when Composer uses symlinks to autoload packages outside of the vendor directory.
You'll see errors in Vapor application's CloudWatch logs similar to this:
Fatal error: require(): Failed opening required '/var/task/vendor/composer/../foo/bar...
As per this GitHub issue, the resolution is to run the composer install command with the COMPOSER_MIRROR_PATH_REPOS option:
COMPOSER_MIRROR_PATH_REPOS=1 composer install
The above command should be within your vapor.yaml file rather than within the Chipper CI pipeline, as it needs to be the command used to download composer dependencies when running vapor deploy.
Error: failed to open stream: No such file or directory
This error is often seen on Composer file GithubActionError.php.
This happens when the composer/composer package is required as a dev dependency within your composer.json file.
Since Chipper CI adds vendor/bin the $PATH variable, this directory is checked first. This results in Vapor using ./vendor/bin/composer when running commands composer install --no-dev.
The result is that the composer command deletes itself while it's running. The most common error when this happens is:
In ClassLoader.php line 571:
include(/alloc/chipper/repository/.vapor/build/app/vendor/composer/../composer/composer/src/Composer/Console/GithubActionError.php):
failed to open stream: No such file or directory
You can fix this in two ways:
- (Recommended) Delete
./vendor/bin/composerjust before runningvapor deploy - Or, remove
composer/composeras a dev dependency
The simplest is to just update your pipeline script so it deletes the ./vendor/bin/composer command first:
rm -f ./vendor/bin/composer
vapor deploy
This makes it so vapor runs composer install from the globally installed /usr/bin/composer instead of the locally installed ./vendor/bin/composer.