ArtifactCleanupService class
Manages Artifact Registry repositories and Cloud Run revision retention.
The orchestrator (and the generated script_deploy.sh) use this to
keep production GCP usage bounded after every deploy:
- Artifact Registry — creates the docker repository if missing,
then applies a JSON cleanup policy (keep N most-recent versions
tagged
latest/prod, delete everything else older than D days). - Cloud Run — keeps the last N revisions of a service and prunes everything older. Revisions currently routing traffic are always preserved.
All operations are idempotent: re-running has no effect when the
repository already exists / the policy is unchanged / no revisions need
pruning. Public methods never throw — failures are returned via the
…Result types so the orchestrator can surface them in the wizard.
Constructors
- ArtifactCleanupService(String projectId, {String defaultRegion = 'us-central1', ProcessRunner? runner})
Properties
- defaultRegion → String
-
Default region for repository / Cloud Run operations.
Callers can override per-call (e.g.
us-east1).final - hashCode → int
-
The hash code for this object.
no setterinherited
- projectId → String
-
GCP / Firebase project ID.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
applyCleanupPolicies(
{required String repository, String? region, int keepRecent = 5, int deleteOlderDays = 30}) → Future< CleanupPolicyResult> -
Apply a cleanup policy to
repositorythat keeps thekeepRecentmost-recent versions taggedlatest/prodand deletes everything older thandeleteOlderDaysdays. -
capCloudRunRevisions(
{required String service, String? region, int keepRevisions = 3}) → Future< RevisionPruneResult> -
Cap Cloud Run revisions of
serviceto thekeepRevisionsmost recent ones. Revisions currently routing traffic are always preserved. -
ensureRepository(
{required String repository, String? region, String repositoryFormat = 'docker'}) → Future< RepositoryEnsureResult> -
Ensure Artifact Registry
repositoryexists inregion. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
buildPolicy(
{required int keepRecent, required int deleteOlderDays}) → List< Map< String, Object?> > -
Build the policy structure used by
set-cleanup-policies. -
parseRevisionList(
String stdout) → List< String> ? -
Parse
gcloud run revisions list --format=jsonoutput into the list of revision IDs (e.g.arcane-server-00042-xyz). -
parseTrafficRevisions(
String stdout) → Set< String> -
Parse
gcloud run services describe --format=jsonoutput into the set of revision IDs that currently route traffic.