The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

Speed up your CI builds with Airdrop

Published on by

Speed up your CI builds with Airdrop image

I'm on a mission to use NodeJS the least amount possible. Why? Because it slows down people's builds on Chipper CI!

Luckily, Airdrop exists.

Laravel Airdrop is a tool that stores your built static assets. When you do CI runs, Airdrop checks to see if your static assets have changed.

If the assets have not changed, Airdrop downloads them from storage and places in the right place - allowing you to skip building your assets.

If they have changed, then you use Node to build your static assets as usual.

This is great for saving time in CI and deployment.

Here's how to use Airdrop.

Install

Installing Airdrop is easy:

composer require hammerstone/airdrop
 
# Add config/airdrop.php to your project
php artisan airdrop:install

Configuring Airdrop

There's only a few things to configure in Airdrop - and a bunch of them can be left to their defaults.

Triggers

You can tell Airdrop when to decide to re-build static assets.

Triggers are specific to the environment (APP_ENV) - each environment gets its own set of files. This is called the Configuration trigger.

The other trigger is the FileTrigger. This tracks configured files and rebuilds assets if the files have changed.

The FileTrigger will check:

  1. Files in the resources (CSS, JS, etc)
  2. If the Webpack/Vite configuration file changes

I also add the package-lock.json file that NPM produces.

<?php
 
use Hammerstone\Airdrop\Drivers\FilesystemDriver;
use Hammerstone\Airdrop\Drivers\GithubActionsDriver;
use Hammerstone\Airdrop\Triggers\ConfigTrigger;
use Hammerstone\Airdrop\Triggers\FileTrigger;
 
return [
'driver' => env('AIRDROP_DRIVER', 'default'),
'drivers' => [
'default' => [...],
'github' => [...],
],
'triggers' => [
ConfigTrigger::class => [
'env' => env('APP_ENV')
],
FileTrigger::class => [
'include' => [
resource_path(), // default
base_path('webpack.mix.js'), // mix default
base_path('vite.config.js'), // vite default
base_path('package-lock.json'), // my addition here
],
],
],
'outputs' => [...],
];

Drivers

You can decide where Airdrop will store static assets. Usually you just use the FilesystemDriver here, and use Laravel's Storage mechanism to tell Airdrop where to put the files.

The disk setting related to the Laravel “disk” storage used. Using some remote storage, such as s3, is recommended.

The GitHub Actions Driver lets you save files to the GH Actions cache, which is pretty handy!

return [
// The driver you wish to use to stash and restore your files.
'driver' => env('AIRDROP_DRIVER', 'default'),
 
'drivers' => [
'default' => [
// The class responsible for implementing the stash and restore
// logic. Must extend BaseDriver.
'class' => FilesystemDriver::class,
 
// The disk on which to store the built files.
'disk' => env('AIRDROP_REMOTE_DISK', 's3'),
 
// The folder (if any) where you'd like your stashed assets to reside.
'remote_directory' => env('AIRDROP_REMOTE_DIR', 'airdrop'),
 
// A writeable directory on the machine that builds the assets.
// Used to build up the ZIP file before stashing it.
'local_tmp_directory' => env('AIRDROP_LOCAL_TMP_DIR', storage_path('framework')),
 
// The skip file is an empty file that will be created to
// indicate that asset building can be skipped.
'skip_file' => env('AIRDROP_SKIP_FILE', base_path('.airdrop_skip')),
],
],
// ...
];

Outputs

Outputs are the files that Airdrop will store and retrieve for you. The files you “watch” via Triggers don't necessarily need to be the same files you have Airdrop save/store for you!

The defaults for Airdrop are pretty good, but of course you can configure these as needed.

return [
// ...
'outputs' => [
/*
* Files or folders that should be included.
*/
'include' => [
// Mix/Webpack
public_path('mix-manifest.json'),
public_path('css'),
public_path('js'),
 
// Vite
public_path('build/manifest.json'),
public_path('build/assets'),
],
 
// ...
],
];

Note: You likely don't want to commit static assets to your repository when using Airdrop. To avoid that, and to finish configuring Airdrop, add the following to your .gitignore file:

/.airdrop_skip
 
# Mix/Webpack
public/css/*
public/js/**
 
# Vite
public/build/*

Integrating Airdrop

When you build your app Airdrop in CI, or in a deployment script (this works great for Forge quick deploys!), you can run the following:

# Download files, only if needed
php artisan airdrop:download
 
# Airdrop creates .airdrop_skip if
# it downloaded files
if [ ! -f ".airdrop_skip" ]; then
npm ci --no-audit
npm run dev
fi
 
# Upload the files if needed
php artisan airdrop:upload
Chris Fidao photo

Teaching coding and servers at CloudCasts and Servers for Hackers. Co-founder of Chipper CI.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Jump24 - UK Laravel Agency

Laravel Developers that Click into Place. Never outsourced. Never offshored. Always exceptional.

Visit Jump24 - UK Laravel Agency
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit

The latest

View all →
Ship AI with Laravel: Smart Ticket Triage with Structured Output image

Ship AI with Laravel: Smart Ticket Triage with Structured Output

Read article
PHPantom: A Fast PHP Language Server Built in Rust image

PHPantom: A Fast PHP Language Server Built in Rust

Read article
Axios npm Package Compromised With Remote Access Trojan image

Axios npm Package Compromised With Remote Access Trojan

Read article
Build an AI Chat Agent with Laravel 12, MongoDB Atlas Vector Search, and Voyage AI image

Build an AI Chat Agent with Laravel 12, MongoDB Atlas Vector Search, and Voyage AI

Read article
PHP Debugger: A Lightweight Xdebug Alternative Built for Speed image

PHP Debugger: A Lightweight Xdebug Alternative Built for Speed

Read article
Laravel USPS: A Modern Wrapper for the USPS API image

Laravel USPS: A Modern Wrapper for the USPS API

Read article