Skip to content

Commit fe3821f

Browse files
committed
Docs
1 parent 9c0fdac commit fe3821f

File tree

13 files changed

+494
-24
lines changed

13 files changed

+494
-24
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ yarn-error.log
77
composer.lock
88
bootstrap/cache/packages.php
99
bootstrap/cache/services.php
10+
11+
docs/*.blade.php
12+
docs/**/*.blade.php

docs/configuration.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
# Configuration
3+
4+
The Airdrop configuration file contains a reasonable starting point for most Laravel applications, but you'll want to customize it for your particular app.
5+
6+
To publish this file, run `php artisan airdrop:install`
7+
8+
## Drivers
9+
10+
The driver you choose determines how your built assets will be stashed and restored.
11+
12+
By default, we only offer one driver: the Filesystem driver. It will store built assets as `.zip` on a disk of your choosing (usually a cloud provider).
13+
14+
To read more about the various configuration options, head to the [Filesystem Driver](/drivers/filesystem) section.
15+
16+
## Triggers
17+
18+
The `triggers` section tells Airdrop how to calculate if your assets need to be rebuilt. We offer two different triggers out of the box:
19+
- [Config Trigger](/triggers/config) than can trigger a build based on ENV vars (or any other config).
20+
- [File Trigger](/triggers/file) that triggers a build whenever a file changes.
21+
22+
Each trigger has its own configuration that you can use to fine-tune your settings, but both come with reasonable defaults.
23+
24+
You can have as many triggers as you want. You can also [build your own](/triggers/custom).
25+
26+
## Outputs
27+
28+
The `outputs` section of the config file defines which files are generated as the result of your build process.
29+
30+
**Anything that is generated as a result of your build process should be included here.**
31+
32+
config/airdrop.php{.filename}
33+
```php
34+
[
35+
// ...
36+
'outputs' => [
37+
/*
38+
* Files or folders that should be included.
39+
*/
40+
'include' => [
41+
// The mix-manifest file tells Laravel how to get your versioned assets.
42+
public_path('mix-manifest.json'),
43+
44+
// Compiled CSS.
45+
public_path('css'),
46+
47+
// Compiled JS.
48+
public_path('js'),
49+
],
50+
51+
/*
52+
* Files or folders that should be excluded or ignored.
53+
*/
54+
'exclude' => [
55+
//
56+
],
57+
]
58+
];
59+
```
60+
61+
62+
By default Airdrop will store your compiled CSS, JS, and your mix-manifest file. If Airdrop determines that a build is not necessary on the next deploy, these files will be pulled down and put in place as if they had just been built.

docs/deploying.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
# Deploying
3+
4+
To integrate Airdrop into your build process, you'll need to do a few things.
5+
6+
## Adding the Airdrop Commands
7+
8+
The first thing you'll need to do is run `php artisan airdrop:download` _before_ you build your assets. This is the command that will download and place your built assets, if they are available.
9+
10+
The next thing you'll need to do is run `php artisan airdrop:upload` _after_ you build your assets. This command will store the built assets, if they aren't already stored.
11+
12+
This will take care of downloading and uploading your assets, should that be required.
13+
14+
Once you're done, your asset step will look something like this:
15+
16+
```bash
17+
php artisan airdop:download
18+
npm run production
19+
php artisan airdrop:upload
20+
```
21+
22+
## Skipping Asset Compilation
23+
24+
The next (and last!) thing we need to change is the skipping of the compilation of assets if it isn't required.
25+
26+
The FilesystemDriver creates a flag file called `.airdrop_skip` if the asset building step can be skipped, so we need to check for the existence of that file.
27+
28+
### Laravel Mix
29+
If you're using Laravel Mix you can modify your `webpack.mix.js` file to see if that file exists, and return early if it does:
30+
31+
```js
32+
// Exit early if assets don't need to be built.
33+
if (require('fs').existsSync('.airdrop_skip')) {
34+
console.log("Assets already exist. Skipping compilation.");
35+
process.exit(0);
36+
}
37+
38+
// Rest of the file...
39+
```
40+
{data-filename="webpack.mix.js"}
41+
42+
### Bash
43+
44+
If you're not using Laravel Mix, or you want to skip several steps based on the existence of that file, you can do so using bash.
45+
46+
```bash
47+
php artisan airdrop:download
48+
49+
# Skip several steps if we can.
50+
if [ ! -f ".airdrop_skip" ]; then
51+
nvm install
52+
nvm use
53+
yarn install --frozen-lockfile
54+
npm run production
55+
fi
56+
57+
php artisan airdrop:upload
58+
```
59+
60+
Now we're skipping multiple potentially expensive commands based on the presence of the Airdrop skip file.
61+
62+
> Remember: If you change the path of the skip file in your configuration, you'll need to change it in your Mix / Bash file as well.
63+
64+
65+

docs/drivers/custom.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Building A Custom Driver
2+
3+
If the [Filesystem](/drivers/filesystem) Driver isn't quite right for you, you can build your own quite easily.
4+
5+
Your custom driver must extend the Hammerstone `BaseDriver`.
6+
7+
CustomDriver.php{.filename}
8+
```php
9+
use Hammerstone\Airdrop\Drivers\BaseDriver;
10+
11+
class CustomDriver extends BaseDriver
12+
{
13+
/**
14+
* Called after building, to stash the files somewhere.
15+
*/
16+
public function upload()
17+
{
18+
// @TODO
19+
}
20+
21+
/**
22+
* Called before building files, to see if we can skip that
23+
* altogether and just download them.
24+
*/
25+
public function download()
26+
{
27+
// @TODO
28+
}
29+
}
30+
```
31+
32+
The current hash will be available as a class property `$hash`, and the config for your driver will be available as `$config`.
33+
34+
## Enabling Your Custom Driver
35+
36+
To enable your driver, you'll need to add it to the `drivers` array in `airdrop.php`.
37+
38+
config/airdrop.php{.filename}
39+
```php
40+
'drivers' => [
41+
'custom' => [
42+
// Use our new custom class as the driver.
43+
'class' => CustomDriver::class,
44+
45+
// Pass in any configuration you want.
46+
'key' => 'value'
47+
]
48+
],
49+
```

docs/drivers/filesystem.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Filesystem Driver
2+
3+
The Filesystem Driver is the default (and only!) driver that we ship with. It stores all of your built assets as a `.zip` on a filesystem of your choosing.
4+
5+
6+
## Configuration
7+
8+
If you'd like to change the configuration, you can do so in `airdrop.php`.
9+
10+
config/aidrop.php{.filename}
11+
```php
12+
[
13+
'drivers' => [
14+
'default' => [
15+
// The class responsible for implementing the stash and restore
16+
// logic. Must extend BaseDriver.
17+
'class' => FilesystemDriver::class,
18+
19+
// The disk on which to store the built files.
20+
'disk' => env('AIRDROP_REMOTE_DISK', 's3'),
21+
22+
// The folder (if any) where you'd like your stashed assets to reside.
23+
'remote_directory' => env('AIRDROP_REMOTE_DIR', 'airdrop'),
24+
25+
// A writeable directory on the machine that builds the assets.
26+
// Used to build up the ZIP file before stashing it.
27+
'local_tmp_directory' => env('AIRDROP_LOCAL_TMP_DIR', storage_path('framework')),
28+
29+
// The skip file is an empty file that will be created to
30+
// indicate that asset building can be skipped.
31+
'skip_file' => env('AIRDROP_SKIP_FILE', base_path('.airdrop_skip')),
32+
]
33+
],
34+
]
35+
36+
```
37+
38+
39+
`disk` controls which disk your built files are stored on.
40+
41+
`remote_directory` allows you to place all of your built assets in a subdirectory on your remote disk, to avoid cluttering up the root directory.
42+
43+
`local_tmp_directory` is a place that Airdrop can use to create the `.zip` file before it is uploaded. Airdrop will clean up after itself, so nothing will be left behind once it's done.
44+
45+
`skip_file` is the file we referenced in the [deploying](/deploying) section. It's used as a signal to other processes that the built files have been successfully restored, and they do not need to be built again.
46+

docs/installation.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
# Installation
33

44
You can install the package via Composer
5-
```
5+
```console
66
composer require hammerstone/airdrop
77
```
88

99
Once the package is installed, you may optionally publish the config file by running
10-
```
10+
```console
1111
php artisan airdop:install
1212
```
13+
14+
You'll likely want to publish the config file so that you can set up your triggers and outputs.

docs/manifest.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"basePath": "/airdrop/docs/local",
3+
"assetUrl": "/airdrop/docs/local",
4+
"navigation": {
5+
"Overview": "/overview",
6+
"Installation": "/installation",
7+
"Configuration": "/configuration",
8+
"Deploying": "/deploying",
9+
"Triggers": {
10+
"children": {
11+
"Config Trigger": "/triggers/config",
12+
"File Trigger": "/triggers/file",
13+
"Custom": "/triggers/custom"
14+
}
15+
},
16+
"Drivers": {
17+
"children": {
18+
"Filesystem": "/drivers/filesystem",
19+
"Custom": "/drivers/custom"
20+
}
21+
}
22+
}
23+
}

docs/navigation.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

docs/overview.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11

2-
# Airdrop for Laravel Overview
2+
# Airdrop for Laravel
33

4-
![Logo](/img/logo.png)
4+
Hammerstone Airdrop for Laravel is a package that speeds up your code deploys by skipping your asset build step whenever possible.
55

6-
Hammerstone Airdrop for Laravel is a package that speeds up your deploys by skipping your asset build step whenever possible.
6+
When you're deploying your code, Airdrop will calculate a hash of everything needed to build your assets: installed packages, JS/CSS files, ENV vars, etc.
7+
8+
After Airdrop has calculated a hash for these inputs, it will check to see if it has ever built this exact configuration before. If it has, it will pull down the built assets and put them in place, letting you skip the expensive build step.
9+
10+
![Flowchart](/flowchart.png){style="width: 698px"}
11+
12+
This can reduce the time your deploys and CI runs take from minutes down to just a few seconds:
13+
14+
<div class='flex justify-center my-4'>
15+
<blockquote class="twitter-tweet"><p lang="en" dir="ltr">We&#39;ve sped up our <a href="https://twitter.com/ChipperCI?ref_src=twsrc%5Etfw">@ChipperCI</a> pipeline quite a bit by not building our assets if nothing on the frontend has changed, but instead downloading them from S3 already built.<br><br>Usually takes 1-3 minutes to build the assets, we can pull them off of S3 in seconds! <a href="https://t.co/owdZOEcJwP">pic.twitter.com/owdZOEcJwP</a></p>&mdash; Aaron Francis (@aarondfrancis) <a href="https://twitter.com/aarondfrancis/status/1180161402188771328?ref_src=twsrc%5Etfw">October 4, 2019</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
16+
</div>

docs/public/flowchart.png

164 KB
Loading

0 commit comments

Comments
 (0)