@catladder/pipeline 0.0.7 → 1.0.2
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/{scripts/magic/types → types}/index.d.ts +1 -1
- 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 -9
- package/src/build/base/constants.ts +7 -0
- package/src/build/base/createBuildJob.ts +46 -0
- package/{scripts/magic → src}/build/docker.ts +15 -2
- 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} +5 -4
- 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/createSamplePipeline.d.ts +0 -2
- package/dist/scripts/createSamplePipeline.js +0 -14
- package/dist/scripts/magic/build/docker.d.ts +0 -2
- package/dist/scripts/magic/build/docker.js +0 -68
- package/dist/scripts/magic/build/index.d.ts +0 -9
- package/dist/scripts/magic/build/index.js +0 -12
- package/dist/scripts/magic/build/node.d.ts +0 -6
- package/dist/scripts/magic/build/node.js +0 -150
- package/dist/scripts/magic/build/types.d.ts +0 -18
- package/dist/scripts/magic/build/types.js +0 -7
- package/dist/scripts/magic/context/index.d.ts +0 -3
- package/dist/scripts/magic/context/index.js +0 -122
- package/dist/scripts/magic/createChildPipeline/index.d.ts +0 -3
- package/dist/scripts/magic/createChildPipeline/index.js +0 -68
- package/dist/scripts/magic/createPipeline.d.ts +0 -14
- package/dist/scripts/magic/createPipeline.js +0 -80
- package/dist/scripts/magic/deploy/index.d.ts +0 -9
- package/dist/scripts/magic/deploy/index.js +0 -12
- package/dist/scripts/magic/deploy/kubernetes.d.ts +0 -5
- package/dist/scripts/magic/deploy/kubernetes.js +0 -62
- package/dist/scripts/magic/deploy/types.d.ts +0 -41
- package/dist/scripts/magic/deploy/types.js +0 -7
- package/dist/scripts/magic/index.d.ts +0 -2
- package/dist/scripts/magic/index.js +0 -16
- package/dist/scripts/magic/sample-config.d.ts +0 -3
- package/dist/scripts/magic/sample-config.js +0 -77
- package/dist/scripts/magic/tests/createPipeline.test.d.ts +0 -1
- package/dist/scripts/magic/tests/createPipeline.test.js +0 -89
- package/dist/scripts/magic/types/config.d.ts +0 -49
- package/dist/scripts/magic/types/config.js +0 -17
- package/dist/scripts/magic/types/context.d.ts +0 -19
- package/dist/scripts/magic/types/context.js +0 -2
- package/dist/scripts/magic/types/gitlab-types.d.ts +0 -57
- package/dist/scripts/magic/types/gitlab-types.js +0 -2
- package/dist/scripts/magic/types/index.js +0 -15
- package/dist/scripts/magic.d.ts +0 -2
- package/dist/scripts/magic.js +0 -43
- package/dist/scripts/monorepoGenerate.d.ts +0 -2
- package/dist/scripts/monorepoGenerate.js +0 -164
- package/dist/scripts/printAllValues.d.ts +0 -2
- package/dist/scripts/printAllValues.js +0 -58
- package/dist/scripts/printBuildEnv.d.ts +0 -2
- package/dist/scripts/printBuildEnv.js +0 -77
- package/dist/scripts/utils/extractAllValues.d.ts +0 -1
- package/dist/scripts/utils/extractAllValues.js +0 -78
- package/dist/scripts/utils/extractBuildEnv.d.ts +0 -5
- package/dist/scripts/utils/extractBuildEnv.js +0 -152
- package/dist/scripts/utils/extractValuesFromEnvVars.d.ts +0 -2
- package/dist/scripts/utils/extractValuesFromEnvVars.js +0 -63
- package/dist/scripts/utils/extractValuesFromMr.d.ts +0 -2
- package/dist/scripts/utils/extractValuesFromMr.js +0 -86
- package/dist/tests/extractValuesFromMr.test.d.ts +0 -1
- package/dist/tests/extractValuesFromMr.test.js +0 -68
- 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 -18
- package/scripts/magic/build/node.ts +0 -143
- package/scripts/magic/build/types.ts +0 -21
- package/scripts/magic/context/index.ts +0 -127
- package/scripts/magic/createChildPipeline/index.ts +0 -60
- 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,60 +0,0 @@
|
|
|
1
|
-
import { merge } from "lodash";
|
|
2
|
-
import slugify from "slugify";
|
|
3
|
-
import { buildJobCreators } from "../build";
|
|
4
|
-
import { createContext } from "../context";
|
|
5
|
-
import { deployJobCreators } from "../deploy";
|
|
6
|
-
import { Config } from "../types/config";
|
|
7
|
-
import { CommitInfo, Context, Environment } from "../types/context";
|
|
8
|
-
import { GitlabJobDef, GitlabJobs } from "../types/gitlab-types";
|
|
9
|
-
|
|
10
|
-
const createRawJobs = (context: Context): GitlabJobs => {
|
|
11
|
-
const buildJobs =
|
|
12
|
-
buildJobCreators[context.componentConfig.build.type](context);
|
|
13
|
-
const deployJobs =
|
|
14
|
-
deployJobCreators[context.componentConfig.deploy.type](context);
|
|
15
|
-
|
|
16
|
-
return [...buildJobs, ...deployJobs];
|
|
17
|
-
};
|
|
18
|
-
const getFullJobName = (name: string, componentName: string, env?: string) => {
|
|
19
|
-
if (env) {
|
|
20
|
-
return `${env} ${componentName} ${name}`;
|
|
21
|
-
}
|
|
22
|
-
return `${componentName} ${name}`;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const replaceReferences = (
|
|
26
|
-
def: GitlabJobDef,
|
|
27
|
-
componentName: string,
|
|
28
|
-
env?: string
|
|
29
|
-
): GitlabJobDef => {
|
|
30
|
-
return {
|
|
31
|
-
...def,
|
|
32
|
-
needs: def.needs?.map((n) => getFullJobName(n, componentName, env)),
|
|
33
|
-
dependencies: def.dependencies?.map((n) =>
|
|
34
|
-
getFullJobName(n, componentName, env)
|
|
35
|
-
),
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const createJobs = (
|
|
40
|
-
envs: string[],
|
|
41
|
-
config: Config,
|
|
42
|
-
componentName: string
|
|
43
|
-
): Record<string, GitlabJobDef> => {
|
|
44
|
-
return envs.reduce((acc, env) => {
|
|
45
|
-
const context = createContext(componentName, config, env);
|
|
46
|
-
const jobs = createRawJobs(context);
|
|
47
|
-
return {
|
|
48
|
-
...acc,
|
|
49
|
-
...jobs.reduce((acc, { name, job, perEnv = true }) => {
|
|
50
|
-
const def = job;
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
...acc,
|
|
54
|
-
[getFullJobName(name, componentName, perEnv ? env : undefined)]:
|
|
55
|
-
replaceReferences(def, componentName, perEnv ? env : undefined),
|
|
56
|
-
};
|
|
57
|
-
}, {}),
|
|
58
|
-
};
|
|
59
|
-
}, {});
|
|
60
|
-
};
|
|
@@ -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
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
|
|
3
|
-
import { readdirSync, readFileSync, lstatSync, existsSync } from "fs";
|
|
4
|
-
import { join } from "path";
|
|
5
|
-
import { parse } from "yaml";
|
|
6
|
-
import yargs from "yargs";
|
|
7
|
-
|
|
8
|
-
import { hideBin } from "yargs/helpers";
|
|
9
|
-
import { extractBuildEnv } from "./utils/extractBuildEnv";
|
|
10
|
-
type Type = "test" | "deploy";
|
|
11
|
-
const args = yargs(hideBin(process.argv)).array("env").argv as Record<
|
|
12
|
-
string,
|
|
13
|
-
unknown
|
|
14
|
-
>;
|
|
15
|
-
|
|
16
|
-
const thisGitlabCi = parse(
|
|
17
|
-
readFileSync(".gitlab-ci.yml", { encoding: "utf-8" })
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
const subcis = readdirSync(".")
|
|
21
|
-
.filter((file) => lstatSync(file).isDirectory())
|
|
22
|
-
.map((dir) => ({
|
|
23
|
-
dirname: dir,
|
|
24
|
-
ci: join(dir, ".gitlab-ci.yml"),
|
|
25
|
-
}))
|
|
26
|
-
.filter(({ ci }) => existsSync(ci));
|
|
27
|
-
|
|
28
|
-
const makeConfig = async ({
|
|
29
|
-
subapp,
|
|
30
|
-
type,
|
|
31
|
-
ci,
|
|
32
|
-
env,
|
|
33
|
-
}: {
|
|
34
|
-
subapp: string;
|
|
35
|
-
type: Type;
|
|
36
|
-
env: string;
|
|
37
|
-
ci: string;
|
|
38
|
-
}) => {
|
|
39
|
-
const changes = [subapp + "/**/*"];
|
|
40
|
-
const rules = [
|
|
41
|
-
// same as rules "always", but with `changes` to only trigger changed branches
|
|
42
|
-
{ if: "$CI_COMMIT_TAG" },
|
|
43
|
-
{
|
|
44
|
-
if: "$CI_COMMIT_MESSAGE =~ /^chore(release).*/",
|
|
45
|
-
when: "never",
|
|
46
|
-
},
|
|
47
|
-
{ if: "$CI_COMMIT_BRANCH =~ /^[0-9]+.([0-9]+|x).x$/" },
|
|
48
|
-
{
|
|
49
|
-
if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH",
|
|
50
|
-
changes,
|
|
51
|
-
},
|
|
52
|
-
// add it manually when no changes
|
|
53
|
-
{
|
|
54
|
-
if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH",
|
|
55
|
-
when: "manual",
|
|
56
|
-
},
|
|
57
|
-
{ if: "$CI_MERGE_REQUEST_ID", changes },
|
|
58
|
-
// add it manually when no changes
|
|
59
|
-
{ if: "$CI_MERGE_REQUEST_ID", when: "manual" },
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
variables: {
|
|
64
|
-
// merge
|
|
65
|
-
...thisGitlabCi.variables,
|
|
66
|
-
APP_DIR: subapp,
|
|
67
|
-
VALUES_DIR: subapp,
|
|
68
|
-
COMPONENT_NAME: subapp,
|
|
69
|
-
PARENT_PIPELINE_ID: "$CI_PIPELINE_ID",
|
|
70
|
-
[type.toUpperCase() + "_ONLY"]: "1",
|
|
71
|
-
...(await extractBuildEnv(subapp, env)),
|
|
72
|
-
},
|
|
73
|
-
stage: type,
|
|
74
|
-
rules: rules,
|
|
75
|
-
trigger: {
|
|
76
|
-
include: ci,
|
|
77
|
-
strategy: "depend",
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
const generateSubPipeline = async (type: Type, envs: string[]) => {
|
|
82
|
-
return await envs.reduce(async (acc, env) => {
|
|
83
|
-
return {
|
|
84
|
-
...(await acc),
|
|
85
|
-
...(await subcis.reduce(
|
|
86
|
-
async (inneracc, { dirname, ci }) => ({
|
|
87
|
-
...(await inneracc),
|
|
88
|
-
|
|
89
|
-
[`${env}-${dirname} ${type}`]: await makeConfig({
|
|
90
|
-
subapp: dirname,
|
|
91
|
-
ci,
|
|
92
|
-
type,
|
|
93
|
-
env,
|
|
94
|
-
}),
|
|
95
|
-
}),
|
|
96
|
-
{} as Promise<Record<string, unknown>>
|
|
97
|
-
)),
|
|
98
|
-
};
|
|
99
|
-
}, {} as Promise<Record<string, unknown>>);
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
generateSubPipeline(args.t as Type, args.env as string[]).then((p) =>
|
|
103
|
-
console.log(JSON.stringify(p, null, 2))
|
|
104
|
-
);
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
|
|
3
|
-
import yargs from "yargs";
|
|
4
|
-
import { hideBin } from "yargs/helpers";
|
|
5
|
-
import { extractAllValues } from "./utils/extractAllValues";
|
|
6
|
-
|
|
7
|
-
const args = yargs(hideBin(process.argv)).argv as Record<string, unknown>;
|
|
8
|
-
|
|
9
|
-
extractAllValues(args.d as string, args.e as string)
|
|
10
|
-
.then(async (values) => {
|
|
11
|
-
console.log(JSON.stringify(values, null, 2) ?? "");
|
|
12
|
-
})
|
|
13
|
-
.catch((e) => {
|
|
14
|
-
console.error("could not extract values", {
|
|
15
|
-
error: e,
|
|
16
|
-
});
|
|
17
|
-
});
|
package/scripts/printBuildEnv.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
|
|
3
|
-
import { isObject } from "lodash";
|
|
4
|
-
import yargs from "yargs";
|
|
5
|
-
import { hideBin } from "yargs/helpers";
|
|
6
|
-
import { extractBuildEnv } from "./utils/extractBuildEnv";
|
|
7
|
-
|
|
8
|
-
const args = yargs(hideBin(process.argv)).argv as Record<string, unknown>;
|
|
9
|
-
|
|
10
|
-
extractBuildEnv(args.d as string, args.e as string)
|
|
11
|
-
.then(async (values) => {
|
|
12
|
-
Object.entries(values).forEach(([key, value]) =>
|
|
13
|
-
console.log(
|
|
14
|
-
`${key}: "${isObject(value) ? JSON.stringify(value) : value}"`
|
|
15
|
-
)
|
|
16
|
-
);
|
|
17
|
-
})
|
|
18
|
-
.catch((e) => {
|
|
19
|
-
console.error("could not extract values", {
|
|
20
|
-
error: e,
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "fs";
|
|
2
|
-
import { merge } from "lodash";
|
|
3
|
-
import { parse } from "yaml";
|
|
4
|
-
import { extractValuesFromEnvVars } from "./extractValuesFromEnvVars";
|
|
5
|
-
import { extractValuesFromMr } from "./extractValuesFromMr";
|
|
6
|
-
|
|
7
|
-
const { CI_PROJECT_ID, CI_MERGE_REQUEST_IID } = process.env;
|
|
8
|
-
|
|
9
|
-
const readYaml = (path: string) => {
|
|
10
|
-
try {
|
|
11
|
-
return parse(readFileSync(path, { encoding: "utf-8" }));
|
|
12
|
-
} catch (e) {
|
|
13
|
-
return {};
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const extractAllValues = async (
|
|
18
|
-
appDirectory: string,
|
|
19
|
-
env: string | null
|
|
20
|
-
) => {
|
|
21
|
-
const valuesFromEnvVars = extractValuesFromEnvVars();
|
|
22
|
-
const valuesDefault = readYaml(appDirectory + "/values.yml");
|
|
23
|
-
const valuesEnv = env
|
|
24
|
-
? readYaml(appDirectory + "/values-" + env + ".yml")
|
|
25
|
-
: {};
|
|
26
|
-
const valuesFromMR =
|
|
27
|
-
CI_PROJECT_ID && CI_MERGE_REQUEST_IID
|
|
28
|
-
? await extractValuesFromMr(CI_PROJECT_ID, Number(CI_MERGE_REQUEST_IID))
|
|
29
|
-
: {};
|
|
30
|
-
|
|
31
|
-
return merge({}, valuesFromEnvVars, valuesDefault, valuesEnv, valuesFromMR);
|
|
32
|
-
};
|