2.2.0 • Published 3 months ago

nx-remotecache-gcs v2.2.0

Weekly downloads
75
License
MIT
Repository
github
Last release
3 months ago

nx-remotecache-gcs

A task runner for Nx that uses a Google Cloud Storage bucket as a remote cache, so all team members and CI servers can share a single cache. The concept and benefits of computation caching are explained in the NX documentation.

setup

npm install --save-dev nx-remotecache-gcs

create a Google Cloud Storage bucket. Since this is only a cache, there is no need for a dual- or multi-region bucket, so choose a single location near you.

gsutil mb -p [PROJECT_ID] -l [BUCKET_LOCATION] -b on gs://[BUCKET_NAME]/

setup a lifecycle rule for your storage bucket to automatically delete old files. If you want to use our suggested auto-delete-after-30-days rule, you can simply use the json that is included:

gsutil lifecycle set node_modules/nx-remotecache-gcs/lifecycle.json gs://[BUCKET_NAME]

by default all viewers, editors and owners of your Google Cloud project can read and/or write to the bucket. You could also restrict who can read and write the bucket to only allow certain users or (build server) service accounts.

finally, add tasksRunnerOptions in your nx.json file

{
    "projects": {
        ...
    },
    "tasksRunnerOptions": {
        "default": {
            "runner": "nx-remotecache-gcs",
            "options": {
                "bucket": "gs://NAME-OF-YOUR-STORAGE-BUCKET",
                "cacheableOperations": [
                    "build",
                    "test",
                    "lint",
                    "e2e"
                ]
            }
        }
    }
}

run a build and see if files end up in your cache storage bucket:

nx run-many --target=build --all

Options

Use NX_SKIP_REMOTE_CACHE environment variable for temporary disabling remote cache, while keeping the local cache in tact. This can be beneficial for some CI cases you want to run without using the remote cache.

export NX_SKIP_REMOTE_CACHE=true
nx run project:target
NX_SKIP_REMOTE_CACHE=true nx run project:target