From af0cb1b6fce8d0e40626b3cadd1a6e2bb4c1869f Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Mon, 13 Dec 2021 10:06:13 -0800 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=A4=AC=20This=20was=20supposed=20to?= =?UTF-8?q?=20go=20in=20the=20last=20release?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + src/commands/functions-delete.ts | 14 ++++++++++++-- src/deploy/functions/release/index.ts | 6 +++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a6ca1697a5..94a28c9a7db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ - Fixes issue when installing a Firebase Extension where secrets would be created before validation. - Fixes issue with filtering on a specific storage bucket using functions in the emulator (#3893) - Fixes check in Cloud Functions for Firebase initialization to check for API enablement before trying to enable them. (#2574) +- No longer tries to clean up function build images from Artifact Registry when Artifact Registry is not enabled diff --git a/src/commands/functions-delete.ts b/src/commands/functions-delete.ts index af2154b3e39..a5842eb1d42 100644 --- a/src/commands/functions-delete.ts +++ b/src/commands/functions-delete.ts @@ -4,11 +4,11 @@ import * as functionsConfig from "../functionsConfig"; import { Command } from "../command"; import { FirebaseError } from "../error"; import { Options } from "../options"; -import { needProjectId } from "../projectUtils"; -import { promptOnce } from "../prompt"; +import { needProjectId } from "../projectUtils"; import { promptOnce } from "../prompt"; import { reduceFlat } from "../functional"; import { requirePermissions } from "../requirePermissions"; import * as args from "../deploy/functions/args"; +import * as ensure from "../ensureApiEnabled"; import * as helper from "../deploy/functions/functionsDeployHelper"; import * as utils from "../utils"; import * as backend from "../deploy/functions/backend"; @@ -104,5 +104,15 @@ export default new Command("functions:delete [filters...]") } // Clean up image caches too + const opts: { ar?: containerCleaner.ArtifactRegistryCleaner } = {}; + const arEnabled = await ensure.check( + needProjectId(options), + "artifactregistry.googleapis.com", + "functions", + /* silent= */ true + ); + if (!arEnabled) { + opts.ar = new containerCleaner.NoopArtifactRegistryCleaner(); + } await containerCleaner.cleanupBuildImages([], allEpToDelete); }); diff --git a/src/deploy/functions/release/index.ts b/src/deploy/functions/release/index.ts index 3fa0a12d85c..1e2882eb646 100644 --- a/src/deploy/functions/release/index.ts +++ b/src/deploy/functions/release/index.ts @@ -75,7 +75,11 @@ export async function release( const deletedEndpoints = Object.values(plan) .map((r) => r.endpointsToDelete) .reduce(reduceFlat, []); - await containerCleaner.cleanupBuildImages(haveEndpoints, deletedEndpoints); + const opts: { ar?: containerCleaner.ArtifactRegistryCleaner } = {}; + if (!context.artifactRegistryEnabled) { + opts.ar = new containerCleaner.NoopArtifactRegistryCleaner(); + } + await containerCleaner.cleanupBuildImages(haveEndpoints, deletedEndpoints, opts); const allErrors = summary.results.filter((r) => r.error).map((r) => r.error) as Error[]; if (allErrors.length) { From dd28630cbba12127917a900d3b187c4a0ec06f92 Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Mon, 13 Dec 2021 10:09:30 -0800 Subject: [PATCH 2/3] Set changelist number in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94a28c9a7db..b897142ec3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ - Fixes issue when installing a Firebase Extension where secrets would be created before validation. - Fixes issue with filtering on a specific storage bucket using functions in the emulator (#3893) - Fixes check in Cloud Functions for Firebase initialization to check for API enablement before trying to enable them. (#2574) -- No longer tries to clean up function build images from Artifact Registry when Artifact Registry is not enabled +- No longer tries to clean up function build images from Artifact Registry when Artifact Registry is not enabled (#3943) From f8b3533a8ec55d3427e11344359a565a4b09c7d4 Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Mon, 13 Dec 2021 11:30:43 -0800 Subject: [PATCH 3/3] Formatter & use opts in functions-delete --- src/commands/functions-delete.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands/functions-delete.ts b/src/commands/functions-delete.ts index a5842eb1d42..a02d20b6127 100644 --- a/src/commands/functions-delete.ts +++ b/src/commands/functions-delete.ts @@ -4,7 +4,8 @@ import * as functionsConfig from "../functionsConfig"; import { Command } from "../command"; import { FirebaseError } from "../error"; import { Options } from "../options"; -import { needProjectId } from "../projectUtils"; import { promptOnce } from "../prompt"; +import { needProjectId } from "../projectUtils"; +import { promptOnce } from "../prompt"; import { reduceFlat } from "../functional"; import { requirePermissions } from "../requirePermissions"; import * as args from "../deploy/functions/args"; @@ -114,5 +115,5 @@ export default new Command("functions:delete [filters...]") if (!arEnabled) { opts.ar = new containerCleaner.NoopArtifactRegistryCleaner(); } - await containerCleaner.cleanupBuildImages([], allEpToDelete); + await containerCleaner.cleanupBuildImages([], allEpToDelete, opts); });