DEV Community

cometa-kaito
cometa-kaito

Posted on Originally published at tech.rebounder.jp

Cloud Run Jobs Freeze Their Image

Check this first

Read the image the job actually runs.

gcloud run jobs describe <job> --region=asia-northeast1 \
  --format="value(spec.template.spec.template.spec.containers[0].image)"
Enter fullscreen mode Exit fullscreen mode

Then check whether your fix is contained in it.

git merge-base --is-ancestor <fix-commit> <image-sha> && echo "contained" || echo "not contained"
Enter fullscreen mode Exit fullscreen mode

If it is not contained, re-running changes nothing. Worse, the job may overwrite data again using the old behaviour.

What is actually happening

The image is pinned in the job definition. When the definition lives in infrastructure-as-code, the tag is declared as a variable, and the job keeps running the old code until that tag is bumped and applied.

local fix → commit → [ wall ] → job execution
                       ↑ image is still the old one
Enter fullscreen mode Exit fullscreen mode

The awkward part is that the run succeeds. Nothing appears in the logs. All you are left with is "I ran it and it did not take effect".

Two ways out

A. Override the environment variable at execution time

If the code reads process.env.X ?? default, you can swap the value without touching the image.

gcloud run jobs execute <job> --region=asia-northeast1 \
  --update-env-vars=KEY=value --wait
Enter fullscreen mode Exit fullscreen mode

No build, no apply, so this is the fast path. But it applies to that execution only — the job definition is unchanged, and the old default comes back the next time the flag is omitted.

B. Update the image (the real fix)

Build, bump the tag, apply. The exact commands depend on your setup, but you cannot skip the tag bump.

Preventing a repeat

After this incident we put the sha check at the very top of the runbook. The root cause was that running the job without checking was possible at all, so changing the order of the steps is what actually helps.

We also wrote down, in the runbook, that the environment-variable override is a stopgap. Because it is fast, it is easy to walk away believing the problem is fixed.


Originally published at tech.rebounder.jp.

Top comments (1)

Collapse
 
lycore profile image
Lycore Development •

The merge-base --is-ancestor check is a nice, cheap way to answer "does this job even contain my fix". Putting it at the top of the runbook is the right call, since the run itself succeeds quietly. One small idea: log or print the image digest at job start, so every execution's output records which code it actually ran.