@catladder/cli 1.13.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/commandConfigSecrets.d.ts +2 -1
- package/dist/apps/cli/commands/project/commandConfigSecrets.js +54 -36
- package/dist/apps/cli/commands/project/commandConfigSecrets.js.map +1 -1
- package/dist/apps/cli/commands/project/{commandInitGitlab.d.ts → commandInitProject.old.d.ts} +0 -0
- package/dist/apps/cli/commands/project/{commandInitProject.js → commandInitProject.old.js} +1 -1
- package/dist/apps/cli/commands/project/commandInitProject.old.js.map +1 -0
- package/dist/apps/cli/commands/project/{commandInitProject.d.ts → commandSetup.d.ts} +0 -0
- package/dist/apps/cli/commands/project/commandSetup.js +58 -0
- package/dist/apps/cli/commands/project/commandSetup.js.map +1 -0
- package/dist/apps/cli/commands/project/index.js +3 -4
- package/dist/apps/cli/commands/project/index.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/commandConfigSecrets.ts +32 -21
- package/src/apps/cli/commands/project/{commandInitProject.ts → commandInitProject.old.ts} +0 -0
- package/src/apps/cli/commands/project/commandSetup.ts +12 -0
- package/src/apps/cli/commands/project/index.ts +4 -4
- 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
- package/dist/apps/cli/commands/project/commandInitGitlab.js +0 -202
- package/dist/apps/cli/commands/project/commandInitGitlab.js.map +0 -1
- package/dist/apps/cli/commands/project/commandInitProject.js.map +0 -1
- package/src/apps/cli/commands/project/commandInitGitlab.ts +0 -191
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getFullKubernetesClusterName,
|
|
3
|
-
isOfDeployType,
|
|
4
|
-
} from "@catladder/pipeline";
|
|
5
|
-
import Vorpal from "vorpal";
|
|
6
|
-
import { $ } from "zx";
|
|
7
|
-
import { getAllPipelineContexts } from "../../../../config/getProjectConfig";
|
|
8
|
-
import { connectToCluster } from "../../../../utils/cluster";
|
|
9
|
-
import {
|
|
10
|
-
doGitlabRequest,
|
|
11
|
-
getProjectInfo,
|
|
12
|
-
upsertAllVariables,
|
|
13
|
-
} from "../../../../utils/gitlab";
|
|
14
|
-
import ensureNamespace from "./utils/ensureNamespace";
|
|
15
|
-
import open from "open";
|
|
16
|
-
|
|
17
|
-
export default async (vorpal: Vorpal) =>
|
|
18
|
-
vorpal
|
|
19
|
-
.command(
|
|
20
|
-
"project-init-gitlab",
|
|
21
|
-
"Initializes the gitlab repo, e.g. connects the cluster to it"
|
|
22
|
-
)
|
|
23
|
-
.action(async function () {
|
|
24
|
-
const allContext = await getAllPipelineContexts();
|
|
25
|
-
|
|
26
|
-
for (const context of allContext) {
|
|
27
|
-
const deployConfig = context.componentConfig.deploy;
|
|
28
|
-
if (isOfDeployType(deployConfig, "kubernetes")) {
|
|
29
|
-
const fullName = getFullKubernetesClusterName(deployConfig.cluster);
|
|
30
|
-
this.log(
|
|
31
|
-
`connecting ${context.environment.shortName}:${context.componentName} ${fullName}`
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
await connectToCluster(fullName);
|
|
35
|
-
|
|
36
|
-
const namespace = await ensureNamespace(context);
|
|
37
|
-
|
|
38
|
-
//$.verbose = true;
|
|
39
|
-
|
|
40
|
-
// we name the service account and the role and the role binding with the same name
|
|
41
|
-
// we currently create one per component to better separate them
|
|
42
|
-
const serviceAccountName = `cl-${context.componentName}-deploy`;
|
|
43
|
-
const KUBE_URL =
|
|
44
|
-
await $`TERM=dumb kubectl cluster-info | grep -E 'Kubernetes master|Kubernetes control plane' | awk '/http/ {print $NF}'`.then(
|
|
45
|
-
(s) => s.stdout.trim()
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
// first upsert service acount in the ns
|
|
49
|
-
try {
|
|
50
|
-
await $`kubectl delete serviceaccount --namespace ${namespace} ${serviceAccountName}`;
|
|
51
|
-
await $`kubectl delete rolebinding --namespace ${namespace} ${serviceAccountName}`;
|
|
52
|
-
await $`kubectl delete role --namespace ${namespace} ${serviceAccountName}`;
|
|
53
|
-
} catch (e) {
|
|
54
|
-
// ignore
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
await $`kubectl create serviceaccount --namespace ${namespace} ${serviceAccountName}`;
|
|
58
|
-
|
|
59
|
-
// upsert role in the ns
|
|
60
|
-
|
|
61
|
-
await $`cat <<EOF | kubectl apply -f -
|
|
62
|
-
kind: Role
|
|
63
|
-
apiVersion: rbac.authorization.k8s.io/v1
|
|
64
|
-
metadata:
|
|
65
|
-
namespace: ${namespace}
|
|
66
|
-
name: ${serviceAccountName}
|
|
67
|
-
rules:
|
|
68
|
-
- apiGroups: ["", "extensions", "apps", "networking.k8s.io", "batch"]
|
|
69
|
-
resources: ["deployments", "replicasets", "statefulsets", "pods", "secrets", "configmaps", "services", "ingresses", "serviceaccounts", "jobs", "cronjobs"]
|
|
70
|
-
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"] # You can also use ["*"]
|
|
71
|
-
---
|
|
72
|
-
kind: RoleBinding
|
|
73
|
-
apiVersion: rbac.authorization.k8s.io/v1
|
|
74
|
-
metadata:
|
|
75
|
-
name: ${serviceAccountName}
|
|
76
|
-
namespace: ${namespace}
|
|
77
|
-
subjects:
|
|
78
|
-
- kind: ServiceAccount
|
|
79
|
-
name: ${serviceAccountName}
|
|
80
|
-
namespace: ${namespace}
|
|
81
|
-
roleRef:
|
|
82
|
-
kind: Role
|
|
83
|
-
name: ${serviceAccountName}
|
|
84
|
-
apiGroup: rbac.authorization.k8s.io
|
|
85
|
-
EOF
|
|
86
|
-
`;
|
|
87
|
-
|
|
88
|
-
// get token name
|
|
89
|
-
const tokenName =
|
|
90
|
-
await $`kubectl get serviceaccount --namespace ${namespace} ${serviceAccountName} -o jsonpath='{.secrets[0].name}'`;
|
|
91
|
-
|
|
92
|
-
const KUBE_CA_PEM =
|
|
93
|
-
await $`kubectl get secret ${tokenName} --namespace ${namespace} -o jsonpath="{['data']['ca\\.crt']}"`.then(
|
|
94
|
-
(c) => c.stdout.trim()
|
|
95
|
-
);
|
|
96
|
-
const KUBE_TOKEN =
|
|
97
|
-
await $`kubectl get secret ${tokenName} --namespace ${namespace} -o jsonpath="{['data']['token']}" | base64 --decode`.then(
|
|
98
|
-
(c) => c.stdout.trim()
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
const vars = {
|
|
102
|
-
KUBE_TOKEN,
|
|
103
|
-
KUBE_CA_PEM,
|
|
104
|
-
KUBE_URL,
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
await upsertAllVariables(
|
|
108
|
-
this,
|
|
109
|
-
vars,
|
|
110
|
-
context.environment.shortName,
|
|
111
|
-
context.componentName
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const { id: projectId, web_url: projectWebUrl } = await getProjectInfo(
|
|
117
|
-
this
|
|
118
|
-
);
|
|
119
|
-
const variables = await doGitlabRequest(
|
|
120
|
-
this,
|
|
121
|
-
`projects/${projectId}/variables`
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
if (!variables.find((v: any) => v.key === "GL_TOKEN")) {
|
|
125
|
-
this.log(
|
|
126
|
-
"I need add a GL_TOKEN to the project, so that semantic release will work\n"
|
|
127
|
-
);
|
|
128
|
-
this.log(
|
|
129
|
-
"👉 Please please create a project access token in gitlab and copy its value into clipboard\n\n - name: something like 'semantic-release'\n - expires: leave empty\n - scopes: api, read_repository"
|
|
130
|
-
);
|
|
131
|
-
this.log("\n");
|
|
132
|
-
|
|
133
|
-
const { understood } = await this.prompt({
|
|
134
|
-
default: true,
|
|
135
|
-
message: "Understood and open gitlab now? 🤔",
|
|
136
|
-
name: "understood",
|
|
137
|
-
type: "confirm",
|
|
138
|
-
});
|
|
139
|
-
if (!understood) {
|
|
140
|
-
this.log("continuing anyway...");
|
|
141
|
-
}
|
|
142
|
-
open(`${projectWebUrl}/-/settings/access_tokens`);
|
|
143
|
-
|
|
144
|
-
this.log("\n");
|
|
145
|
-
|
|
146
|
-
this.log("Enter your copied token now: ");
|
|
147
|
-
|
|
148
|
-
this.log("\n");
|
|
149
|
-
const { GL_TOKEN } = await this.prompt({
|
|
150
|
-
type: "password",
|
|
151
|
-
name: "GL_TOKEN",
|
|
152
|
-
message: "Access Token: ",
|
|
153
|
-
});
|
|
154
|
-
await doGitlabRequest(this, `projects/${projectId}/variables`, {
|
|
155
|
-
key: "GL_TOKEN",
|
|
156
|
-
value: GL_TOKEN,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const deploy_tokens = await doGitlabRequest(
|
|
161
|
-
this,
|
|
162
|
-
`projects/${projectId}/deploy_tokens`
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
!deploy_tokens.find(
|
|
167
|
-
(v: { name: string }) => v.name === "gitlab-deploy-token"
|
|
168
|
-
)
|
|
169
|
-
) {
|
|
170
|
-
this.log(
|
|
171
|
-
"I will setup the 'GitLab Deploy Token', so Kubernetes can pull images from this project."
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
await doGitlabRequest(this, `projects/${projectId}/deploy_tokens`, {
|
|
175
|
-
id: projectId,
|
|
176
|
-
name: "gitlab-deploy-token",
|
|
177
|
-
scopes: ["read_registry"],
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
this.log("gitlab is ready! 🥂");
|
|
181
|
-
this.log("\n");
|
|
182
|
-
this.log("do not forget to make sure that:");
|
|
183
|
-
[
|
|
184
|
-
"you have __health route in place",
|
|
185
|
-
"lint and test are defined",
|
|
186
|
-
"eat your vegetables",
|
|
187
|
-
"be awesome 🤩",
|
|
188
|
-
].forEach((tip) => this.log(` - ${tip}`));
|
|
189
|
-
this.log("\n");
|
|
190
|
-
this.log("\n");
|
|
191
|
-
});
|