Remote caching for @nrwl/nx using Google Cloud Buckets
npm install nx-remotecache-gcp
A task runner for @nrwl/nx that uses a Google Cloud Storage bucket as a remote cache.
This enables all team members and CI servers to share a single cache.
The concept and benefits of Cache Task Results are explained in the
Nx documentation.
This package was built with nx-remotecache-custom 🙌
| Nx | Remote Cache |
|-----------|--------------|
| >= 16.9.0 | >= 2.0.2 |
| < 16.9.0 | < 1.2.1 |
1. Add Nx to your workspace guide
2. Install this package as dev dependency.
``shell`
npm install --save-dev nx-remotecache-gcp
storage.buckets.get
3. Authenticate to Google Cloud
The user authenticating must have read/write access to the bucket as well as permissiongcloud auth
1. Locally using google cloud CLI using NX_GOOGLE_APPLICATION_CREDENTIALS_PATH
2. For Github actions use google-github-actions/auth
3. You may provide and point to your own Google service account credentials.
4. Create a Google bucket to store the cache in
To authenticate on CI it is recommended to create a service account that only has the required
permissions.
1. Create a custom role with only the storage.buckets.get permission
2. Create a service account with the custom Role and limit it only manage the nx-cache bucket using
this CEL Expression resource.name.startsWith(\"projects/_/buckets/
3. Add Object Admin to the bucket from the page of the Bucket
Note: Environment variables have precedence over configured variables
Additionally all parameters defined in nx-remotecache-custom are valid here
| Parameter | Description | Environment Variable / .env | nx.json |NXCACHE_GCP_PROJECT
|-----------------------------|-------------------------------------------------|------------------------------------------|------------------------------------|
| Google Project | Project Name in which the Bucket resides | | googleProject |NXCACHE_GCP_BUCKET_NAME
| Bucket Name | Bucket name in which the cache will be stored | | bucketName |NXCACHE_READ
| Read from Remote Cache | Allow reading from the the remote cache | | read (true/false) |NXCACHE_WRITE
| Write to Remote Cache | Allow writing to the the remote cache | | write (true/false) |NX_GOOGLE_APPLICATION_CREDENTIALS_PATH
| Credentials path (optional) | Provide your own google application credentials | | googleApplicationCredentialsPath |
`json`
{
"tasksRunnerOptions": {
"default": {
"runner": "nx-remotecache-gcp",
"options": {
"googleProject": "my-google-project-id",
"bucketName": "my-nx-cache-bucket",
"read": true,
"write": false,
"cacheableOperations": [
"build",
"test",
"lint",
"e2e"
]
}
}
}
}
Running tasks should now show the storage or retrieval from the remote cache:
```
------------------------------------------------------------------------------
Remote cache hit: Google Cloud Bucket
File: 1fb268062785d739b5a43c1e4032fd7731c6080e2249e87a00e568b3c41acf9c.tar.gz
------------------------------------------------------------------------------