DEV Community

Cover image for Laravel Vapor Multiple Deploy File to different AWS account or region
Norby Baruani
Norby Baruani

Posted on

Laravel Vapor Multiple Deploy File to different AWS account or region

Brief Description

Will be sharing how I was able to deploy same codebase to different AWS account on Vapor using multiple vapor.yml config file with the help of bash scripts.

At the time of writing this, Laravel Vapor did not support deploy command to receive a filepath to deploy against. Hopefully one day that feature can be added by the team.

These approach allows you to use separate AWS account for your staging and production environments if needed as well better than that deploy to multiple aws account or multiple aws region.

How it works

Assuming you already have your laravel project setup and working with Laravel Vapor.

  1. Rename vapor.yml to vapor.{account}.yml, project should be a unique name different to the other file you need to create. eg. vapor.dev.yml 2.Create another vapor config file to deploy to the different account or region. eg. vapor.devcon.yml and make sure config are correct.
  2. Make sure vapor.yml file doesn't exist on your root directory of project anymore.
  3. Copy the following scripts to the root directory of project and make sure to make them executable.

Interact with scripts

At this stage you should have 2 vapor config file on your root directory. From our example you would have:

vapor.dev.yml
vapor.devcon.yml
Enter fullscreen mode Exit fullscreen mode
Vapor CLI:
./vapor-cli.sh dev env:pull staging
./vapor-cli.sh dev env:push staging
Enter fullscreen mode Exit fullscreen mode
Deploy:
./vapor-deploy.sh dev staging
./vapor-deploy.sh devcon production
Enter fullscreen mode Exit fullscreen mode

Take Away

This approach can be used to deploy Staging and Production to different AWS account or Region as well.

All that will be

  • To have correct file naming and config to have only correct environment setting on the related file.

  • To make changes to both script by to only allow 1 argument and use 1st argument as filename and environment to run against.

Eg.

vapor.staging.yml
vapor.production.yml
Enter fullscreen mode Exit fullscreen mode
./vapor-deploy.sh staging
./vapor-deploy.sh production
Enter fullscreen mode Exit fullscreen mode

Top comments (0)