Skip to content

Fix GCF V2 Artifact Registry cleanup #8318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 17, 2025

Conversation

chalosalvador
Copy link
Member

@chalosalvador chalosalvador commented Mar 13, 2025

Description

Updates the artifact name encoding logic to match GCF V2's format when cleaning up function artifacts from Artifact Registry.

The artifact names follow this schema:

{encoded_project}__{encoded_region}__{encoded_function}

Each part is encoded separately with these rules:

  • Underscores are doubled ("_" -> "__")
  • Dashes are doubled ("-" -> "--")
  • A leading capital letter is replaced with <lower><dash><lower>
  • Other capital letters are replaced with <underscore><lower>

Changes

  • Updated ArtifactRegistryCleaner.packagePath() to encode each part separately
  • Added comprehensive test cases for different encoding scenarios
  • Improved documentation with schema and examples
  • Fixed integration tests to expect the correct artifact name format

Example

Input:
- project: "my-cool-project"
- region: "us-central1"
- functionId: "myFunction"

Output: "my--cool--project__us--central1__my_function"

Testing

  • Added test cases for:
    • Project IDs with dashes
    • Project IDs with underscores
    • Regions with dashes
    • Function IDs with capital letters
  • Verified against actual GCF V2 artifact names in Artifact Registry

Related Issues

Fixes #8164

Scenarios Tested

  • Deploy a Cloud function with firebase deploy --only functions
  • Deploy a hosting with a Cloud Function for SSR firebase deploy --only hosting
  • Deploy a v1 function
const functions = require('firebase-functions/v1');
const logger = require("firebase-functions/logger");

// Create and deploy your first functions
// https://firebase.google.com/docs/functions/get-started

exports.helloWorldChaloTestV1 = functions.https.onRequest((request, response) => {
  logger.info("Hello logs!", {structuredData: true});
  response.send("Hello from Firebase Cloud Functions v1!!");
});
  • Deploy a v2 function
const {onRequest} = require("firebase-functions/v2/https");

// Create and deploy your first functions
// https://firebase.google.com/docs/functions/get-started

exports.helloWorldChaloTestV2 = onRequest((request, response) => {
  logger.info("Hello logs!", {structuredData: true});
  response.send("Hello from Firebase, Chalo!!");
});

Both cases now show the 200 http status code instead of 404 when cleaning up artifacts:

[debug] [2025-03-13T10:43:44.616Z] <<< [apiv2][status] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-cool-project/locations/europe-west1/repositories/gcf-artifacts/packages/my--cool--project__us--central1__ssrfunction 200
[debug] [2025-03-13T10:43:44.616Z] <<< [apiv2][body] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-cool-project/locations/europe-west1/repositories/gcf-artifacts/packages/my--cool--project__us--central1__ssrfunction {"name":"projects/my-cool-projectd/locations/europe-west1/operations/6f384a75-e68d-4654-9758-1687fd6e23ee","metadata":{"@type":"type.googleapis.com/google.devtools.artifactregistry.v1beta2.OperationMetadata"}}

@chalosalvador chalosalvador enabled auto-merge (squash) March 17, 2025 21:09
@chalosalvador chalosalvador merged commit 61afeba into master Mar 17, 2025
53 of 55 checks passed
@chalosalvador chalosalvador deleted the chalosalvador/fix-gcf-cleanup-artifacts-name branch March 18, 2025 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

webframeworks deploy fails (404) by attempting delete of artifact
3 participants