Skip to main content
Each job with an InstaBox label runs on a fresh machine, so a job that installs its packages downloads them again every time. You can keep the packages between jobs in two ways. The actions/cache action restores a folder at the start of a job and saves it at the end, and it works on InstaBox as it does on GitHub’s runners. A snapshot has the packages on the machine’s disk when the job starts, so its install step has little left to do. Its machine is not started ahead of the job, though, so the job waits for it to start. Start with actions/cache. Add a snapshot when the restore itself is slow, or when the job needs tools that take minutes to install.

Cache packages with actions/cache

Add the actions/cache step before the step that installs your packages. The key names one version of the cache, so make it change when your lockfile changes. A job that finds its key gets the folder back, and a job that does not find it installs as usual and saves the folder when the job ends. On an InstaBox machine, ~ is /data/home. A ~/ path that you cache on ubuntu-latest restores to the same place on InstaBox, so a workflow needs no change when you move it.

npm

Cache npm’s download folder, and let npm ci build node_modules from it.
With restore-keys, a job whose lockfile changed starts from the newest older cache, and downloads only the packages that are new.

pip

Cache pip’s download folder.

Cargo

Cache the registry and the build output together, because compiling the dependencies usually takes longer than downloading them.

Go

Cache the module folder.
GitHub stores these caches, so GitHub’s limits on cache size and age apply. On a paid plan, a job’s machine uploads faster than other machines do, which shortens the save of a large cache.

Start jobs with the packages already on disk

A job that starts from a snapshot has your repository, toolchain, and package folders on its disk when it begins. Its machine starts when the job arrives instead of ahead of it, so the job waits for that start (What to know). Prepare a ci machine, install and build once, save it, and name the snapshot in runs-on. Advanced: custom setup has the steps.
Put the package folders in the snapshot: ~/.npm, ~/.cache/pip, ~/.cargo/registry, or ~/go/pkg/mod. For a compiled language, also build the project once before you save, so the build output is there too. A snapshot holds the whole machine, not one folder. Each job gets its own copy, and a job cannot change the snapshot. The packages that a job downloads are gone when the job ends.

Use both together

You can keep actions/cache in a job that starts from a snapshot. The snapshot holds the packages from the day you saved it. Use a key from your lockfile as above: after the lockfile changes, the first job saves a cache with the newer packages, and later jobs restore it, so their install has little left to download. The cache step downloads its whole folder whenever it finds the key, so this helps most when the snapshot is old.

Save the snapshot again

Save the snapshot again when your dependencies have moved far from it, and at least once a month. Refresh the snapshot has the steps.

Limits

Jobs can start from a snapshot only in private repositories with Run workflows from fork pull requests turned off. Setting one up needs a paid plan (Advanced: custom setup). When a job that names a snapshot is refused lists the other reasons.
Keep tokens, SSH keys, and .env files out of a snapshot, because any workflow on a branch of a linked repository can name it. A cache that actions/cache saves follows GitHub’s rules for which branches can read it.
A machine’s disk is its own. Two jobs share packages only through actions/cache or by starting from the same snapshot.

CI

Run GitHub Actions jobs on InstaBox, and start them from a snapshot.

Snapshots

Save a machine and start new machines from it.