2.4.0 • Published 1 month ago

nx-remotecache-gcp v2.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

npm package link

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 🙌

Compatability

NxRemote Cache
>= 16.9.0>= 2.0.2
< 16.9.0< 1.2.1

Setup

  1. Add Nx to your workspace guide
  2. Install this package as dev dependency.
    npm install --save-dev nx-remotecache-gcp
  3. Authenticate to Google Cloud The user authenticating must have read/write access to the bucket as well as storage.buckets.get permission

    1. Locally using google cloud CLI using gcloud auth
    2. For Github actions use google-github-actions/auth
    3. You may provide NX_GOOGLE_APPLICATION_CREDENTIALS_PATH and point to your own Google service account credentials.
  4. Create a Google bucket to store the cache in

Creating a service account with the right permissions

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/<nx_cache_bucket.name>\")

  3. Add Object Admin to the bucket from the page of the Bucket

Configuration

Note: Environment variables have precedence over configured variables

Additionally all parameters defined in nx-remotecache-custom are valid here

ParameterDescriptionEnvironment Variable / .envnx.json
Google ProjectProject Name in which the Bucket residesNXCACHE_GCP_PROJECTgoogleProject
Bucket NameBucket name in which the cache will be storedNXCACHE_GCP_BUCKET_NAMEbucketName
Read from Remote CacheAllow reading from the the remote cacheNXCACHE_READread (true/false)
Write to Remote CacheAllow writing to the the remote cacheNXCACHE_WRITEwrite (true/false)
Credentials path (optional)Provide your own google application credentialsNX_GOOGLE_APPLICATION_CREDENTIALS_PATHgoogleApplicationCredentialsPath
{
   "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"
            ]
         }
      }
   }
}

Run it 🚀

Running tasks should now show the storage or retrieval from the remote cache:

------------------------------------------------------------------------------
Remote cache hit: Google Cloud Bucket
File: 1fb268062785d739b5a43c1e4032fd7731c6080e2249e87a00e568b3c41acf9c.tar.gz
------------------------------------------------------------------------------
2.3.2

1 month ago

2.4.0

1 month ago

2.3.1

1 month ago

2.3.3

1 month ago

2.3.0

4 months ago

2.2.0

4 months ago

2.1.1

6 months ago

2.0.2

6 months ago

2.1.0

6 months ago

2.0.1

6 months ago

2.0.0

6 months ago

1.2.1

8 months ago

1.2.0

10 months ago

1.1.0

10 months ago

1.0.0

11 months ago

0.0.2

1 year ago