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:

  1. Set a VAPOR_API_TOKEN environment variable in the project settings
  2. 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

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.