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.
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.
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
- Activate Powerpack if you haven't already
- 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:
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.
1{
2 "gcs": {
3 "bucket": "my-bucket"
4 }
5}
6
Property | Description |
---|---|
bucket | The name of the bucket to use |