|
11 | 11 | A GitHub Action that helps persist state written to disk across jobs. Each sticky disk is hot-loaded into the runner and mounted at the specified path. |
12 | 12 | The sticky disk is formatted as an ext4 filesystem. |
13 | 13 |
|
14 | | -A common use case of this action is to cache build artifacts such as NPM packages (egs: node_modules, yarn.lock, etc) across job runs. |
15 | | - |
16 | 14 | ## Usage |
17 | 15 |
|
18 | 16 | ```yaml |
|
28 | 26 | ``` |
29 | 27 |
|
30 | 28 | Each sticky disk is uniquely identified by a key. The sticky disk will be mounted at the specified path. Once the job completes, the sticky disk will be unmounted and committed for future invocations. At the moment, customers can use up to 10 sticky disks in a single GitHub Action job. |
| 29 | +
|
| 30 | +# Use Cases |
| 31 | +
|
| 32 | +## Bazel Build Caching |
| 33 | +
|
| 34 | +Bazel's remote cache can significantly improve build times, but uploading and downloading cached artifacts can still be a bottleneck. Using sticky disks with Blacksmith runners provides near-instant access to your Bazel caches as they are bind mounted into your runners on demand. Our [`useblacksmith/setup-bazel@v2`](https://github.com/useblacksmith/setup-bazel) action is a zero-confg way to use sticky disks to store the disk, repository, and external cache. |
| 35 | + |
| 36 | +```yaml |
| 37 | +jobs: |
| 38 | + build: |
| 39 | + runs-on: blacksmith |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@v4 |
| 42 | + |
| 43 | + - name: Setup Bazel |
| 44 | + uses: useblacksmith/setup-bazel@v2 |
| 45 | + with: |
| 46 | + version: '6.x' |
| 47 | + |
| 48 | + - name: Build |
| 49 | + run: | |
| 50 | + bazel build //... |
| 51 | +``` |
| 52 | + |
| 53 | +### Cache Performance Comparison |
| 54 | + |
| 55 | +| Caching Solution | Cache Size | Average Download Speed | Time to Access | |
| 56 | +|-----------------|------------|----------------|----------------| |
| 57 | +| GitHub Actions Cache | 6GB | 70 Mbps | ~11.5 minutes | |
| 58 | +| Blacksmith Cache | 6GB | 400 Mbps | ~2 minutes | |
| 59 | +| Sticky Disks | 6GB | N/A | 3 seconds | |
| 60 | + |
| 61 | + |
| 62 | +## NPM Package Caching |
| 63 | + |
| 64 | +Node.js projects can have extensive dependency trees, leading to large `node_modules` directories. Sticky disks provide persistent, high-performance storage for your NPM packages. |
| 65 | + |
| 66 | +```yaml |
| 67 | +jobs: |
| 68 | + build: |
| 69 | + runs-on: blacksmith |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + |
| 73 | + - name: Setup Node.js |
| 74 | + uses: actions/setup-node@v4 |
| 75 | + with: |
| 76 | + node-version: '18.x' |
| 77 | + |
| 78 | + - name: Mount NPM Cache |
| 79 | + uses: useblacksmith/stickydisk@v1 |
| 80 | + with: |
| 81 | + key: ${{ github.repository }}-npm-cache |
| 82 | + path: ~/.npm |
| 83 | + |
| 84 | + - name: Mount node_modules |
| 85 | + uses: useblacksmith/stickydisk@v1 |
| 86 | + with: |
| 87 | + key: ${{ github.repository }}-node-modules |
| 88 | + path: ./node_modules |
| 89 | + |
| 90 | + - name: Install Dependencies |
| 91 | + run: npm ci |
| 92 | +
|
| 93 | + - name: Build |
| 94 | + run: npm run build |
| 95 | +``` |
| 96 | + |
| 97 | +# Architecture |
| 98 | + |
| 99 | +<p align="center"> |
| 100 | + <picture> |
| 101 | + <!-- Dark mode --> |
| 102 | + <source media="(prefers-color-scheme: dark)" srcset="./arch-dark-mode.png" width="300"> |
| 103 | + <!-- Light mode --> |
| 104 | + <source media="(prefers-color-scheme: light)" srcset="./arch-light.png" width="300"> |
| 105 | + <img alt="Blacksmith Logo" src="./arch-light.png" width="300"> |
| 106 | + </picture> |
| 107 | +</p> |
0 commit comments