Deploying to Kubernetes or a managed service is a well-known path. Deploying to plain virtual machines raises questions those platforms answer for you: what do you ship, and how does a VM get the new version?
Here’s the pipeline I ended up with on GCP, and the incident that taught me to look at retention rules.
The setup: GPU workloads on a Compute Engine instance group
My workload runs on GCP Compute Engine, in an instance group. Each instance runs a one-shot task that can last hours and needs a GPU. That’s why I didn’t go with a job service.
The CI is GitHub Actions. The question was: how do I make sure every instance that starts runs the latest code and configuration?
What to ship to a VM: git repository or runnable package?
The first decision is the artifact. You can clone a git repository on the VM, or install a runnable package built by the CI. I went with a package, so the VM only receives a built and versioned artifact.
Rollout strategies for virtual machines
Then comes the rollout. The usual options are:
- Restart the application on the running VMs.
- Restart the VMs.
- Build a new machine image.
In my case, the instances are one-shot. They run their task and stop. When a new instance starts, it fetches the latest version, so the rollout is simply the next boot. There’s no running fleet to update.
Docker image vs pip wheel on a VM
My first artifact was a Docker image. It worked, but I had to install and manage Docker on the VMs, which is one more dependency to maintain.
I switched to a pip wheel. A pip install is cheaper than a docker run, and it removes one level of abstraction. The code runs directly on the VM.
The GitHub Actions workflow builds the wheel and publishes it to a Python repository. A simplified version:
name: releaseon: push: branches: [main]jobs: publish: runs-on: ubuntu-latest permissions: contents: read id-token: write steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: "3.12" - uses: google-github-actions/auth@v2 with: workload_identity_provider: ${{ secrets.WIF_PROVIDER }} service_account: ${{ secrets.DEPLOY_SA }} - run: pip install build twine keyrings.google-artifactregistry-auth - run: python -m build - run: twine upload --repository-url https://europe-west1-python.pkg.dev/my-project/workers/ dist/*
On the VM side, the startup script installs the latest version and runs the task:
set -euo pipefailpip install keyrings.google-artifactregistry-authpip install --upgrade \ --index-url https://europe-west1-python.pkg.dev/my-project/workers/simple/ \ my-workermy-worker run
How a repository cleanup policy broke production
The Python repository that stored the wheels had a cleanup policy that removed the oldest versions. The same repository was used for dev and prod. Dev published new wheels all the time; production wasn’t rolled out very often.
You can guess the rest. The production wheel became one of the oldest versions, and the cleanup policy deleted it. The next time the instance group started, the instances failed in a loop trying to install the latest production version.
No deployment and no code change: production broke because of a retention rule.
How to avoid deleting your production artifact
- Use separate repositories for dev and prod, each with its own cleanup policy.
- Add a keep rule so the cleanup always leaves the latest versions in place.
- Alert on instances that fail at startup, so a boot loop doesn’t run unnoticed.
Separate repositories matter more for Python packages than for Docker images. Docker images can be protected with tag-based keep rules, but Python packages have no tags: the version number is all the cleanup policy sees.
In Artifact Registry, keep rules take precedence over delete rules. On the production repository, a policy that always keeps the last versions of the package looks like this:
[ { "name": "keep-latest", "action": { "type": "Keep" }, "mostRecentVersions": { "packageNamePrefixes": ["my-worker"], "keepCount": 10 } }, { "name": "delete-old", "action": { "type": "Delete" }, "condition": { "olderThan": "30d" } }]
gcloud artifacts repositories set-cleanup-policies workers-prod \ --location=europe-west1 \ --policy=cleanup-policy.json \ --no-dry-run
Test a new policy with --dry-run first. It logs what it would delete without deleting anything.


Leave a Reply