I'd like to use pnpm in my CI cloudbuild pipeline. But, does that mean that i have to install it in every step? Since steps in cloudbuild are indepedent from each other. What are the alternatives?
steps:
- id: 'Node packages installing'
name: ${_NODE_VERSION}
entrypoint: 'bash'
args:
- "-c"
- |
npm install -g ${_PNPM_VERSION}
pnpm install
- name: ${_NODE_VERSION}
entrypoint: 'bash'
args:
- "-c"
- |
npm install -g ${_PNPM_VERSION}
pnpm run test
Aside from @abchev’s answer that you need to persist the package as volumes. The most efficient approach is to use a custom Docker image that includes pnpm. With this approach, it ensures that pnpm is already available in your CI pipeline, and you don’t need to install it in every step.
Here’s a sample step-by-step on how you do it:
Create a Custom Docker Image with PNPM, start with a Node.js base image and install PNPM globally.
FROM node:${_NODE_VERSION}
RUN npm install -g ${_PNPM_VERSION}
Build and push the custom image to a registry (e.g., Google Container Registry):
docker build -t gcr.io/PROJECT_ID/custom-node-pnpm docker push gcr.io/PROJECT_ID/custom-node-pnpm
Update Cloud Build Configuration. Reference the custom image in your cloudbuild.yaml file to avoid repeated PNPM installations:
steps:
- id: 'Node packages installing'
name: gcr.io/PROJECT_ID/pnpm-image # Use the custom Docker image
entrypoint: 'bash'
args:
- "-c"
- |
pnpm install # Install dependencies using pnpm
- id: 'Run tests'
name: gcr.io/PROJECT_ID/pnpm-image # Reuse the same image
entrypoint: 'bash'
args:
- "-c"
- |
pnpm run test # Run your tests