Join us for GraphQL Summit, October 10-12 in San Diego. Use promo code ODYSSEY for $400 off your pass.
Launch GraphOS Studio

Optimizing Custom Apollo Router Builds


While running the Apollo in production has great performance, this comes at the cost of increased build time and higher system requirements when compiling from source.

Building the Apollo including custom plugins from source is a memory-expensive process, and as such it’s not suited for all build environments.

Some cloud build pipelines such as Google Cloud Build, will require changes to the default build configuration in order to increase the memory and CPU capacity of the build worker pool.

The will also download a large collection of dependencies during the build process each build by default. We can use Kaniko to cache intermediate build layers.

In this example for Google Cloud Build, we have replaced the standard docker container image, with This is all that's needed to enable caching of the intermediate build steps. Each step will be pushed to the destination container repo as soon as each layer is built, so even failed builds will contribute to increased build speeds as successful layers are cached.

We also changed the default options.machineType value to E2_HIGHCPU_8, this is because the default worker pool doesn’t have the CPU or memory resources necessary to compile the .

- id: Build Router
name: ''
- '--cache=true'
- '--dockerfile=$_DOCKERFILE'
- '--context=dir://$_IMAGE_NAME'
- >-
- id: Deploy Router
name: ''
entrypoint: gcloud
- run
- services
- update
- '--platform=managed'
- '--region=$_DEPLOY_REGION'
- '--quiet'
machineType: E2_HIGHCPU_8
_DOCKERFILE: custom-router/Dockerfile
_IMAGE_NAME: custom-router
_SERVICE_NAME: apollo-router
_DEPLOY_REGION: northamerica-northeast1
_PLATFORM: managed
Edit on GitHubEditForumsDiscord