@catladder/cli 1.15.0 → 1.15.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/commandSetup.js +5 -200
- package/dist/apps/cli/commands/project/commandSetup.js.map +1 -1
- package/dist/apps/cli/commands/project/setup/index.d.ts +2 -0
- package/dist/apps/cli/commands/project/setup/index.js +103 -0
- package/dist/apps/cli/commands/project/setup/index.js.map +1 -0
- package/dist/apps/cli/commands/project/setup/setupAccessTokens.d.ts +2 -0
- package/dist/apps/cli/commands/project/setup/setupAccessTokens.js +106 -0
- package/dist/apps/cli/commands/project/setup/setupAccessTokens.js.map +1 -0
- package/dist/apps/cli/commands/project/setup/setupContext.d.ts +3 -0
- package/dist/apps/cli/commands/project/setup/setupContext.js +74 -0
- package/dist/apps/cli/commands/project/setup/setupContext.js.map +1 -0
- package/dist/apps/cli/commands/project/setup/setupKubernetes.d.ts +3 -0
- package/dist/apps/cli/commands/project/setup/setupKubernetes.js +132 -0
- package/dist/apps/cli/commands/project/setup/setupKubernetes.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/apps/cli/commands/project/commandSetup.ts +2 -230
- package/src/apps/cli/commands/project/setup/index.ts +42 -0
- package/src/apps/cli/commands/project/setup/setupAccessTokens.ts +70 -0
- package/src/apps/cli/commands/project/setup/setupContext.ts +37 -0
- package/src/apps/cli/commands/project/setup/setupKubernetes.ts +112 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
+
return cooked;
|
|
5
|
+
};
|
|
6
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
16
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
17
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
18
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
19
|
+
function step(op) {
|
|
20
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
21
|
+
while (_) try {
|
|
22
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
23
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
24
|
+
switch (op[0]) {
|
|
25
|
+
case 0: case 1: t = op; break;
|
|
26
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
27
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
28
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
29
|
+
default:
|
|
30
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
31
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
32
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
33
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
34
|
+
if (t[2]) _.ops.pop();
|
|
35
|
+
_.trys.pop(); continue;
|
|
36
|
+
}
|
|
37
|
+
op = body.call(thisArg, _);
|
|
38
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
39
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
43
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
|
+
};
|
|
45
|
+
exports.__esModule = true;
|
|
46
|
+
exports.setupKubernetes = void 0;
|
|
47
|
+
var pipeline_1 = require("@catladder/pipeline");
|
|
48
|
+
var zx_1 = require("zx");
|
|
49
|
+
var cluster_1 = require("../../../../../utils/cluster");
|
|
50
|
+
var gitlab_1 = require("../../../../../utils/gitlab");
|
|
51
|
+
var ensureNamespace_1 = __importDefault(require("../utils/ensureNamespace"));
|
|
52
|
+
var setupKubernetes = function (instance, context) { return __awaiter(void 0, void 0, void 0, function () {
|
|
53
|
+
var deployConfig, fullName, namespace, serviceAccountName, KUBE_URL, e_1, tokenName, KUBE_CA_PEM, KUBE_TOKEN, vars;
|
|
54
|
+
return __generator(this, function (_a) {
|
|
55
|
+
switch (_a.label) {
|
|
56
|
+
case 0:
|
|
57
|
+
deployConfig = context.componentConfig.deploy;
|
|
58
|
+
if (!(0, pipeline_1.isOfDeployType)(deployConfig, "kubernetes")) {
|
|
59
|
+
throw new Error("cannot run setupKubernetes on non-kubernetes deployments");
|
|
60
|
+
}
|
|
61
|
+
fullName = (0, pipeline_1.getFullKubernetesClusterName)(deployConfig.cluster);
|
|
62
|
+
instance.log("cluster: ".concat(fullName));
|
|
63
|
+
return [4 /*yield*/, (0, cluster_1.connectToCluster)(fullName)];
|
|
64
|
+
case 1:
|
|
65
|
+
_a.sent();
|
|
66
|
+
instance.log("");
|
|
67
|
+
instance.log("ensuring namespace ...");
|
|
68
|
+
return [4 /*yield*/, (0, ensureNamespace_1["default"])(context)];
|
|
69
|
+
case 2:
|
|
70
|
+
namespace = _a.sent();
|
|
71
|
+
instance.log("Namespace " + namespace + " created / updated!");
|
|
72
|
+
instance.log("");
|
|
73
|
+
//$.verbose = true;
|
|
74
|
+
// we name the service account and the role and the role binding with the same name
|
|
75
|
+
// we currently create one per component to better separate them
|
|
76
|
+
instance.log("ensuring service accounts...");
|
|
77
|
+
serviceAccountName = "cl-".concat(context.componentName, "-deploy");
|
|
78
|
+
return [4 /*yield*/, (0, zx_1.$)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["TERM=dumb kubectl cluster-info | grep -E 'Kubernetes master|Kubernetes control plane' | awk '/http/ {print $NF}'"], ["TERM=dumb kubectl cluster-info | grep -E 'Kubernetes master|Kubernetes control plane' | awk '/http/ {print $NF}'"]))).then(function (s) { return s.stdout.trim(); })];
|
|
79
|
+
case 3:
|
|
80
|
+
KUBE_URL = _a.sent();
|
|
81
|
+
_a.label = 4;
|
|
82
|
+
case 4:
|
|
83
|
+
_a.trys.push([4, 8, , 9]);
|
|
84
|
+
return [4 /*yield*/, (0, zx_1.$)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["kubectl delete serviceaccount --namespace ", " ", ""], ["kubectl delete serviceaccount --namespace ", " ", ""])), namespace, serviceAccountName)];
|
|
85
|
+
case 5:
|
|
86
|
+
_a.sent();
|
|
87
|
+
return [4 /*yield*/, (0, zx_1.$)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["kubectl delete rolebinding --namespace ", " ", ""], ["kubectl delete rolebinding --namespace ", " ", ""])), namespace, serviceAccountName)];
|
|
88
|
+
case 6:
|
|
89
|
+
_a.sent();
|
|
90
|
+
return [4 /*yield*/, (0, zx_1.$)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["kubectl delete role --namespace ", " ", ""], ["kubectl delete role --namespace ", " ", ""])), namespace, serviceAccountName)];
|
|
91
|
+
case 7:
|
|
92
|
+
_a.sent();
|
|
93
|
+
return [3 /*break*/, 9];
|
|
94
|
+
case 8:
|
|
95
|
+
e_1 = _a.sent();
|
|
96
|
+
return [3 /*break*/, 9];
|
|
97
|
+
case 9: return [4 /*yield*/, (0, zx_1.$)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["kubectl create serviceaccount --namespace ", " ", ""], ["kubectl create serviceaccount --namespace ", " ", ""])), namespace, serviceAccountName)];
|
|
98
|
+
case 10:
|
|
99
|
+
_a.sent();
|
|
100
|
+
// upsert role in the ns
|
|
101
|
+
return [4 /*yield*/, (0, zx_1.$)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["cat <<EOF | kubectl apply -f -\nkind: Role\napiVersion: rbac.authorization.k8s.io/v1\nmetadata:\n namespace: ", "\n name: ", "\nrules:\n- apiGroups: [\"\", \"extensions\", \"apps\", \"networking.k8s.io\", \"batch\"]\n resources: [\"deployments\", \"replicasets\", \"statefulsets\", \"pods\", \"secrets\", \"configmaps\", \"services\", \"ingresses\", \"serviceaccounts\", \"jobs\", \"cronjobs\"]\n verbs: [\"get\", \"list\", \"watch\", \"create\", \"update\", \"patch\", \"delete\"] # You can also use [\"*\"]\n---\nkind: RoleBinding\napiVersion: rbac.authorization.k8s.io/v1\nmetadata:\n name: ", "\n namespace: ", "\nsubjects:\n - kind: ServiceAccount\n name: ", "\n namespace: ", "\nroleRef:\n kind: Role\n name: ", "\n apiGroup: rbac.authorization.k8s.io\nEOF\n"], ["cat <<EOF | kubectl apply -f -\nkind: Role\napiVersion: rbac.authorization.k8s.io/v1\nmetadata:\n namespace: ", "\n name: ", "\nrules:\n- apiGroups: [\"\", \"extensions\", \"apps\", \"networking.k8s.io\", \"batch\"]\n resources: [\"deployments\", \"replicasets\", \"statefulsets\", \"pods\", \"secrets\", \"configmaps\", \"services\", \"ingresses\", \"serviceaccounts\", \"jobs\", \"cronjobs\"]\n verbs: [\"get\", \"list\", \"watch\", \"create\", \"update\", \"patch\", \"delete\"] # You can also use [\"*\"]\n---\nkind: RoleBinding\napiVersion: rbac.authorization.k8s.io/v1\nmetadata:\n name: ", "\n namespace: ", "\nsubjects:\n - kind: ServiceAccount\n name: ", "\n namespace: ", "\nroleRef:\n kind: Role\n name: ", "\n apiGroup: rbac.authorization.k8s.io\nEOF\n"])), namespace, serviceAccountName, serviceAccountName, namespace, serviceAccountName, namespace, serviceAccountName)];
|
|
102
|
+
case 11:
|
|
103
|
+
// upsert role in the ns
|
|
104
|
+
_a.sent();
|
|
105
|
+
return [4 /*yield*/, (0, zx_1.$)(templateObject_7 || (templateObject_7 = __makeTemplateObject(["kubectl get serviceaccount --namespace ", " ", " -o jsonpath='{.secrets[0].name}'"], ["kubectl get serviceaccount --namespace ", " ", " -o jsonpath='{.secrets[0].name}'"])), namespace, serviceAccountName)];
|
|
106
|
+
case 12:
|
|
107
|
+
tokenName = _a.sent();
|
|
108
|
+
return [4 /*yield*/, (0, zx_1.$)(templateObject_8 || (templateObject_8 = __makeTemplateObject(["kubectl get secret ", " --namespace ", " -o jsonpath=\"{['data']['ca\\.crt']}\""], ["kubectl get secret ", " --namespace ", " -o jsonpath=\"{['data']['ca\\\\.crt']}\""])), tokenName, namespace).then(function (c) { return c.stdout.trim(); })];
|
|
109
|
+
case 13:
|
|
110
|
+
KUBE_CA_PEM = _a.sent();
|
|
111
|
+
return [4 /*yield*/, (0, zx_1.$)(templateObject_9 || (templateObject_9 = __makeTemplateObject(["kubectl get secret ", " --namespace ", " -o jsonpath=\"{['data']['token']}\" | base64 --decode"], ["kubectl get secret ", " --namespace ", " -o jsonpath=\"{['data']['token']}\" | base64 --decode"])), tokenName, namespace).then(function (c) { return c.stdout.trim(); })];
|
|
112
|
+
case 14:
|
|
113
|
+
KUBE_TOKEN = _a.sent();
|
|
114
|
+
vars = {
|
|
115
|
+
KUBE_TOKEN: KUBE_TOKEN,
|
|
116
|
+
KUBE_CA_PEM: KUBE_CA_PEM,
|
|
117
|
+
KUBE_URL: KUBE_URL
|
|
118
|
+
};
|
|
119
|
+
instance.log("service accounts created / updated!");
|
|
120
|
+
instance.log("");
|
|
121
|
+
instance.log("pusing secrets to gitlab...");
|
|
122
|
+
return [4 /*yield*/, (0, gitlab_1.upsertAllVariables)(instance, vars, context.environment.shortName, context.componentName)];
|
|
123
|
+
case 15:
|
|
124
|
+
_a.sent();
|
|
125
|
+
instance.log("done!");
|
|
126
|
+
return [2 /*return*/];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}); };
|
|
130
|
+
exports.setupKubernetes = setupKubernetes;
|
|
131
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9;
|
|
132
|
+
//# sourceMappingURL=setupKubernetes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setupKubernetes.js","sourceRoot":"","sources":["../../../../../../src/apps/cli/commands/project/setup/setupKubernetes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAI6B;AAE7B,yBAAuB;AACvB,wDAAgE;AAChE,sDAAiE;AACjE,6EAAuD;AAEhD,IAAM,eAAe,GAAG,UAC7B,QAAyB,EACzB,OAAgB;;;;;gBAEV,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC;gBACpD,IAAI,CAAC,IAAA,yBAAc,EAAC,YAAY,EAAE,YAAY,CAAC,EAAE;oBAC/C,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;iBAC7E;gBAEK,QAAQ,GAAG,IAAA,uCAA4B,EAAC,YAAY,CAAC,OAAO,CAAC,CAAC;gBACpE,QAAQ,CAAC,GAAG,CAAC,mBAAY,QAAQ,CAAE,CAAC,CAAC;gBAErC,qBAAM,IAAA,0BAAgB,EAAC,QAAQ,CAAC,EAAA;;gBAAhC,SAAgC,CAAC;gBACjC,QAAQ,CAAC,GAAG,CA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