This Github Action provides a way to directly use Laravel Vapor from within your CI/CD pipeline.
Need anything beyond the default extensions necessary for Laravel, or a custom PHP version? We've got you covered.
Alternatively, to optimize for speed, you can also use our automatically built Docker image. 🔥
To use this Github Action, you will need an active Laravel Vapor subscription.
In order to authenticate with Vapor from Github Actions, we will need to add a VAPOR_API_TOKEN
secret to your repository.
To do so, you may do the following:
- On GitHub, navigate to the main page of the repository you intend to use this action on.
- Under your repository name, click
Settings
. - In the left sidebar, click
Secrets
. - Click
Add a new secret
. - For the name of your secret, enter
VAPOR_API_TOKEN
. - For the value itself, enter your Laravel Vapor API token. You may generate one in your Vapor API settings dashboard.
- Click
Add secret
.
Next, let's head over to the Actions
page, and create a new workflow.
To keep things simple, let's set up an action that deploys to production as soon as a branch is merged into master:
name: Deploy to production
on:
push:
branches: [ master ]
jobs:
vapor:
name: Check out, build and deploy using Vapor
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: ubient/laravel-vapor-action@master
env:
VAPOR_API_TOKEN: ${{ secrets.VAPOR_API_TOKEN }}
with:
args: "deploy production"
The above does a few things:
- It does a git checkout out your Laravel App (your repository) using the
actions/checkout
action. - It builds the
ubient/laravel-vapor-action@master
image (using this repository's Dockerfile). - It runs the built container, passing in the Vapor API token previously configured in your repository's Github Secrets.
- It executes the
vapor
CLI command, passing in the arguments given. In our example, this means it runsvapor deploy production
.
If you would like to find out more regarding the syntax used by Github Actions, you can take a look at this page.
Because building the Docker image on reach run costs a lot of time, you may use our (automatically built) Docker image instead. To do so, set up a Github Secret like previously described, but use the following instead when creating an Actions workflow:
name: Deploy to production
on:
push:
branches: [ master ]
jobs:
vapor:
name: Check out and deploy using Vapor
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Login to Github Package Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- name: Deploy to Production
run: |
docker run \
--env VAPOR_API_TOKEN=${{ secrets.VAPOR_API_TOKEN }} \
--volume $(pwd):/app \
docker.pkg.github.com/ubient/laravel-vapor-action/laravel-vapor-action:latest \
deploy production
As you might've noticed, the above uses a special GITHUB_TOKEN
secret. This secret is automatically generated by Github
meaning that you do not need to do any additional configuration in order to get things working.
Need something extra, such as a different PHP version or additional PHP extensions? That's possible!
Set up a Github Secret like previously described, but use the following instead when creating an Actions workflow:
name: Deploy to Production
on:
push:
branches: [ master ]
jobs:
vapor:
name: Check out, build and deploy using Vapor
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP (w/ extensions) & Composer
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: pecl
extensions: bcmath, ctype, fileinfo, json, mbstring, openssl, pdo, tokenizer, xml
coverage: none
- name: Obtain Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache Composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Vapor CLI Globally
run: composer global require laravel/vapor-cli
- name: Install Composer dependencies
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Obtain NPM Cache directory (used by Laravel Mix)
id: node-cache-dir
run: echo "::set-output name=dir::$(npm config get cache)" # Use $(yarn cache dir) for yarn
- name: Cache NPM dependencies (used by Laravel Mix)
uses: actions/cache@v1
with:
path: ${{ steps.node-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} # Use '**/yarn.lock' for yarn
restore-keys: ${{ runner.os }}-node-
- name: Deploy using Laravel Vapor
env:
VAPOR_API_TOKEN: ${{ secrets.VAPOR_API_TOKEN }}
run: /home/runner/.composer/vendor/bin/vapor deploy production
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.