fix: cap generated container name to GCP Cloud Run's service-id limit#787
Open
Mohak-Agrawal wants to merge 1 commit into
Open
fix: cap generated container name to GCP Cloud Run's service-id limit#787Mohak-Agrawal wants to merge 1 commit into
Mohak-Agrawal wants to merge 1 commit into
Conversation
get_container_name() built "preswald-app-{slug}" with no length cap
before handing it to `gcloud run deploy`/Cloud Run's CreateService API
as the service name. Google Cloud Run rejects service_id values of 50
characters or more:
400 Violation in CreateServiceRequest.service_id: only lowercase,
digits, and hyphens; must begin with letter, and cannot end with
hyphen; must be less than 50 characters.
Any project slug long enough to push the prefixed name past 49
characters triggered exactly this error, surfacing as an opaque 500
during deploy with no indication of the actual cause.
Truncate the sanitized container name to 49 characters (stripping any
trailing hyphen left by the cut) so it always satisfies Cloud Run's
constraint, and add regression tests covering both a long slug (now
capped) and a short slug (unaffected).
Fixes StructuredLabs#659
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was the bug
Deploying to GCP fails with a 500, and the underlying API response is:
{"error": "400 Violation in CreateServiceRequest.service_id: only lowercase, digits, and hyphens; must begin with letter, and cannot end with hyphen; must be less than 50 characters. ..."}Root cause
get_container_name()inpreswald/deploy.pybuilds the Cloud Run service name aspreswald-app-{slug}, sanitizes the character set, and then hands it straight togcloud run deploy <container_name>/ Cloud Run'sCreateServiceAPI — with no length cap.Google Cloud Run rejects
service_idvalues of 50 characters or more. The"preswald-app-"prefix alone is 13 characters, so any project slug that pushes the combined name to 50+ characters triggers exactly the quoted violation. This surfaces to the user as an opaque 500 during deploy, with the real cause several layers removed from the actual GCP validation error.What the fix does
Truncates the sanitized container name to 49 characters (Cloud Run's limit is "less than 50"), stripping any trailing hyphen left by the cut. Short slugs are completely unaffected.
How to reproduce / verify
Added
tests/test_deploy.pywith regression tests covering:zwbq, matching the slug format in the original report), asserting it's byte-for-byte unaffected by the changeNote
The report in #659 was against the hosted
app.preswald.comdeploy flow rather than the localpreswald deploy --target gcppath, and I don't have visibility into that hosted backend's source. However, the error message is GCP Cloud Run's literalCreateServiceRequest.service_idvalidation response, and this is the only place in the OSS codebase that constructs a Cloud Run service name from a project slug with no length bound — the exact same violation reproduces from this code with a sufficiently long slug. If the hosted backend uses different naming logic, happy to adjust scope once that's clarified.Fixes #659