@catladder/cli 1.43.0 → 1.44.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apps/cli/commands/project/setup/setupCloudRun.d.ts +3 -0
- package/dist/apps/cli/commands/project/setup/setupCloudRun.js +92 -0
- package/dist/apps/cli/commands/project/setup/setupCloudRun.js.map +1 -0
- package/dist/apps/cli/commands/project/setup/setupContext.js +12 -5
- package/dist/apps/cli/commands/project/setup/setupContext.js.map +1 -1
- package/dist/apps/cli/commands/shared/index.js.map +1 -1
- package/dist/bundles/catenv/index.js +3 -3
- package/dist/bundles/cli/index.js +2 -2
- package/dist/gcloud/artifactsRegistry.d.ts +5 -0
- package/dist/gcloud/artifactsRegistry.js +59 -0
- package/dist/gcloud/artifactsRegistry.js.map +1 -0
- package/dist/gcloud/cloudRun/getCloudRunDomainSuffix.d.ts +2 -0
- package/dist/gcloud/cloudRun/getCloudRunDomainSuffix.js +67 -0
- package/dist/gcloud/cloudRun/getCloudRunDomainSuffix.js.map +1 -0
- package/dist/gcloud/enableServices.d.ts +3 -0
- package/dist/gcloud/enableServices.js +63 -0
- package/dist/gcloud/enableServices.js.map +1 -0
- package/dist/gcloud/serviceAccounts.d.ts +12 -0
- package/dist/gcloud/serviceAccounts.js +144 -0
- package/dist/gcloud/serviceAccounts.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/gitlab.js +1 -1
- package/dist/utils/gitlab.js.map +1 -1
- package/package.json +2 -2
- package/src/apps/cli/commands/project/setup/setupCloudRun.ts +69 -0
- package/src/apps/cli/commands/project/setup/setupContext.ts +4 -1
- package/src/apps/cli/commands/shared/index.ts +0 -4
- package/src/gcloud/artifactsRegistry.ts +16 -0
- package/src/gcloud/cloudRun/getCloudRunDomainSuffix.ts +34 -0
- package/src/gcloud/enableServices.ts +14 -0
- package/src/gcloud/serviceAccounts.ts +101 -0
- package/src/utils/gitlab.ts +2 -2
package/dist/utils/gitlab.js
CHANGED
|
@@ -60,8 +60,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
60
60
|
};
|
|
61
61
|
exports.__esModule = true;
|
|
62
62
|
exports.upsertAllVariables = exports.getVariableValueByRawName = exports.getAllVariables = exports.getProjectInfo = exports.doGitlabRequest = exports.getGitlabToken = exports.setupGitlabToken = exports.hasGitlabToken = void 0;
|
|
63
|
-
var child_process_promise_1 = require("child-process-promise");
|
|
64
63
|
var pipeline_1 = require("@catladder/pipeline");
|
|
64
|
+
var child_process_promise_1 = require("child-process-promise");
|
|
65
65
|
var lodash_1 = require("lodash");
|
|
66
66
|
var memoizee_1 = __importDefault(require("memoizee"));
|
|
67
67
|
var node_fetch_1 = __importDefault(require("node-fetch"));
|
package/dist/utils/gitlab.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitlab.js","sourceRoot":"","sources":["../../src/utils/gitlab.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAA6C;AAC7C,
|
|
1
|
+
{"version":3,"file":"gitlab.js","sourceRoot":"","sources":["../../src/utils/gitlab.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAuD;AACvD,+DAA6C;AAC7C,iCAAuC;AACvC,sDAAgC;AAChC,0DAA+B;AAC/B,8CAAwB;AAExB,6CAA4E;AAE5E,IAAM,SAAS,GAAG,8BAA8B,CAAC;AAE1C,IAAM,cAAc,GAAG;;gBAAY,qBAAM,IAAA,2BAAa,EAAC,SAAS,CAAC,EAAA;gBAA9B,sBAAA,SAA8B,EAAA;;SAAA,CAAC;AAA5D,QAAA,cAAc,kBAA8C;AAClE,IAAM,gBAAgB,GAAG,UAAO,MAAuB;;;;;gBAC5D,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC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zB,CAAC;AA1CW,QAAA,kBAAkB,sBA0C7B"}
|
package/package.json
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"node": ">=12.0.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@catladder/pipeline": "1.
|
|
27
|
+
"@catladder/pipeline": "1.44.1",
|
|
28
28
|
"@kubernetes/client-node": "^0.16.2",
|
|
29
29
|
"@tsconfig/node14": "^1.0.1",
|
|
30
30
|
"@types/common-tags": "^1.8.0",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"update-notifier": "^5",
|
|
59
59
|
"vorpal": "^1.12.0"
|
|
60
60
|
},
|
|
61
|
-
"version": "1.
|
|
61
|
+
"version": "1.44.1"
|
|
62
62
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Context } from "@catladder/pipeline";
|
|
2
|
+
import {
|
|
3
|
+
GCLOUD_DEPLOY_CREDENTIALS_KEY,
|
|
4
|
+
GCLOUD_RUN_CANONICAL_HOST_SUFFIX,
|
|
5
|
+
isOfDeployType,
|
|
6
|
+
} from "@catladder/pipeline";
|
|
7
|
+
|
|
8
|
+
import type { CommandInstance } from "vorpal";
|
|
9
|
+
import { upsertGcloudArtifactsRegistry } from "../../../../../gcloud/artifactsRegistry";
|
|
10
|
+
import { getCloudRunDomainSuffix } from "../../../../../gcloud/cloudRun/getCloudRunDomainSuffix";
|
|
11
|
+
import { enableGCloudServices } from "../../../../../gcloud/enableServices";
|
|
12
|
+
import { upsertGcloudServiceAccountAndSaveSecret } from "../../../../../gcloud/serviceAccounts";
|
|
13
|
+
import { upsertAllVariables } from "../../../../../utils/gitlab";
|
|
14
|
+
|
|
15
|
+
export const setupCloudRun = async (
|
|
16
|
+
instance: CommandInstance,
|
|
17
|
+
context: Context
|
|
18
|
+
) => {
|
|
19
|
+
if (!isOfDeployType(context.componentConfig.deploy, "google-cloudrun")) {
|
|
20
|
+
throw new Error("deploy config is not of type 'google-cloudrun'");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const config = context.componentConfig.deploy;
|
|
24
|
+
|
|
25
|
+
// enable services
|
|
26
|
+
|
|
27
|
+
instance.log("enable required servies...");
|
|
28
|
+
await enableGCloudServices(
|
|
29
|
+
["run.googleapis.com", "artifactregistry.googleapis.com"],
|
|
30
|
+
config
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
await upsertGcloudArtifactsRegistry(config);
|
|
34
|
+
|
|
35
|
+
await upsertGcloudServiceAccountAndSaveSecret(
|
|
36
|
+
instance,
|
|
37
|
+
context,
|
|
38
|
+
{
|
|
39
|
+
projectId: config.projectId,
|
|
40
|
+
displayName: "Catladder gcloud deploy",
|
|
41
|
+
description: "This service account deploys to google cloud",
|
|
42
|
+
name: "cl-d",
|
|
43
|
+
// TODO: run.admin is a bit much, would be better to follow https://stackoverflow.com/questions/55788714/deploying-to-cloud-run-with-a-custom-service-account-failed-with-iam-serviceacco
|
|
44
|
+
roles: [
|
|
45
|
+
"roles/artifactregistry.repoAdmin",
|
|
46
|
+
"roles/run.admin",
|
|
47
|
+
"roles/iam.serviceAccountUser",
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
GCLOUD_DEPLOY_CREDENTIALS_KEY
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
// gcloud run automatically gives us a hostname
|
|
54
|
+
// but the pipeline need to know it before deployment
|
|
55
|
+
// so we get this through some magic and add this as a ci/cd variable
|
|
56
|
+
// the pipeline than can use this to construct the canonical host
|
|
57
|
+
|
|
58
|
+
const suffix = await getCloudRunDomainSuffix(config);
|
|
59
|
+
instance.log("domain suffix: " + suffix);
|
|
60
|
+
|
|
61
|
+
await upsertAllVariables(
|
|
62
|
+
instance,
|
|
63
|
+
{
|
|
64
|
+
[GCLOUD_RUN_CANONICAL_HOST_SUFFIX]: suffix,
|
|
65
|
+
},
|
|
66
|
+
context.environment.shortName,
|
|
67
|
+
context.componentName
|
|
68
|
+
);
|
|
69
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Context } from "@catladder/pipeline";
|
|
2
2
|
import { isOfDeployType, hasCloudSQL } from "@catladder/pipeline";
|
|
3
3
|
import type { CommandInstance } from "vorpal";
|
|
4
|
+
import { setupCloudRun } from "./setupCloudRun";
|
|
4
5
|
import { setupCloudSQL } from "./setupCloudSQL";
|
|
5
|
-
|
|
6
6
|
import { setupKubernetes } from "./setupKubernetes";
|
|
7
7
|
|
|
8
8
|
export const setupContext = async (
|
|
@@ -22,6 +22,9 @@ export const setupContext = async (
|
|
|
22
22
|
"..."
|
|
23
23
|
);
|
|
24
24
|
instance.log("");
|
|
25
|
+
if (isOfDeployType(context.componentConfig.deploy, "google-cloudrun")) {
|
|
26
|
+
await setupCloudRun(instance, context);
|
|
27
|
+
}
|
|
25
28
|
if (hasCloudSQL(context)) {
|
|
26
29
|
await setupCloudSQL(instance, context);
|
|
27
30
|
}
|
|
@@ -23,10 +23,6 @@ export const openGoogleCloudKubernetesDashboard = async (
|
|
|
23
23
|
namespace: string,
|
|
24
24
|
googleAuthUserNumber = 0
|
|
25
25
|
) => {
|
|
26
|
-
//gke_skynet-164509_europe-west1-d_production
|
|
27
|
-
// ?authuser=1&project=skynet-swiss&pageState=pageState%3D(%22savedViews%22:(%22c%22:%5B%22gke%2Feurope-west6-a%2Fch-production%22%5D,%22n%22:%5B%22pvl-bike2school-review%22%5D,%22i%22:%224e42e0b9cd6147f8a4fba7516752ec48%22))
|
|
28
|
-
// ?authuser=1&project=skynet-swiss&pageState=(%22savedViews%22:(%22i%22:%2279802e2b154d46d480dff4e086e87875%22,%22c%22:%5B%22gke%2Feurope-west6-a%2Fch-production%22%5D,%22n%22:%5B%22pvl-bike2school-review%22%5D))
|
|
29
|
-
|
|
30
26
|
const pageState = `("savedViews":("c":["gke/${cluster.region}/${cluster.name}"],"n":["${namespace}"],"i":"4e42e0b9cd6147f8a4fba7516752ec48"))`;
|
|
31
27
|
const url = `https://console.cloud.google.com/kubernetes/workload?authuser=${googleAuthUserNumber}&project=${
|
|
32
28
|
cluster.projectId
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Gcloudregion } from "@catladder/pipeline";
|
|
2
|
+
import { exec } from "child-process-promise";
|
|
3
|
+
|
|
4
|
+
export const upsertGcloudArtifactsRegistry = async (config: {
|
|
5
|
+
projectId: string;
|
|
6
|
+
region: Gcloudregion;
|
|
7
|
+
}) => {
|
|
8
|
+
try {
|
|
9
|
+
await exec(
|
|
10
|
+
`gcloud artifacts repositories create catladder-deploy --project="${config.projectId}" --repository-format=docker --location=${config.region}`
|
|
11
|
+
);
|
|
12
|
+
} catch (e) {
|
|
13
|
+
// probably already exists
|
|
14
|
+
//
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { DeployConfigCloudRun } from "@catladder/pipeline";
|
|
2
|
+
import { exec } from "child-process-promise";
|
|
3
|
+
|
|
4
|
+
const getSuffixFromService = (service: any) => {
|
|
5
|
+
const fullUrl = service.status.url;
|
|
6
|
+
const name = service.metadata.name;
|
|
7
|
+
|
|
8
|
+
return fullUrl.replace("https://" + name + "-", "");
|
|
9
|
+
};
|
|
10
|
+
export const getCloudRunDomainSuffix = async (config: DeployConfigCloudRun) => {
|
|
11
|
+
/* google cloud run domains are partially predictable, they have a fixed suffix that depends on the region and project, but we don't know it beforehand
|
|
12
|
+
|
|
13
|
+
So what we do is either:
|
|
14
|
+
- get one service and extract its suffix
|
|
15
|
+
- create a dummy project, extract the suffix and save that as a gitlab variable
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const dummyServiceName = "cl-dummy-service";
|
|
21
|
+
|
|
22
|
+
const existingServices = await exec(
|
|
23
|
+
`gcloud run services list --format=json --project="${config.projectId}" --region=${config.region} --limit=1`
|
|
24
|
+
).then((r) => JSON.parse(r.stdout));
|
|
25
|
+
|
|
26
|
+
if (existingServices.length > 0) {
|
|
27
|
+
return getSuffixFromService(existingServices[0]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const result = await exec(
|
|
31
|
+
`gcloud run deploy ${dummyServiceName} --region=${config.region} --allow-unauthenticated --project ${config.projectId} --image=us-docker.pkg.dev/cloudrun/container/hello --format=json`
|
|
32
|
+
).then((r) => JSON.parse(r.stdout));
|
|
33
|
+
return await getSuffixFromService(result);
|
|
34
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { exec } from "child-process-promise";
|
|
2
|
+
|
|
3
|
+
export const enableGCloudServices = async (
|
|
4
|
+
services: string[],
|
|
5
|
+
config: {
|
|
6
|
+
projectId: string;
|
|
7
|
+
}
|
|
8
|
+
) => {
|
|
9
|
+
for (const service of services) {
|
|
10
|
+
await exec(
|
|
11
|
+
`gcloud services enable ${service} --project=${config.projectId}`
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { Context } from "@catladder/pipeline";
|
|
2
|
+
|
|
3
|
+
import { exec } from "child-process-promise";
|
|
4
|
+
import { createHmac } from "crypto";
|
|
5
|
+
import type { CommandInstance } from "vorpal";
|
|
6
|
+
import { upsertAllVariables } from "../utils/gitlab";
|
|
7
|
+
|
|
8
|
+
export const accountExists = async (fullIdentifier: string) => {
|
|
9
|
+
try {
|
|
10
|
+
await exec(`gcloud iam service-accounts describe ${fullIdentifier}`);
|
|
11
|
+
return true;
|
|
12
|
+
} catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type ServiceAccount = {
|
|
18
|
+
projectId: string;
|
|
19
|
+
name: string;
|
|
20
|
+
displayName: string;
|
|
21
|
+
roles: string[];
|
|
22
|
+
description: string;
|
|
23
|
+
};
|
|
24
|
+
const upsertGcloudServiceAccount = async (
|
|
25
|
+
context: Context,
|
|
26
|
+
account: ServiceAccount
|
|
27
|
+
): Promise<string> => {
|
|
28
|
+
const { projectId, name, displayName, roles, description } = account;
|
|
29
|
+
|
|
30
|
+
// name has limit of 30
|
|
31
|
+
const namePrefix = `${name}-`;
|
|
32
|
+
const nameSuffix = `-${context.environment.shortName}-${context.componentName}`;
|
|
33
|
+
const nameMiddleLength = 30 - namePrefix.length - nameSuffix.length;
|
|
34
|
+
const nameMiddle = `${context.fullConfig.customerName}-${context.fullConfig.appName}`;
|
|
35
|
+
|
|
36
|
+
const middle = hashIfNessecary(nameMiddle, nameMiddleLength);
|
|
37
|
+
|
|
38
|
+
const fullName = `${namePrefix}${middle}${nameSuffix}`;
|
|
39
|
+
|
|
40
|
+
const fullDisplayName = `${context.fullConfig.customerName}-${context.fullConfig.appName} ${context.environment.shortName}:${context.componentName} | ${displayName}`;
|
|
41
|
+
|
|
42
|
+
const fullIdentifier = `${fullName}@${projectId}.iam.gserviceaccount.com`;
|
|
43
|
+
|
|
44
|
+
const existing = await accountExists(fullIdentifier);
|
|
45
|
+
|
|
46
|
+
if (!existing) {
|
|
47
|
+
await exec(
|
|
48
|
+
`gcloud iam service-accounts create ${fullName} --display-name="${fullDisplayName}" --project="${projectId}" --description="${description}"`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
const memberName = `serviceAccount:${fullIdentifier}`;
|
|
52
|
+
for (const role of roles) {
|
|
53
|
+
await exec(
|
|
54
|
+
`gcloud projects add-iam-policy-binding ${projectId} --member=${memberName} --role=${role} `
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// create key
|
|
59
|
+
|
|
60
|
+
// delete first all keys
|
|
61
|
+
const keys = await exec(
|
|
62
|
+
`gcloud iam service-accounts keys list --iam-account=${fullIdentifier} --managed-by=user --format=json`
|
|
63
|
+
).then((o) => JSON.parse(o.stdout));
|
|
64
|
+
|
|
65
|
+
for (const key of keys) {
|
|
66
|
+
await exec(
|
|
67
|
+
`gcloud iam service-accounts keys delete ${key.name} --quiet --iam-account=${fullIdentifier}`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return await exec(
|
|
72
|
+
`gcloud iam service-accounts keys create /dev/stdout --iam-account=${fullIdentifier}`
|
|
73
|
+
).then((o) => o.stdout);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const upsertGcloudServiceAccountAndSaveSecret = async (
|
|
77
|
+
instance: CommandInstance,
|
|
78
|
+
context: Context,
|
|
79
|
+
account: ServiceAccount,
|
|
80
|
+
secretName: string
|
|
81
|
+
): Promise<void> => {
|
|
82
|
+
instance.log("upserting service account " + account.name + "...");
|
|
83
|
+
const key = await upsertGcloudServiceAccount(context, account);
|
|
84
|
+
|
|
85
|
+
await upsertAllVariables(
|
|
86
|
+
instance,
|
|
87
|
+
{
|
|
88
|
+
[secretName]: key,
|
|
89
|
+
},
|
|
90
|
+
context.environment.shortName,
|
|
91
|
+
context.componentName
|
|
92
|
+
);
|
|
93
|
+
instance.log("done!");
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const hashIfNessecary = (str: string, maxLength: number) =>
|
|
97
|
+
str.length > maxLength ? hash(str, maxLength) : str;
|
|
98
|
+
|
|
99
|
+
const hash = (str: string, length: number) => {
|
|
100
|
+
return createHmac("sha256", str).digest("hex").substring(0, length);
|
|
101
|
+
};
|
package/src/utils/gitlab.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { exec } from "child-process-promise";
|
|
2
1
|
import { getSecretVarName } from "@catladder/pipeline";
|
|
3
|
-
import {
|
|
2
|
+
import { exec } from "child-process-promise";
|
|
3
|
+
import { has, isObject } from "lodash";
|
|
4
4
|
import memoizee from "memoizee";
|
|
5
5
|
import fetch from "node-fetch";
|
|
6
6
|
import open from "open";
|