@nx/powerpack-gcs-cache

The @nx/powerpack-gcs-cache plugin enables you to use Google Cloud Storage instead of Nx Cloud to host your remote cache.

This plugin will enable the remote cache for your Nx workspace, but does not provide any of the other features of Nx Cloud. If you want to leverage distributed task execution, re-running flaky tasks or automatically splitting tasks, you'll need to connect to Nx Cloud and use Nx Replay instead.

Potential Cache Poisoning

Using your own Google Cloud Storage account to host the remote cache opens you up to the possibility of cache poisoning. To avoid this, use Nx Replay.

This plugin requires an active Nx Powerpack license

In order to use @nx/powerpack-gcs-cache, you need to have an active Powerpack license. If you don't have a license or it has expired, your cache will no longer be shared and each machine will use its local cache.

Set Up @nx/powerpack-gcs-cache

1. Install the Package

  1. Activate Powerpack if you haven't already
  2. Install the package

โฏ

nx add @nx/powerpack-gcs-cache

2. Authenticate with Google Cloud

There are several ways to authenticate with Google Cloud Storage, but the method recommended by Google is to use Workload Identity Federation, like this:

.github/workflows/ci.yml
1name: CI 2... 3permissions: 4 id-token: write 5 ... 6 7jobs: 8 main: 9 env: 10 NX_POWERPACK_LICENSE: ${{ secrets.NX_POWERPACK_LICENSE }} 11 runs-on: ubuntu-latest 12 steps: 13 ... 14 15 - id: 'auth' 16 name: 'Authenticate to Google Cloud' 17 uses: 'google-github-actions/auth@v2' 18 with: 19 token_format: 'access_token' 20 workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' 21 service_account: 'my-service-account@my-project.iam.gserviceaccount.com' 22 23 - name: 'Set up Cloud SDK' 24 uses: 'google-github-actions/setup-gcloud@v2' 25 with: 26 version: '>= 363.0.0' 27 28 ... 29 30 - run: pnpm exec nx affected -t lint test build 31

Note: Any authentication method that sets up the Application Default Credentials will enable the plugin to work.

3. Configure the Nx Cache to Use Google Cloud Storage

Finally, you need to configure your Nx cache in the nx.json file. The bucket that you specify needs to already exist - Nx doesn't create it for you.

nx.json
1{ 2 "gcs": { 3 "bucket": "my-bucket" 4 } 5} 6
PropertyDescription
bucketThe name of the bucket to use

Package reference

Here is a list of all the executors and generators available from this package.

Guides

Executors

Generators