SIGTERM.
Prerequisites
- The gcloud CLI, signed in to a project with billing enabled.
- An Archil disk, ideally in the Archil region closest to your Cloud Run region, such as
gcp-us-central1forus-central1. See Region availability.
disk CLI. The output includes the disk ID and a one-time mount token, which grants access to this disk only:
Set up the project
Enable the APIs the steps below use. Cloud Run builds and runs the service as the Compute Engine default service account unless you choose another, so give that account permission to build the image, and store the mount token in Secret Manager where only that account can read it, rather than in the service’s environment variables:Build the service
The image needs thearchil client and your app:
Dockerfile
server.py mounts the disk before it starts serving, appends a line to a file on the disk for every request, and unmounts the disk when Cloud Run sends SIGTERM. It mounts with --conditional because more than one instance can have the disk mounted at once: Cloud Run scales out under load, and a new revision starts before the old one stops.
server.py
--execution-environment gen2 selects the environment that supports FUSE:
Use the disk
Request the service with your own identity token:How the disk behaves on Cloud Run
Mount with--conditional. Every instance of every revision can then read and write anywhere on the disk. For faster writes to a directory only one instance uses, check it out with archil checkout; see Sharing disks.
Unmount on SIGTERM. Unmounting sends the client’s buffered writes to the disk. Cloud Run sends SIGTERM before it shuts an instance down, and waits 10 seconds before stopping it.
Clean up
Delete the service, the secret, the service’s image, and the disk once you no longer need them:Next steps
- Python SDK: read, write, and search the disk without mounting it.
- Sharing disks: how conditional mode and checkouts work.
archilCLI reference: everyarchil mountoption.