@catladder/pipeline 0.0.5 → 1.0.0
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/babel-inline.json +11 -0
- package/bin/catladder-gitlab.js +3 -0
- package/dist/build/base/constants.d.ts +7 -0
- package/dist/build/base/constants.js +11 -0
- package/dist/build/base/createBuildJob.d.ts +5 -0
- package/dist/build/base/createBuildJob.js +99 -0
- package/dist/build/docker.d.ts +5 -0
- package/dist/build/docker.js +95 -0
- package/dist/build/index.d.ts +12 -0
- package/dist/build/index.js +63 -0
- package/dist/build/node/buildJob.d.ts +3 -0
- package/dist/build/node/buildJob.js +97 -0
- package/dist/build/node/cache.d.ts +4 -0
- package/dist/build/node/cache.js +67 -0
- package/dist/build/node/constants.d.ts +6 -0
- package/dist/build/node/constants.js +10 -0
- package/dist/build/node/index.d.ts +5 -0
- package/dist/build/node/index.js +63 -0
- package/dist/build/node/meteor.d.ts +3 -0
- package/dist/build/node/meteor.js +103 -0
- package/dist/build/node/testJob.d.ts +3 -0
- package/dist/build/node/testJob.js +112 -0
- package/dist/build/node/yarn.d.ts +2 -0
- package/dist/build/node/yarn.js +12 -0
- package/dist/build/tests/storybook.test.d.ts +1 -0
- package/dist/build/tests/storybook.test.js +221 -0
- package/dist/build/types.d.ts +63 -0
- package/dist/build/types.js +16 -0
- package/dist/catladder-gitlab.d.ts +1 -0
- package/dist/catladder-gitlab.js +44 -0
- package/dist/config/configruedEnvs.d.ts +4 -0
- package/dist/config/configruedEnvs.js +86 -0
- package/dist/config/configruedEnvs.test.d.ts +1 -0
- package/dist/config/configruedEnvs.test.js +103 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +24 -0
- package/dist/config/readConfig.d.ts +2 -0
- package/dist/config/readConfig.js +47 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +6 -0
- package/dist/context/index.d.ts +5 -0
- package/dist/context/index.js +211 -0
- package/dist/defaults/index.d.ts +2 -0
- package/dist/defaults/index.js +8 -0
- package/dist/deploy/base.d.ts +9 -0
- package/dist/deploy/base.js +94 -0
- package/dist/deploy/index.d.ts +11 -0
- package/dist/deploy/index.js +34 -0
- package/dist/deploy/kubernetes/cloudsql.d.ts +6 -0
- package/dist/deploy/kubernetes/cloudsql.js +16 -0
- package/dist/deploy/kubernetes/deployJob.d.ts +3 -0
- package/dist/deploy/kubernetes/deployJob.js +148 -0
- package/dist/deploy/kubernetes/index.d.ts +1 -0
- package/dist/deploy/kubernetes/index.js +22 -0
- package/dist/deploy/kubernetes/mongodb.d.ts +15 -0
- package/dist/deploy/kubernetes/mongodb.js +23 -0
- package/dist/deploy/types.d.ts +92 -0
- package/dist/deploy/types.js +16 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +36 -0
- package/dist/pipeline/createChildPipeline.d.ts +9 -0
- package/dist/pipeline/createChildPipeline.js +266 -0
- package/dist/pipeline/createChildPipeline.test.d.ts +1 -0
- package/dist/pipeline/createChildPipeline.test.js +199 -0
- package/dist/pipeline/createJobs.d.ts +3 -0
- package/dist/pipeline/createJobs.js +331 -0
- package/dist/pipeline/index.d.ts +2 -0
- package/dist/pipeline/index.js +24 -0
- package/dist/pipeline/yarnInfo.d.ts +2 -0
- package/dist/pipeline/yarnInfo.js +296 -0
- package/dist/rules/index.d.ts +3 -0
- package/dist/rules/index.js +27 -0
- package/dist/runner/index.d.ts +3 -0
- package/dist/runner/index.js +12 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/config.d.ts +73 -0
- package/dist/types/config.js +80 -0
- package/dist/types/context.d.ts +36 -0
- package/dist/types/context.js +3 -0
- package/dist/types/gitlab-types.d.ts +86 -0
- package/dist/types/gitlab-types.js +5 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +26 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +18 -0
- package/package.json +30 -8
- package/src/build/base/constants.ts +7 -0
- package/src/build/base/createBuildJob.ts +46 -0
- package/{scripts/magic → src}/build/docker.ts +17 -4
- package/src/build/index.ts +42 -0
- package/src/build/node/buildJob.ts +54 -0
- package/src/build/node/cache.ts +36 -0
- package/src/build/node/constants.ts +6 -0
- package/src/build/node/index.ts +17 -0
- package/src/build/node/meteor.ts +75 -0
- package/src/build/node/testJob.ts +80 -0
- package/src/build/node/yarn.ts +8 -0
- package/src/build/tests/storybook.test.ts +46 -0
- package/src/build/types.ts +75 -0
- package/src/catladder-gitlab.ts +52 -0
- package/src/config/configruedEnvs.test.ts +97 -0
- package/src/config/configruedEnvs.ts +56 -0
- package/src/config/index.ts +2 -0
- package/src/config/readConfig.ts +36 -0
- package/src/constants.ts +2 -0
- package/src/context/index.ts +194 -0
- package/src/defaults/index.ts +6 -0
- package/src/deploy/base.ts +101 -0
- package/src/deploy/index.ts +19 -0
- package/src/deploy/kubernetes/cloudsql.ts +13 -0
- package/src/deploy/kubernetes/deployJob.ts +116 -0
- package/src/deploy/kubernetes/index.ts +1 -0
- package/src/deploy/kubernetes/mongodb.ts +20 -0
- package/src/deploy/types.ts +60 -0
- package/src/index.ts +8 -0
- package/{scripts/magic/tests/createPipeline.test.ts → src/pipeline/createChildPipeline.test.ts} +12 -11
- package/src/pipeline/createChildPipeline.ts +51 -0
- package/src/pipeline/createJobs.ts +158 -0
- package/src/pipeline/index.ts +2 -0
- package/src/pipeline/yarnInfo.ts +54 -0
- package/src/rules/index.ts +37 -0
- package/src/runner/index.ts +10 -0
- package/src/types/config.ts +88 -0
- package/src/types/context.ts +36 -0
- package/src/types/gitlab-types.ts +94 -0
- package/{scripts/magic → src}/types/index.ts +0 -0
- package/src/utils/index.ts +10 -0
- package/tsconfig.json +4 -2
- package/Dockerfile +0 -84
- package/dist/scripts/magic/index.js +0 -16
- package/scripts/createSamplePipeline.ts +0 -10
- package/scripts/getCommitInfo +0 -11
- package/scripts/kubernetesCreateSecret +0 -9
- package/scripts/kubernetesDelete +0 -4
- package/scripts/kubernetesDeploy +0 -55
- package/scripts/kubernetesEnsureNamespace +0 -3
- package/scripts/magic/build/index.ts +0 -16
- package/scripts/magic/build/node.ts +0 -130
- package/scripts/magic/build/types.ts +0 -17
- package/scripts/magic/createChildPipeline/index.ts +0 -176
- package/scripts/magic/createPipeline.ts +0 -52
- package/scripts/magic/deploy/index.ts +0 -19
- package/scripts/magic/deploy/kubernetes.ts +0 -65
- package/scripts/magic/deploy/types.ts +0 -29
- package/scripts/magic/index.ts +0 -2
- package/scripts/magic/sample-config.ts +0 -78
- package/scripts/magic/types/config.ts +0 -54
- package/scripts/magic/types/context.ts +0 -21
- package/scripts/magic/types/gitlab-types.ts +0 -69
- package/scripts/magic.ts +0 -51
- package/scripts/monorepoGenerate.ts +0 -104
- package/scripts/printAllValues.ts +0 -17
- package/scripts/printBuildEnv.ts +0 -22
- package/scripts/utils/extractAllValues.ts +0 -32
- package/scripts/utils/extractBuildEnv.ts +0 -94
- package/scripts/utils/extractValuesFromEnvVars.ts +0 -21
- package/scripts/utils/extractValuesFromMr.ts +0 -39
- package/tests/extractValuesFromMr.test.ts +0 -156
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { merge } from "lodash";
|
|
2
|
-
import slugify from "slugify";
|
|
3
|
-
import { GitlabJobDef, GitlabJobs } from "../types/gitlab-types";
|
|
4
|
-
|
|
5
|
-
import { Config, DefaultEnvConfig } from "../types/config";
|
|
6
|
-
import { CommitInfo, Context, Environment } from "../types/context";
|
|
7
|
-
import { deployJobCreators, getDeployDefaults } from "../deploy";
|
|
8
|
-
import { buildJobCreators, getBuildDefaults } from "../build";
|
|
9
|
-
import { BuildConfig } from "../build/types";
|
|
10
|
-
import { DeployConfig } from "../deploy/types";
|
|
11
|
-
|
|
12
|
-
const createRawJobs = (context: Context): GitlabJobs => {
|
|
13
|
-
const buildJobs =
|
|
14
|
-
buildJobCreators[context.componentConfig.build.type](context);
|
|
15
|
-
const deployJobs =
|
|
16
|
-
deployJobCreators[context.componentConfig.deploy.type](context);
|
|
17
|
-
|
|
18
|
-
return [...buildJobs, ...deployJobs];
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const getEnvironment = (
|
|
22
|
-
config: Config,
|
|
23
|
-
componentName: string,
|
|
24
|
-
env: string,
|
|
25
|
-
commitInfo: CommitInfo
|
|
26
|
-
): Environment => {
|
|
27
|
-
const componentConfig = config.components[componentName];
|
|
28
|
-
if (!componentConfig) {
|
|
29
|
-
throw new Error("unknown component " + componentName);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const defaultConfig = componentConfig;
|
|
33
|
-
const envConfig = componentConfig.env?.[env] ?? {};
|
|
34
|
-
|
|
35
|
-
const mergedConfig = merge({}, defaultConfig, envConfig);
|
|
36
|
-
|
|
37
|
-
const publicEnvVars = mergedConfig.vars?.public ?? {};
|
|
38
|
-
const secretEnvVarsRaw = mergedConfig.vars?.secret ?? {}; // TODO, map to gl secrets?
|
|
39
|
-
const secretEnvVars = {}; // TODO
|
|
40
|
-
const referencedRaw = mergedConfig.vars?.fromComponents ?? {};
|
|
41
|
-
|
|
42
|
-
const referenced = Object.entries(referencedRaw).reduce(
|
|
43
|
-
(acc, [otherApp, mapping]) => {
|
|
44
|
-
// TODO: prevent infinit looop
|
|
45
|
-
const { variables } = getEnvironment(config, otherApp, env, commitInfo);
|
|
46
|
-
|
|
47
|
-
return Object.fromEntries(
|
|
48
|
-
Object.entries(mapping).map(([ourKey, otherKey]) => [
|
|
49
|
-
ourKey,
|
|
50
|
-
variables[otherKey],
|
|
51
|
-
])
|
|
52
|
-
);
|
|
53
|
-
},
|
|
54
|
-
{}
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
const envType = componentConfig.env?.[env]?.type ?? env;
|
|
58
|
-
const environmentName =
|
|
59
|
-
envType === "review"
|
|
60
|
-
? `${env}-${componentName}/${commitInfo.refName}`
|
|
61
|
-
: `${env}-${componentName}`;
|
|
62
|
-
|
|
63
|
-
const KUBE_APP_NAME =
|
|
64
|
-
envType === "review"
|
|
65
|
-
? `${componentName}-${commitInfo.refSlug}`
|
|
66
|
-
: componentName;
|
|
67
|
-
|
|
68
|
-
const KUBE_NAMESPACE = `${config.customerName}-${config.appName}-${env}`;
|
|
69
|
-
|
|
70
|
-
const APP_SLUG = slugify(KUBE_APP_NAME);
|
|
71
|
-
|
|
72
|
-
const HOST_CANONICAL = `${config.appName}-${APP_SLUG}.${config.customerName}.panter.cloud`;
|
|
73
|
-
|
|
74
|
-
const hostname = mergedConfig.hostname ?? HOST_CANONICAL;
|
|
75
|
-
const url = `https://${hostname}`;
|
|
76
|
-
|
|
77
|
-
const predefinedVariables = {
|
|
78
|
-
HOST_CANONICAL,
|
|
79
|
-
ROOT_URL: url,
|
|
80
|
-
KUBE_NAMESPACE,
|
|
81
|
-
KUBE_APP_NAME,
|
|
82
|
-
ENV_SHORT: env,
|
|
83
|
-
};
|
|
84
|
-
const variables = {
|
|
85
|
-
...predefinedVariables,
|
|
86
|
-
...publicEnvVars,
|
|
87
|
-
...secretEnvVars,
|
|
88
|
-
...referenced,
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
hostname,
|
|
93
|
-
fullName: environmentName,
|
|
94
|
-
shortName: env,
|
|
95
|
-
url: url,
|
|
96
|
-
variables,
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export const createContext = (
|
|
101
|
-
componentName: string,
|
|
102
|
-
config: Config,
|
|
103
|
-
env: string
|
|
104
|
-
): Context => {
|
|
105
|
-
const rawConfig = config.components[componentName];
|
|
106
|
-
if (!rawConfig) {
|
|
107
|
-
throw new Error("unknown component " + componentName);
|
|
108
|
-
}
|
|
109
|
-
// envs can override the config
|
|
110
|
-
const envConfig = rawConfig.env?.[env] ?? {};
|
|
111
|
-
const componentConfigWithoutDefaults = merge({}, rawConfig, envConfig);
|
|
112
|
-
// fill in defaults of build and deploy
|
|
113
|
-
const defaults: {
|
|
114
|
-
build: Partial<BuildConfig>;
|
|
115
|
-
deploy: Partial<DeployConfig>;
|
|
116
|
-
} = {
|
|
117
|
-
build: getBuildDefaults[componentConfigWithoutDefaults.build.type](),
|
|
118
|
-
deploy: getDeployDefaults[componentConfigWithoutDefaults.deploy.type](),
|
|
119
|
-
};
|
|
120
|
-
const componentConfig = merge({}, componentConfigWithoutDefaults, defaults);
|
|
121
|
-
const commit = {
|
|
122
|
-
refName: process.env.CI_COMMIT_REF_NAME ?? "unknown",
|
|
123
|
-
refSlug: process.env.CI_COMMIT_REF_SLUG ?? "unknown",
|
|
124
|
-
};
|
|
125
|
-
return {
|
|
126
|
-
fullConfig: config,
|
|
127
|
-
componentConfig,
|
|
128
|
-
componentName,
|
|
129
|
-
environment: getEnvironment(config, componentName, env, commit),
|
|
130
|
-
commit: commit,
|
|
131
|
-
};
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const getFullJobName = (name: string, componentName: string, env?: string) => {
|
|
135
|
-
if (env) {
|
|
136
|
-
return `${env} ${componentName} ${name}`;
|
|
137
|
-
}
|
|
138
|
-
return `${componentName} ${name}`;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const replaceReferences = (
|
|
142
|
-
def: GitlabJobDef,
|
|
143
|
-
componentName: string,
|
|
144
|
-
env?: string
|
|
145
|
-
): GitlabJobDef => {
|
|
146
|
-
return {
|
|
147
|
-
...def,
|
|
148
|
-
needs: def.needs?.map((n) => getFullJobName(n, componentName, env)),
|
|
149
|
-
dependencies: def.dependencies?.map((n) =>
|
|
150
|
-
getFullJobName(n, componentName, env)
|
|
151
|
-
),
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
export const createJobs = (
|
|
156
|
-
envs: string[],
|
|
157
|
-
config: Config,
|
|
158
|
-
componentName: string
|
|
159
|
-
): Record<string, GitlabJobDef> => {
|
|
160
|
-
return envs.reduce((acc, env) => {
|
|
161
|
-
const context = createContext(componentName, config, env);
|
|
162
|
-
const jobs = createRawJobs(context);
|
|
163
|
-
return {
|
|
164
|
-
...acc,
|
|
165
|
-
...jobs.reduce((acc, { name, job, perEnv = true }) => {
|
|
166
|
-
const def = job;
|
|
167
|
-
|
|
168
|
-
return {
|
|
169
|
-
...acc,
|
|
170
|
-
[getFullJobName(name, componentName, perEnv ? env : undefined)]:
|
|
171
|
-
replaceReferences(def, componentName, perEnv ? env : undefined),
|
|
172
|
-
};
|
|
173
|
-
}, {}),
|
|
174
|
-
};
|
|
175
|
-
}, {});
|
|
176
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { createJobs } from "./createChildPipeline";
|
|
2
|
-
import { Config, ENV_TYPES, PipelineTrigger } from "./types/config";
|
|
3
|
-
import { GitlabJobDef } from "./types/gitlab-types";
|
|
4
|
-
|
|
5
|
-
export const createPipeline = async (
|
|
6
|
-
trigger: PipelineTrigger,
|
|
7
|
-
config: Config
|
|
8
|
-
) => {
|
|
9
|
-
const envs = Object.keys(ENV_TYPES).filter(
|
|
10
|
-
(e) => ENV_TYPES[e as keyof typeof ENV_TYPES].trigger === trigger
|
|
11
|
-
);
|
|
12
|
-
const components = Object.keys(config.components);
|
|
13
|
-
|
|
14
|
-
// 2. write the triggering pipeline
|
|
15
|
-
|
|
16
|
-
const jobs = components.reduce<Record<string, GitlabJobDef>>(
|
|
17
|
-
(acc, componentName) => {
|
|
18
|
-
return {
|
|
19
|
-
...acc,
|
|
20
|
-
...createJobs(envs, config, componentName),
|
|
21
|
-
};
|
|
22
|
-
},
|
|
23
|
-
{}
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
const rules = [
|
|
27
|
-
// same as rules "always", but with `changes` to only trigger changed branches
|
|
28
|
-
{ if: "$CI_COMMIT_TAG" },
|
|
29
|
-
{
|
|
30
|
-
if: "$CI_COMMIT_MESSAGE =~ /^chore(release).*/",
|
|
31
|
-
when: "never",
|
|
32
|
-
},
|
|
33
|
-
{ if: "$CI_COMMIT_BRANCH =~ /^[0-9]+.([0-9]+|x).x$/" },
|
|
34
|
-
{
|
|
35
|
-
if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH",
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
{ if: "$CI_MERGE_REQUEST_ID" },
|
|
39
|
-
];
|
|
40
|
-
|
|
41
|
-
const mainPipeline = {
|
|
42
|
-
image:
|
|
43
|
-
"git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG",
|
|
44
|
-
workflow: {
|
|
45
|
-
rules,
|
|
46
|
-
},
|
|
47
|
-
stages: ["setup", "test", "build", "deploy", "verify", "actions"],
|
|
48
|
-
...jobs,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
return mainPipeline;
|
|
52
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { GitlabJobs } from "../types/gitlab-types";
|
|
2
|
-
import { ComponentConfig } from "../types/config";
|
|
3
|
-
import { Context } from "../types/context";
|
|
4
|
-
import { createKubernetesDeployJobs, getKubernetesDefault } from "./kubernetes";
|
|
5
|
-
import { DeployConfig } from "./types";
|
|
6
|
-
|
|
7
|
-
export const deployJobCreators: {
|
|
8
|
-
[type in DeployConfig["type"]]: (context: Context) => GitlabJobs;
|
|
9
|
-
} = {
|
|
10
|
-
kubernetes: createKubernetesDeployJobs,
|
|
11
|
-
serverless: () => [],
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const getDeployDefaults: {
|
|
15
|
-
[type in DeployConfig["type"]]: () => Partial<DeployConfig>;
|
|
16
|
-
} = {
|
|
17
|
-
kubernetes: getKubernetesDefault,
|
|
18
|
-
serverless: () => ({}),
|
|
19
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { GitlabJobs } from "../types/gitlab-types";
|
|
2
|
-
import { Context } from "../types/context";
|
|
3
|
-
import { DeployConfigKubernetes, isOfType } from "./types";
|
|
4
|
-
|
|
5
|
-
export const createKubernetesDeployJobs = (context: Context): GitlabJobs => {
|
|
6
|
-
const deployConfig = context.componentConfig.deploy;
|
|
7
|
-
if (!isOfType(deployConfig, "kubernetes")) {
|
|
8
|
-
// should not happen
|
|
9
|
-
throw new Error("deploy config is not kubernetes");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const defaltKubeValues = {
|
|
13
|
-
application: {
|
|
14
|
-
hostname: context.environment.hostname,
|
|
15
|
-
command: context.componentConfig.build.startCommand,
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
const kubeValues = {
|
|
19
|
-
...defaltKubeValues,
|
|
20
|
-
...deployConfig.values,
|
|
21
|
-
}; // TODO: merge with some defaults
|
|
22
|
-
return [
|
|
23
|
-
{
|
|
24
|
-
name: "deploy-to-kubernetes",
|
|
25
|
-
|
|
26
|
-
job: {
|
|
27
|
-
variables: {
|
|
28
|
-
...context.environment.variables,
|
|
29
|
-
|
|
30
|
-
// TODO: refactor and unify with other stages
|
|
31
|
-
HELM_EXPERIMENTAL_OCI: "1",
|
|
32
|
-
IMAGE_PULL_SECRET: `gitlab-registry-${context.componentName}`,
|
|
33
|
-
KUBE_VALUES: JSON.stringify(kubeValues),
|
|
34
|
-
HELM_GITLAB_CHART_PATH: "catladder/helm-charts",
|
|
35
|
-
HELM_GITLAB_CHART_NAME: "the-panter-chart",
|
|
36
|
-
COMPONENT_NAME: context.componentName,
|
|
37
|
-
// TODO: unify with docker build stage
|
|
38
|
-
IMAGE_TAG: "$CI_COMMIT_SHA",
|
|
39
|
-
HELM_GITLAB_CHART_VERSION: "3.2.0", // TODO, we could actually just ship the chart directly here
|
|
40
|
-
RELEASE_NAME: `${context.fullConfig.customerName}-${context.fullConfig.appName}-$CI_ENVIRONMENT_SLUG`,
|
|
41
|
-
},
|
|
42
|
-
stage: "deploy",
|
|
43
|
-
dependencies: [],
|
|
44
|
-
script: [
|
|
45
|
-
"kubernetesEnsureNamespace",
|
|
46
|
-
"kubernetesCreateSecret",
|
|
47
|
-
"kubernetesDeploy",
|
|
48
|
-
],
|
|
49
|
-
environment: {
|
|
50
|
-
name: context.environment.fullName,
|
|
51
|
-
url: context.environment.url,
|
|
52
|
-
kubernetes: {
|
|
53
|
-
namespace: context.environment.variables.KUBE_NAMESPACE,
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
];
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export const getKubernetesDefault = (): Partial<DeployConfigKubernetes> => {
|
|
62
|
-
return {
|
|
63
|
-
values: {},
|
|
64
|
-
};
|
|
65
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export type DeployConfigBase = {};
|
|
2
|
-
export type DeployConfigKubernetes = {
|
|
3
|
-
type: "kubernetes";
|
|
4
|
-
additionalHelmArgs?: string[];
|
|
5
|
-
values?: {
|
|
6
|
-
application?: {
|
|
7
|
-
resources?: {
|
|
8
|
-
limits?: {
|
|
9
|
-
cpu?: any;
|
|
10
|
-
};
|
|
11
|
-
requests?: {
|
|
12
|
-
cpu?: any;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
} & Record<string, any>;
|
|
16
|
-
} & Record<string, any>;
|
|
17
|
-
} & DeployConfigBase;
|
|
18
|
-
|
|
19
|
-
export type DeployConfigServerless = {
|
|
20
|
-
type: "serverless";
|
|
21
|
-
};
|
|
22
|
-
export type DeployConfig = DeployConfigKubernetes | DeployConfigServerless;
|
|
23
|
-
|
|
24
|
-
export const isOfType = <T extends DeployConfig["type"]>(
|
|
25
|
-
t: DeployConfig,
|
|
26
|
-
type: T
|
|
27
|
-
): t is Extract<DeployConfig, { type: T }> => {
|
|
28
|
-
return t.type === type;
|
|
29
|
-
};
|
package/scripts/magic/index.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Config } from "./types/config";
|
|
2
|
-
|
|
3
|
-
const sampleConfig: Config = {
|
|
4
|
-
customerName: "pan",
|
|
5
|
-
appName: "fonsi",
|
|
6
|
-
components: {
|
|
7
|
-
web: {
|
|
8
|
-
dir: "web",
|
|
9
|
-
build: {
|
|
10
|
-
type: "node",
|
|
11
|
-
},
|
|
12
|
-
deploy: {
|
|
13
|
-
type: "kubernetes",
|
|
14
|
-
values: {
|
|
15
|
-
application: {
|
|
16
|
-
resources: {
|
|
17
|
-
limits: {
|
|
18
|
-
cpu: "100m",
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
vars: {
|
|
25
|
-
public: {
|
|
26
|
-
GOOGLE_TAG_MANAGER_ID: "1234",
|
|
27
|
-
},
|
|
28
|
-
fromComponents: {
|
|
29
|
-
api: {
|
|
30
|
-
API_URL: "ROOT_URL",
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
env: {
|
|
35
|
-
prod: {
|
|
36
|
-
hostname: "fudilo.ch",
|
|
37
|
-
vars: {},
|
|
38
|
-
deploy: {
|
|
39
|
-
type: "kubernetes",
|
|
40
|
-
values: {
|
|
41
|
-
application: {
|
|
42
|
-
resources: {
|
|
43
|
-
limits: {
|
|
44
|
-
cpu: "1000m",
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
myCustomProd: {
|
|
52
|
-
type: "prod",
|
|
53
|
-
hostname: "fudilo2.ch",
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
api: {
|
|
58
|
-
env: {
|
|
59
|
-
prod: {
|
|
60
|
-
hostname: "api.fudilo.ch",
|
|
61
|
-
},
|
|
62
|
-
myCustomProd: {
|
|
63
|
-
type: "prod",
|
|
64
|
-
hostname: "api.fudilo2.ch",
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
build: {
|
|
68
|
-
type: "node",
|
|
69
|
-
},
|
|
70
|
-
deploy: {
|
|
71
|
-
type: "kubernetes",
|
|
72
|
-
},
|
|
73
|
-
dir: "api",
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export default sampleConfig;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { BuildConfig } from "../build/types";
|
|
2
|
-
import { DeployConfig } from "../deploy/types";
|
|
3
|
-
|
|
4
|
-
export type PipelineTrigger = "mainBranch" | "mr" | "taggedRelease";
|
|
5
|
-
|
|
6
|
-
export const ENV_TYPES = {
|
|
7
|
-
dev: {
|
|
8
|
-
trigger: "mainBranch",
|
|
9
|
-
},
|
|
10
|
-
review: {
|
|
11
|
-
trigger: "mr",
|
|
12
|
-
},
|
|
13
|
-
prod: {
|
|
14
|
-
trigger: "taggedRelease",
|
|
15
|
-
},
|
|
16
|
-
stage: {
|
|
17
|
-
trigger: "taggedRelease",
|
|
18
|
-
},
|
|
19
|
-
} as const;
|
|
20
|
-
type EnvType = keyof typeof ENV_TYPES;
|
|
21
|
-
|
|
22
|
-
export type DefaultEnvConfig = {
|
|
23
|
-
deploy: DeployConfig;
|
|
24
|
-
build: BuildConfig;
|
|
25
|
-
vars?: {
|
|
26
|
-
public?: Record<string, any>;
|
|
27
|
-
secret?: Record<string, string>;
|
|
28
|
-
fromComponents?: {
|
|
29
|
-
[otherApp: string]: Record<string, string>;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
type EnvConfig<E extends EnvType = EnvType> = {
|
|
34
|
-
type?: E;
|
|
35
|
-
hostname?: string;
|
|
36
|
-
} & Partial<DefaultEnvConfig>;
|
|
37
|
-
|
|
38
|
-
export type Env = {
|
|
39
|
-
dev?: EnvConfig<"dev">;
|
|
40
|
-
stage?: EnvConfig<"stage">;
|
|
41
|
-
review?: EnvConfig<"review">;
|
|
42
|
-
prod?: EnvConfig<"prod">;
|
|
43
|
-
} & Record<string, EnvConfig>;
|
|
44
|
-
|
|
45
|
-
export type ComponentConfig = {
|
|
46
|
-
env?: Env;
|
|
47
|
-
dir: string;
|
|
48
|
-
} & DefaultEnvConfig;
|
|
49
|
-
|
|
50
|
-
export type Config = {
|
|
51
|
-
customerName: string;
|
|
52
|
-
appName: string;
|
|
53
|
-
components: Record<string, ComponentConfig>;
|
|
54
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ComponentConfig, Config } from "./config";
|
|
2
|
-
|
|
3
|
-
export type Environment = {
|
|
4
|
-
hostname: string;
|
|
5
|
-
fullName: string;
|
|
6
|
-
shortName: string;
|
|
7
|
-
url: string;
|
|
8
|
-
variables: Record<string, string>;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type CommitInfo = {
|
|
12
|
-
refName: string;
|
|
13
|
-
refSlug: string;
|
|
14
|
-
};
|
|
15
|
-
export type Context = {
|
|
16
|
-
componentConfig: ComponentConfig;
|
|
17
|
-
componentName: string;
|
|
18
|
-
fullConfig: Config;
|
|
19
|
-
environment: Environment;
|
|
20
|
-
commit: CommitInfo;
|
|
21
|
-
};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
export type GitlabStage =
|
|
2
|
-
| "setup"
|
|
3
|
-
| "test"
|
|
4
|
-
| "build"
|
|
5
|
-
| "deploy"
|
|
6
|
-
| "verify"
|
|
7
|
-
| "actions";
|
|
8
|
-
|
|
9
|
-
export type Artifacts = {
|
|
10
|
-
paths: string[];
|
|
11
|
-
};
|
|
12
|
-
export type GitlabJobCache = {
|
|
13
|
-
key: string;
|
|
14
|
-
policy?: string;
|
|
15
|
-
paths: string[];
|
|
16
|
-
};
|
|
17
|
-
export type GitlabRule = {
|
|
18
|
-
if: string;
|
|
19
|
-
when?: "always" | "on_success" | "manual" | "never"; // todo
|
|
20
|
-
};
|
|
21
|
-
export type Retry = {
|
|
22
|
-
max: number;
|
|
23
|
-
when: string[];
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type Service = {
|
|
27
|
-
name: string;
|
|
28
|
-
command: string[];
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type GitlabEnvironment = {
|
|
32
|
-
url: string;
|
|
33
|
-
name: string;
|
|
34
|
-
kubernetes?: {
|
|
35
|
-
namespace?: string;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
export type GitlabJobDef = {
|
|
39
|
-
stage: GitlabStage;
|
|
40
|
-
before_script?: string[];
|
|
41
|
-
script: string[];
|
|
42
|
-
interruptible?: boolean;
|
|
43
|
-
needs?: string[];
|
|
44
|
-
rules?: GitlabRule[];
|
|
45
|
-
cache?: GitlabJobCache | GitlabJobCache[];
|
|
46
|
-
artifacts?: Artifacts;
|
|
47
|
-
retry?: Retry;
|
|
48
|
-
services?: Service[];
|
|
49
|
-
image?: string;
|
|
50
|
-
variables?: GitlabVariables;
|
|
51
|
-
dependencies?: string[];
|
|
52
|
-
environment?: GitlabEnvironment;
|
|
53
|
-
allow_failure?: boolean;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export type GitlabVariables = Record<string, string | undefined>;
|
|
57
|
-
|
|
58
|
-
export type GitlabJob = {
|
|
59
|
-
name: string;
|
|
60
|
-
perEnv?: boolean;
|
|
61
|
-
job: GitlabJobDef;
|
|
62
|
-
};
|
|
63
|
-
export type GitlabJobs = GitlabJob[];
|
|
64
|
-
|
|
65
|
-
export type GitlabPipeline = {
|
|
66
|
-
variables: GitlabVariables;
|
|
67
|
-
stages: GitlabStage[];
|
|
68
|
-
jobs: GitlabJobs;
|
|
69
|
-
};
|
package/scripts/magic.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
|
|
3
|
-
import { existsSync, writeFileSync } from "fs";
|
|
4
|
-
import { parse } from "yaml";
|
|
5
|
-
import { PipelineTrigger } from "./magic/types/config";
|
|
6
|
-
import { createPipeline } from "./magic/createPipeline";
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
CI_MERGE_REQUEST_ID,
|
|
10
|
-
CI_COMMIT_TAG,
|
|
11
|
-
CI_COMMIT_BRANCH,
|
|
12
|
-
CI_DEFAULT_BRANCH,
|
|
13
|
-
} = process.env;
|
|
14
|
-
|
|
15
|
-
const isDefaultBranch = CI_COMMIT_BRANCH == CI_DEFAULT_BRANCH;
|
|
16
|
-
const isHotfixBranch = false; // TODO: $CI_COMMIT_BRANCH =~ /^[0-9]+\.([0-9]+|x)\.x$/
|
|
17
|
-
const isMergeRequest = Boolean(CI_MERGE_REQUEST_ID);
|
|
18
|
-
const isTaggedRelease = Boolean(CI_COMMIT_TAG);
|
|
19
|
-
|
|
20
|
-
const fullPath = (ext: string) => process.cwd() + "/catladder." + ext;
|
|
21
|
-
const readConfig = () => {
|
|
22
|
-
const found = ["ts", "js", "yml", "yaml"].find((extension) =>
|
|
23
|
-
existsSync(fullPath(extension))
|
|
24
|
-
);
|
|
25
|
-
if (found) {
|
|
26
|
-
if (found === "ts" || found === "js") {
|
|
27
|
-
return require(fullPath(found)).default;
|
|
28
|
-
} else {
|
|
29
|
-
return parse(fullPath(found));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const trigger: PipelineTrigger | null =
|
|
35
|
-
isMergeRequest || isHotfixBranch
|
|
36
|
-
? "mr"
|
|
37
|
-
: isDefaultBranch
|
|
38
|
-
? "mainBranch"
|
|
39
|
-
: isTaggedRelease
|
|
40
|
-
? "taggedRelease"
|
|
41
|
-
: null;
|
|
42
|
-
if (trigger) {
|
|
43
|
-
const config = readConfig();
|
|
44
|
-
createPipeline(trigger, config).then((mainPipeline) => {
|
|
45
|
-
writeFileSync(`__pipeline.yml`, JSON.stringify(mainPipeline, null, 2), {
|
|
46
|
-
encoding: "utf-8",
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
} else {
|
|
50
|
-
throw new Error("no matching trigger");
|
|
51
|
-
}
|