Dwight Watson's blog

Deploying to Laravel Vapor with GitHub Actions

This blog post was originally published a little while ago. Please consider that it may no longer be relevant or even accurate.

I've been using GitHub Actions more and more as a CI pipeline for my Laravel apps. Following a successful build on the master branch I want to deploy my apps to production which is now starting to be Laravel Vapor. The process is pretty easy.

First, get an API key from Laravel Vapor and add it as a secret to your GitHub project. I use VAPOR_API_TOKEN as the secret name. You can then reference the API key using the ${{ secrets.VAPOR_API_TOKEN }} syntax and making it available as an environment variable when you deploy your app.

Finally, you can also pass through the commit ID and message so that Vapor's UI can better distinguish what was contained in the deployment.

name: Deploy

on: [push]

jobs:
deploy:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'

steps:
- uses: actions/checkout@v1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, memcached
tools: composer:v2

- name: Use Node.js 15.x
uses: actions/setup-node@v1
with:
node-version: 15.x

- name: Install composer dependencies
run: composer install --prefer-dist --no-interaction --no-progress

- name: Deploy to production
env:
VAPOR_API_TOKEN: ${{ secrets.VAPOR_API_TOKEN }}
run: vendor/bin/vapor deploy production --commit="${{ github.event.head_commit.id }}" --message="${{ github.event.head_commit.message }}"

If you're deploying to multiple Vapor apps/environments you may consider using a matrix which allows the jobs to run in parallel resulting in faster deployments. In the below example I use multiple Vapor manifests to deploy into two production environments at the same time.

deploy:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'

strategy:
matrix:
manifest: [vapor.yml, vapor.nz.yml]

steps:
//

- name: Deploy to production
env:
VAPOR_API_TOKEN: ${{ secrets.VAPOR_API_TOKEN }}
run: vendor/bin/vapor deploy production --manifest="${{ matrix.manifest }}" --commit="${{ github.event.head_commit.id }}" --message="${{ github.event.head_commit.message }}"

A blog about Laravel & Rails by Dwight Watson;

Picture of Dwight Watson

Follow me on Twitter, or GitHub.