This guide will walk you though how I use GitHub Actions to create a CI/CD pipeline for Laravel applications. We'll use Lasso from Sam Carré to compile Webpack assets and upload them to a S3 storage provider and then trigger a deployment using the workflow.
Warning: This article is very much a work-in-progress and in need of polishing my brain dump.
"CI/CD" is Continuous (Integeration or Iteration) / Continuous (Development, Delivery or Deployment) is a process of developing, testing and deploying your code. You'll also likely see this referred to as an "Agile Development Cycle".
Let's all get on the same page so we don't make a 🍑 out of you and me.
For this example we're going to use a pretty simple master main, develop and feature branching model. Develop will be our default branch where all code is based from and main will be our production code.
We're going to go into some detail but the overall summary of the CI/CD pipeline looks like this.
developto do your work in.
developbranch run our builds and tests.
developrun a workflow to compile and upload the assets to an S3 bucket using Lasso and deploy the code.
developfor a release, open a PR into the
mainbranch and we'll repeat steps 3 and 4 for production.
First we need to require a couple of packages.
composer require league/flysystem-aws-s3-v3 ~1.0.
composer require sammyjo20/lasso.
Next we need to update Laravel's
.env file with additional S3 driver options and the Lasso environment.
Next let's get Lasso configured, for a full explaination of the settings go to the Lasso readme.
php artisan vendor:publish --tag=lasso-config.
'disk' => 'assets'to
'disk' => 's3'to use the S3 drivers.
upload_toif you plan on using the same bucket for multiple sites. You'll notice in this repository I've set it to
Since the whole point of this is to automate our deployments and no longer commit our assets to GitHub we need to update our
.gitignore file as well.
To get us started we're going to create and run two workflows, one to do our testing (CI) and one to do our deploying (CD).
The goal of this workflow is to run our build and tests when a PR is opened and when any changes are made to code where a PR is already open.
We're only going to add one section here to make sure our NPM dependencies install and package correctly.
Copy .env step add the
Install npm dependencies and package step to your workflow.
This workflow can be found here: test.yml.
The goal of this workflow is to run when a PR is merged into develop or mail, run our tests, compile and upload assets with Lasso and finally deploy the code.
This workflow can be found here: deploy.yml.
Important: Never hard code passwords or tokens into your code, use secrets.
Before we can use secrets in our workflow we need to create them in the repository. Go to Settings -> Secrets in your repository and add the following variables.
|AWS_ACCESS_KEY_ID||Also known as the public key to your account or API user.|
|AWS_SECRET_ACCESS_KEY||Also known as the secret key to your account or API user.|
|AWS_DEFAULT_REGION||The default region where you bucket resides.|
|AWS_BUCKET||The buckets name.|
|AWS_ENDPOINT||The endpoint should be a fully qualified domain name including the protocol (https://).|
Note: You can use any s3 compliant API service, I use Backblaze's B2 service because it's cheaper than AWS.
In addition to the changes we made to test our NPM dependencies we'll add additional steps to complete the process.
We're going to add a new step to compile and upload our assets to our S3 bucket and we'll call
Publish assets with Lasso.
Lastly you need to add
php artisan lasso:pull to your deployment script, I suggest doing this prior to clearing or filling any caches.
Almost forgot, don't forget to update your S3 variables in your
Well, that's pretty much it. At this point you should be up and running, should you have an issues getting this setup Twitter is the best way to reach me.
The steps called
Trigger develop deployment and
Trigger production deployment in deploy.yml
deploy to different environments based on branch name.
This pattern allows me to deploy code from my
develop branch to my
preview environment and code from my
main branch to my
CI/CD pipelines have many forms, each is specific to the needs of the project and should evolve over time. This is just one way of doing it, find the process that works for you.
I'm Alex, I've done some form of web development for the better part of 15 years. I currently work for MassMutual doing operational data architecture and web development for our insurance business lines.
I also do a bit of feelance work to pay for 🍺 and 🚗.
You can get ahold of me through the methods below.