From ff171efde60f7de446ea7afafbc33091f19013d6 Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Mon, 13 Dec 2021 12:07:11 -0800 Subject: [PATCH] Do not try to clean up AR images if AR is not enabled (#3943) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🤬 This was supposed to go in the last release * Set changelist number in changelog * Formatter & use opts in functions-delete --- CHANGELOG.md | 1 + src/commands/functions-delete.ts | 13 ++++++++++++- src/deploy/functions/release/index.ts | 6 +++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a6ca1697a5..b897142ec3b 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 (#3943) diff --git a/src/commands/functions-delete.ts b/src/commands/functions-delete.ts index af2154b3e39..a02d20b6127 100644 --- a/src/commands/functions-delete.ts +++ b/src/commands/functions-delete.ts @@ -9,6 +9,7 @@ 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 +105,15 @@ export default new Command("functions:delete [filters...]") } // Clean up image caches too - await containerCleaner.cleanupBuildImages([], allEpToDelete); + 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, opts); }); 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) {