Skip to content

Commit

Permalink
include service name in revision for GCP cloud run
Browse files Browse the repository at this point in the history
When creating new revisions in GCP Cloud Run, the name must include
the service name as prefix. The new format for the revision name
will follow the format: <service name>-rev-<commit hash>-<random-postfix>.

i.e.  hello-rev-c4685d4b9eefbbbf33055cd7ac9a62189b1e4476-6480ecbb
  • Loading branch information
hephex committed Jun 11, 2023
1 parent c614814 commit 8ed91a3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/treb/plugins/gcp/cloudrun/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def clean_annotations(annotations: Mapping[str, str]) -> Dict[str, str]:
}


def prepare_revision_id(revision: str, timestamp: int) -> str:
def prepare_revision_id(service_name: str, revision: str, timestamp: int) -> str:
"""Generates a revision ID for a new Cloud Run service revision used to
identify a service revision.
Expand All @@ -99,8 +99,9 @@ def prepare_revision_id(revision: str, timestamp: int) -> str:
The revision ID for the new service revision.
"""
postfix = hex(timestamp)[2:].lower()
service_id = service_name.split("/")[-1]

return f"rev-{revision}-{postfix}"
return f"{service_id}-rev-{revision}-{postfix}"


@define(frozen=True, kw_only=True)
Expand Down Expand Up @@ -146,7 +147,7 @@ def run(self, ctx: Context, snapshot: None) -> CloudRunService:
previous_revision_id=prev_revision_id,
)

revision_id = prepare_revision_id(ctx.revision, int(time.time()))
revision_id = prepare_revision_id(self.service.service_name, ctx.revision, int(time.time()))

service.template.revision = revision_id
service.template.containers[0].image = self.image.tag
Expand Down

0 comments on commit 8ed91a3

Please sign in to comment.