Skip to content

Commit 8a6eb53

Browse files
leomp12claude
andcommitted
fix(cli): Ensure Artifact Registry repo exists before first deploy
Creates gcf-artifacts repo via gcloud if not found, preventing Cloud Build failures on new Firebase projects during cloudcommerce setup. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c001d85 commit 8a6eb53

4 files changed

Lines changed: 39 additions & 3 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
[submodule "ecomplus-stores/efacini"]
1111
path = ecomplus-stores/efacini
1212
url = git@github.com:efacini/efacini.git
13+
[submodule "ecomplus-stores/forjaestelar"]
14+
path = ecomplus-stores/forjaestelar
15+
url = git@github.com:doppelstore/forjaestelar.git

ecomplus-stores/forjaestelar

Submodule forjaestelar added at 6bd74e4

packages/cli/src/cli.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import * as dotenv from 'dotenv';
1111
import Deepmerge from '@fastify/deepmerge';
1212
import login from './login';
1313
import build, { prepareCodebases } from './build';
14-
import { siginGcloudAndSetIAM, createServiceAccountKey } from './setup-gcloud';
14+
import {
15+
ensureGcfArtifactsRepo,
16+
siginGcloudAndSetIAM,
17+
createServiceAccountKey,
18+
} from './setup-gcloud';
1519
import createGhSecrets from './setup-gh';
1620
import importFeed from './ext/import-feed';
1721

@@ -80,15 +84,18 @@ const run = async () => {
8084
const baseFirebaseConfig = JSON.parse(
8185
fs.readFileSync(joinPath(baseConfigDir, 'firebase.json'), 'utf8'),
8286
);
83-
const userRewrites: Array<Record<string, any>> | undefined = userFirebaseConfig?.hosting?.rewrites;
87+
const userRewrites: Array<Record<string, any>> | undefined = userFirebaseConfig
88+
?.hosting?.rewrites;
8489
if (Array.isArray(userRewrites) && Array.isArray(baseFirebaseConfig.hosting?.rewrites)) {
8590
const hostingRest: Record<string, any> = { ...userFirebaseConfig.hosting };
8691
delete hostingRest.rewrites;
8792
const mergedConfig = deepmerge(baseFirebaseConfig, {
8893
...userFirebaseConfig,
8994
hosting: hostingRest,
9095
});
91-
const mergedRewrites: Array<Record<string, any>> = [...baseFirebaseConfig.hosting.rewrites];
96+
const mergedRewrites: Array<Record<string, any>> = [
97+
...baseFirebaseConfig.hosting.rewrites,
98+
];
9299
userRewrites.forEach((userRewrite) => {
93100
const matchIdx = mergedRewrites.findIndex((r) => r.function === userRewrite.function);
94101
if (matchIdx >= 0) {
@@ -174,6 +181,11 @@ ECOM_STORE_ID=${storeId}
174181
);
175182

176183
if (argv.deploy !== false) {
184+
if (argv.gcloud !== false) {
185+
try {
186+
await ensureGcfArtifactsRepo(projectId!);
187+
} catch {}
188+
}
177189
await $firebase('deploy');
178190
}
179191
if (argv.commit !== false) {

packages/cli/src/setup-gcloud.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@ const checkServiceAccountExists = async (projectId: string) => {
7474
return hasServiceAccount;
7575
};
7676

77+
const ensureGcfArtifactsRepo = async (
78+
projectId: string,
79+
location = process.env.DEPLOY_REGION || 'us-east4',
80+
) => {
81+
$.verbose = true;
82+
try {
83+
await $`gcloud artifacts repositories describe gcf-artifacts \
84+
--location=${location} --project=${projectId}`;
85+
return;
86+
} catch {
87+
// repo doesn't exist
88+
}
89+
await $`gcloud artifacts repositories create gcf-artifacts \
90+
--repository-format=docker \
91+
--location=${location} \
92+
--project=${projectId} \
93+
--description=${'Cloud Functions build artifacts'}`;
94+
};
95+
7796
const siginGcloudAndSetIAM = async (projectId: string, pwd: string) => {
7897
$.verbose = true;
7998
let hasGcloud: boolean;
@@ -227,6 +246,7 @@ const createServiceAccountKey = async (projectId: string, pwd: string) => {
227246
export default siginGcloudAndSetIAM;
228247

229248
export {
249+
ensureGcfArtifactsRepo,
230250
siginGcloudAndSetIAM,
231251
createServiceAccountKey,
232252
};

0 commit comments

Comments
 (0)