CoderFunda
  • Home
  • About us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • About us
  • Home
  • Php
  • HTML
  • CSS
  • JavaScript
    • JavaScript
    • Jquery
    • JqueryUI
    • Stock
  • SQL
  • Vue.Js
  • Python
  • Wordpress
  • C++
    • C++
    • C
  • Laravel
    • Laravel
      • Overview
      • Namespaces
      • Middleware
      • Routing
      • Configuration
      • Application Structure
      • Installation
    • Overview
  • DBMS
    • DBMS
      • PL/SQL
      • SQLite
      • MongoDB
      • Cassandra
      • MySQL
      • Oracle
      • CouchDB
      • Neo4j
      • DB2
      • Quiz
    • Overview
  • Entertainment
    • TV Series Update
    • Movie Review
    • Movie Review
  • More
    • Vue. Js
    • Php Question
    • Php Interview Question
    • Laravel Interview Question
    • SQL Interview Question
    • IAS Interview Question
    • PCS Interview Question
    • Technology
    • Other

25 August, 2022

Speed up your CI builds with Airdrop

 Programing Coderfunda     August 25, 2022     Laravel, Laravel Tutorials, Packages     No comments   

 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:

1composer require hammerstone/airdrop
2 
3# Add config/airdrop.php to your project
4php 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.

1<?php
2 
3use Hammerstone\Airdrop\Drivers\FilesystemDriver;
4use Hammerstone\Airdrop\Drivers\GithubActionsDriver;
5use Hammerstone\Airdrop\Triggers\ConfigTrigger;
6use Hammerstone\Airdrop\Triggers\FileTrigger;
7 
8return [
9 'driver' => env('AIRDROP_DRIVER', 'default'),
10 'drivers' => [
11 'default' => [...],
12 'github' => [...],
13 ],
14 'triggers' => [
15 ConfigTrigger::class => [
16 'env' => env('APP_ENV')
17 ],
18 FileTrigger::class => [
19 'include' => [
20 resource_path(), // default
21 base_path('webpack.mix.js'), // mix default
22 base_path('vite.config.js'), // vite default
23 base_path('package-lock.json'), // my addition here
24 ],
25 ],
26 ],
27 'outputs' => [...],
28];

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!

1return [
2 // The driver you wish to use to stash and restore your files.
3 'driver' => env('AIRDROP_DRIVER', 'default'),
4 
5 'drivers' => [
6 'default' => [
7 // The class responsible for implementing the stash and restore
8 // logic. Must extend BaseDriver.
9 'class' => FilesystemDriver::class,
10 
11 // The disk on which to store the built files.
12 'disk' => env('AIRDROP_REMOTE_DISK', 's3'),
13 
14 // The folder (if any) where you'd like your stashed assets to reside.
15 'remote_directory' => env('AIRDROP_REMOTE_DIR', 'airdrop'),
16 
17 // A writeable directory on the machine that builds the assets.
18 // Used to build up the ZIP file before stashing it.
19 'local_tmp_directory' => env('AIRDROP_LOCAL_TMP_DIR', storage_path('framework')),
20 
21 // The skip file is an empty file that will be created to
22 // indicate that asset building can be skipped.
23 'skip_file' => env('AIRDROP_SKIP_FILE', base_path('.airdrop_skip')),
24 ],
25 ],
26 // ...
27];

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.

1return [
2 // ...
3 'outputs' => [
4 /*
5 * Files or folders that should be included.
6 */
7 'include' => [
8 // Mix/Webpack
9 public_path('mix-manifest.json'),
10 public_path('css'),
11 public_path('js'),
12 
13 // Vite
14 public_path('build/manifest.json'),
15 public_path('build/assets'),
16 ],
17 
18 // ...
19 ],
20];

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:

1/.airdrop_skip
2 
3# Mix/Webpack
4public/css/*
5public/js/**
6 
7# Vite
8public/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:

1# Download files, only if needed
2php artisan airdrop:download
3 
4# Airdrop creates .airdrop_skip if
5# it downloaded files
6if [ ! -f ".airdrop_skip" ]; then
7 npm ci --no-audit
8 npm run dev
9fi
10 
11# Upload the files if needed
12php artisan airdrop:upload
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook

Related Posts:

  • Laravel Vue Datatables Component Example With Code Examples In this tutorial, i want to share with you how to implement datatables with vue js laravel. i will share simple example of vue datatable in lara… Read More
  • Vue JS call a function on load With Code Examples If you want to call a function on page load in vue js then in this example i will show you how to trigger function on page load in vue js. we wi… Read More
  • Vue JS Ajax Form Submit With Code Examples I will share example of how to ajax form submit using api in vue js app. you can easily pass form data with ajax post request in vue.js. we will… Read More
  • Laravel Vue JS File Upload With Code Examples Today, we will learn file upload with laravel and vue js. we will create example of laravel vue axios file upload. we can easily fire post reque… Read More
  • How to get current date time in vue js With Code Examples Do you want to get current date in vue js app. If yes then i will help you to getting current date and time in vue js app. if you know to get cu… Read More
Newer Post Older Post Home

0 comments:

Post a Comment

Thanks

Meta

Popular Posts

  • Vue3 :style backgroundImage not working with require
    I'm trying to migrate a Vue 2 project to Vue 3. In Vue 2 I used v-bind style as follow: In Vue 3 this doesn't work... I tried a...
  • Enabling authentication in swagger
    I created a asp.net core empty project running on .net6. I am coming across an issue when I am trying to enable authentication in swagger. S...
  • SQL ORDER BY Keyword
      The SQL ORDER BY Keyword The ORDER BY keyword is used to sort the result-set in ascending or descending order. The ORDER BY keyword sorts ...
  • Laravel auth login with phone or email
          <?php     Laravel auth login with phone or email     <? php     namespace App \ Http \ Controllers \ Auth ;         use ...
  • AdminJS not overriding default dashboard with custom React component
    So, I just started with adminjs and have been trying to override the default dashboard with my own custom component. I read the documentatio...

Categories

  • Ajax (26)
  • Bootstrap (30)
  • DBMS (42)
  • HTML (12)
  • HTML5 (45)
  • JavaScript (10)
  • Jquery (34)
  • Jquery UI (2)
  • JqueryUI (32)
  • Laravel (1017)
  • Laravel Tutorials (23)
  • Laravel-Question (6)
  • Magento (9)
  • Magento 2 (95)
  • MariaDB (1)
  • MySql Tutorial (2)
  • PHP-Interview-Questions (3)
  • Php Question (13)
  • Python (36)
  • RDBMS (13)
  • SQL Tutorial (79)
  • Vue.js Tutorial (68)
  • Wordpress (150)
  • Wordpress Theme (3)
  • codeigniter (108)
  • oops (4)
  • php (853)

Social Media Links

  • Follow on Twitter
  • Like on Facebook
  • Subscribe on Youtube
  • Follow on Instagram

Pages

  • Home
  • Contact Us
  • Privacy Policy
  • About us

Blog Archive

  • September (100)
  • August (50)
  • July (56)
  • June (46)
  • May (59)
  • April (50)
  • March (60)
  • February (42)
  • January (53)
  • December (58)
  • November (61)
  • October (39)
  • September (36)
  • August (36)
  • July (34)
  • June (34)
  • May (36)
  • April (29)
  • March (82)
  • February (1)
  • January (8)
  • December (14)
  • November (41)
  • October (13)
  • September (5)
  • August (48)
  • July (9)
  • June (6)
  • May (119)
  • April (259)
  • March (122)
  • February (368)
  • January (33)
  • October (2)
  • July (11)
  • June (29)
  • May (25)
  • April (168)
  • March (93)
  • February (60)
  • January (28)
  • December (195)
  • November (24)
  • October (40)
  • September (55)
  • August (6)
  • July (48)
  • May (2)
  • January (2)
  • July (6)
  • June (6)
  • February (17)
  • January (69)
  • December (122)
  • November (56)
  • October (92)
  • September (76)
  • August (6)

  • Failed to install 'cordova-plugin-firebase': CordovaError: Uh oh - 9/21/2024
  • pyspark XPath Query Returns Lists Omitting Missing Values Instead of Including None - 9/20/2024
  • SQL REPL from within Python/Sqlalchemy/Psychopg2 - 9/20/2024
  • MySql Explain with Tobias Petry - 9/20/2024
  • How to combine information from different devices into one common abstract virtual disk? [closed] - 9/20/2024

Laravel News

  • "In Array Keys" Validation Rule Added in Laravel 12.16 - 5/28/2025
  • Validate URLs Effectively with Laravel's Str::isUrl Method - 5/25/2025
  • Setup Social Auth Redirects with Laravel Herd - 5/27/2025
  • Last Call: Early Access for NativePHP Ends This Week - 5/27/2025
  • Use Amazon Bedrock in Laravel with Prism PHP - 5/27/2025

Copyright © 2025 CoderFunda | Powered by Blogger
Design by Coderfunda | Blogger Theme by Coderfunda | Distributed By Coderfunda