@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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { PipelineTrigger, ComponentConfig, Config, EnvType } from "./config";
|
|
2
|
+
|
|
3
|
+
export type Environment = {
|
|
4
|
+
hostname: string;
|
|
5
|
+
fullName: string;
|
|
6
|
+
shortName: string;
|
|
7
|
+
slug: string;
|
|
8
|
+
url: string;
|
|
9
|
+
/**
|
|
10
|
+
* env vars contain all build-time env vars. secrets have to be resolved (they are stored in gitlab)
|
|
11
|
+
*/
|
|
12
|
+
envVars: Record<string, string>;
|
|
13
|
+
envType: EnvType;
|
|
14
|
+
secretEnvVarKeys: string[];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type CommitInfo = {
|
|
18
|
+
refName: string;
|
|
19
|
+
refSlug: string;
|
|
20
|
+
trigger: PipelineTrigger;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type YarnInfo = {
|
|
24
|
+
version: string;
|
|
25
|
+
workspaces: { location: string }[];
|
|
26
|
+
isClassic: boolean;
|
|
27
|
+
componentIsInWorkspace: boolean;
|
|
28
|
+
};
|
|
29
|
+
export type Context = {
|
|
30
|
+
componentName: string;
|
|
31
|
+
componentConfig: ComponentConfig;
|
|
32
|
+
fullConfig: Config;
|
|
33
|
+
environment: Environment;
|
|
34
|
+
commitInfo?: CommitInfo;
|
|
35
|
+
yarnInfo?: YarnInfo;
|
|
36
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export type Artifacts = {
|
|
2
|
+
paths: string[];
|
|
3
|
+
};
|
|
4
|
+
export type GitlabJobCache = {
|
|
5
|
+
key: string;
|
|
6
|
+
policy?: string;
|
|
7
|
+
paths: string[];
|
|
8
|
+
};
|
|
9
|
+
export type GitlabRule = {
|
|
10
|
+
if?: string;
|
|
11
|
+
when?: "always" | "on_success" | "manual" | "never"; // todo
|
|
12
|
+
allow_failure?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type Retry = {
|
|
15
|
+
max: number;
|
|
16
|
+
when: string[];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type Service = {
|
|
20
|
+
name: string;
|
|
21
|
+
command: string[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type GitlabEnvironment = {
|
|
25
|
+
url: string;
|
|
26
|
+
name: string;
|
|
27
|
+
kubernetes?: {
|
|
28
|
+
namespace?: string;
|
|
29
|
+
};
|
|
30
|
+
action?: "stop" | "start" | "prepare"; // defaults to start
|
|
31
|
+
on_stop?: string; // other job to run on stop
|
|
32
|
+
auto_stop_in?: string;
|
|
33
|
+
};
|
|
34
|
+
export type GitlabJobDef = {
|
|
35
|
+
stage: string;
|
|
36
|
+
before_script?: string[];
|
|
37
|
+
script: (string | undefined)[];
|
|
38
|
+
interruptible?: boolean;
|
|
39
|
+
needs?: Array<string | { job: string; artifacts: boolean }>;
|
|
40
|
+
rules?: GitlabRule[];
|
|
41
|
+
cache?: GitlabJobCache | GitlabJobCache[];
|
|
42
|
+
artifacts?: Artifacts;
|
|
43
|
+
retry?: Retry;
|
|
44
|
+
services?: Service[];
|
|
45
|
+
image?: string;
|
|
46
|
+
variables?: GitlabVariables;
|
|
47
|
+
dependencies?: string[];
|
|
48
|
+
environment?: GitlabEnvironment;
|
|
49
|
+
allow_failure?: boolean;
|
|
50
|
+
trigger?: {
|
|
51
|
+
strategy: "depend";
|
|
52
|
+
include: Array<{
|
|
53
|
+
artifact: string;
|
|
54
|
+
job: string;
|
|
55
|
+
}>;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const GITLAB_BASE_STAGES = [
|
|
60
|
+
"setup",
|
|
61
|
+
"test",
|
|
62
|
+
"build",
|
|
63
|
+
"deploy",
|
|
64
|
+
"verify",
|
|
65
|
+
"stop",
|
|
66
|
+
] as const;
|
|
67
|
+
export type GitlabBaseStage = typeof GITLAB_BASE_STAGES[number];
|
|
68
|
+
export type GitlabVariables = Record<string, string | undefined>;
|
|
69
|
+
|
|
70
|
+
export type GitlabJob = {
|
|
71
|
+
/**
|
|
72
|
+
* the name of the job (without any env or app prefix and suffix)
|
|
73
|
+
*/
|
|
74
|
+
name: string;
|
|
75
|
+
/**
|
|
76
|
+
* envMode sets the behavior of the job regarding multiple envs:
|
|
77
|
+
* - none: the job does not run per env, but once for all envs
|
|
78
|
+
* - jobPerEnv: the job runs once per env
|
|
79
|
+
* - stagePerEnv: the job runs once per env and is organized in its own stage. This mproves usability in gitlab, but works the same as `jobPerEnv`
|
|
80
|
+
*/
|
|
81
|
+
envMode: "jobPerEnv" | "stagePerEnv" | "none";
|
|
82
|
+
job: GitlabJobDef;
|
|
83
|
+
needsStages?: {
|
|
84
|
+
stage: GitlabBaseStage;
|
|
85
|
+
artifacts?: boolean;
|
|
86
|
+
}[];
|
|
87
|
+
};
|
|
88
|
+
export type GitlabJobs = GitlabJob[];
|
|
89
|
+
|
|
90
|
+
export type GitlabPipeline = {
|
|
91
|
+
variables: GitlabVariables;
|
|
92
|
+
stages: string[];
|
|
93
|
+
jobs: GitlabJobs;
|
|
94
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isNil } from "lodash";
|
|
2
|
+
|
|
3
|
+
export function notNil<TValue>(
|
|
4
|
+
value: TValue | null | undefined
|
|
5
|
+
): value is TValue {
|
|
6
|
+
return value !== null && value !== undefined;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const ensureArray = <T>(s: T | T[]): T[] | null =>
|
|
10
|
+
isNil(s) ? null : Array.isArray(s) ? s : [s];
|
package/tsconfig.json
CHANGED
package/Dockerfile
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
FROM node:14
|
|
3
|
-
|
|
4
|
-
RUN rm /bin/sh && \
|
|
5
|
-
ln -s /bin/bash /bin/sh && \
|
|
6
|
-
mkdir -p /root/.nvm
|
|
7
|
-
|
|
8
|
-
# add sources
|
|
9
|
-
# Google Chrome (for testing purposes)
|
|
10
|
-
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
|
|
11
|
-
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
|
|
12
|
-
|
|
13
|
-
# install some sources
|
|
14
|
-
RUN apt-get update && apt-get install -y \
|
|
15
|
-
git ssh-client \
|
|
16
|
-
openssl \
|
|
17
|
-
curl \
|
|
18
|
-
bash \
|
|
19
|
-
apt-transport-https \
|
|
20
|
-
ca-certificates \
|
|
21
|
-
git \
|
|
22
|
-
gettext-base \
|
|
23
|
-
libxss1 \
|
|
24
|
-
google-chrome-stable
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
# set high timeout for yarn, see https://github.com/dhis2/notes/issues/29
|
|
29
|
-
RUN yarn config set network-timeout 600000 -g
|
|
30
|
-
|
|
31
|
-
# add semantic release
|
|
32
|
-
RUN yarn global add \
|
|
33
|
-
semantic-release \
|
|
34
|
-
@semantic-release/commit-analyzer \
|
|
35
|
-
@semantic-release/release-notes-generator \
|
|
36
|
-
@semantic-release/git \
|
|
37
|
-
@semantic-release/changelog \
|
|
38
|
-
@semantic-release/gitlab;
|
|
39
|
-
|
|
40
|
-
# kubernetes & helm
|
|
41
|
-
ENV KUBERNETES_VERSION 1.18.20
|
|
42
|
-
RUN curl -L -o /usr/bin/kubectl "https://storage.googleapis.com/kubernetes-release/release/v${KUBERNETES_VERSION}/bin/linux/amd64/kubectl" ;\
|
|
43
|
-
chmod +x /usr/bin/kubectl ;\
|
|
44
|
-
kubectl version --client
|
|
45
|
-
|
|
46
|
-
# helm 2 for legacy reasons
|
|
47
|
-
ENV HELM_2_VERSION 2.14.3
|
|
48
|
-
RUN curl "https://get.helm.sh/helm-v${HELM_2_VERSION}-linux-amd64.tar.gz" | tar zx ;\
|
|
49
|
-
mv linux-amd64/helm /usr/bin/ ;\
|
|
50
|
-
helm version --client
|
|
51
|
-
RUN cp /usr/bin/helm /usr/bin/helm2
|
|
52
|
-
# helm3
|
|
53
|
-
ENV HELM_VERSION 3.6.3
|
|
54
|
-
RUN curl "https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz" | tar zx ;\
|
|
55
|
-
mv linux-amd64/helm /usr/bin/helm3 ;\
|
|
56
|
-
helm3 version --client
|
|
57
|
-
|
|
58
|
-
# install nvm && some common node versions
|
|
59
|
-
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash && \
|
|
60
|
-
source /root/.nvm/nvm.sh && \
|
|
61
|
-
chmod +x /root/.nvm/nvm.sh && \
|
|
62
|
-
/root/.nvm/nvm.sh install 10 && \
|
|
63
|
-
/root/.nvm/nvm.sh install 12 && \
|
|
64
|
-
/root/.nvm/nvm.sh install 14 && \
|
|
65
|
-
/root/.nvm/nvm.sh install 16
|
|
66
|
-
|
|
67
|
-
# add meteor (used by some apps)
|
|
68
|
-
# install also additional used released (should theoretically speed up ci-builds)
|
|
69
|
-
RUN curl https://install.meteor.com/ | sh && \
|
|
70
|
-
meteor update --release 2.2 --allow-superuser
|
|
71
|
-
|
|
72
|
-
# scripts
|
|
73
|
-
|
|
74
|
-
RUN yarn global add ts-node typescript
|
|
75
|
-
|
|
76
|
-
COPY ./scripts /scripts
|
|
77
|
-
RUN chmod +x /scripts/*
|
|
78
|
-
|
|
79
|
-
COPY package.json /scripts/
|
|
80
|
-
COPY yarn.lock /scripts/
|
|
81
|
-
|
|
82
|
-
WORKDIR /scripts
|
|
83
|
-
RUN yarn
|
|
84
|
-
ENV PATH="/scripts:${PATH}"
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
exports.__esModule = true;
|
|
13
|
-
exports.createPipeline = void 0;
|
|
14
|
-
var createPipeline_1 = require("./createPipeline");
|
|
15
|
-
__createBinding(exports, createPipeline_1, "createPipeline");
|
|
16
|
-
__exportStar(require("./types"), exports);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
import { writeFileSync } from "fs";
|
|
3
|
-
import { createPipeline } from "./magic/createPipeline";
|
|
4
|
-
import sampleConfig from "./magic/sample-config";
|
|
5
|
-
|
|
6
|
-
createPipeline("taggedRelease", sampleConfig).then((mainPipeline) => {
|
|
7
|
-
writeFileSync(`__pipeline.yml`, JSON.stringify(mainPipeline, null, 2), {
|
|
8
|
-
encoding: "utf-8",
|
|
9
|
-
});
|
|
10
|
-
});
|
package/scripts/getCommitInfo
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
export BUILD_TAG="$(git describe --tags || git rev-parse HEAD)"
|
|
4
|
-
export BUILD_ID="$BUILD_TAG"
|
|
5
|
-
export BUILD_COMMIT="$(git rev-parse HEAD)"
|
|
6
|
-
export BUILD_TIME="$(date)"
|
|
7
|
-
echo "BUILD_TAG=$BUILD_TAG" >>build.env
|
|
8
|
-
echo "BUILD_ID=$BUILD_ID" >>build.env
|
|
9
|
-
echo "BUILD_COMMIT=$BUILD_COMMIT" >>build.env
|
|
10
|
-
echo "BUILD_TIME=$BUILD_TIME" >>build.env
|
|
11
|
-
echo '{"id":"'$BUILD_ID'","commit":"'$BUILD_COMMIT'","tag":"'$BUILD_TAG'","time":"'$BUILD_TIME'"}' >__build_info.json
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
echo "KUBE_NAMESPACE: '$KUBE_NAMESPACE', IMAGE_PULL_SECRET: '$IMAGE_PULL_SECRET'"
|
|
3
|
-
kubectl create secret -n "$KUBE_NAMESPACE" \
|
|
4
|
-
docker-registry $IMAGE_PULL_SECRET \
|
|
5
|
-
--docker-server="$CI_REGISTRY" \
|
|
6
|
-
--docker-username="${CI_DEPLOY_USER:-$CI_REGISTRY_USER}" \
|
|
7
|
-
--docker-password="${CI_DEPLOY_PASSWORD:-$CI_REGISTRY_PASSWORD}" \
|
|
8
|
-
--docker-email="$GITLAB_USER_EMAIL" \
|
|
9
|
-
-o yaml --dry-run | kubectl replace -n "$KUBE_NAMESPACE" --force -f -
|
package/scripts/kubernetesDelete
DELETED
package/scripts/kubernetesDeploy
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
echo "Deploy to kubernetes"
|
|
4
|
-
echo "Release: $RELEASE_NAME"
|
|
5
|
-
echo "URL (canonical): $HOST_CANONICAL"
|
|
6
|
-
#helm3 init --client-only --stable-repo-url=https://charts.helm.sh/stable
|
|
7
|
-
helm3 chart pull $CI_REGISTRY/$HELM_GITLAB_CHART_PATH/$HELM_GITLAB_CHART_NAME:v$HELM_GITLAB_CHART_VERSION
|
|
8
|
-
helm3 chart export $CI_REGISTRY/$HELM_GITLAB_CHART_PATH/$HELM_GITLAB_CHART_NAME:v$HELM_GITLAB_CHART_VERSION -d /tmp/
|
|
9
|
-
# use helmArgs defined in variables
|
|
10
|
-
helmArgsEvaluated=$(echo $helmArgs | envsubst)
|
|
11
|
-
|
|
12
|
-
# this bash-brainfuck simply splits $helmArgs by newline to an array...
|
|
13
|
-
readarray -t helmArgsArray <<<"$helmArgsEvaluated"
|
|
14
|
-
|
|
15
|
-
#Log the time until selfdestruct in case of review environment
|
|
16
|
-
if [[ ${ENV_SHORT} == "review" ]]; then echo "NOTE - This deployment will stop itself after 2 weeks"; fi
|
|
17
|
-
|
|
18
|
-
echo "all values"
|
|
19
|
-
echo "$KUBE_VALUES"
|
|
20
|
-
echo $KUBE_VALUES >__all_values.yml
|
|
21
|
-
|
|
22
|
-
echo "doing helm upgrade"
|
|
23
|
-
helm3 upgrade --install "$RELEASE_NAME" /tmp/$HELM_GITLAB_CHART_NAME \
|
|
24
|
-
--wait \
|
|
25
|
-
--timeout 15m0s \
|
|
26
|
-
--cleanup-on-fail \
|
|
27
|
-
--set global.componentName="$KUBE_APP_NAME" \
|
|
28
|
-
--set global.ENV_SHORT="$ENV_SHORT" \
|
|
29
|
-
--set global.CI_COMMIT_REF_SLUG="$CI_COMMIT_REF_SLUG" \
|
|
30
|
-
--set global.BUILD_ID="$BUILD_ID" \
|
|
31
|
-
--set image.repository="$CI_REGISTRY_IMAGE" \
|
|
32
|
-
--set image.pullSecret="$IMAGE_PULL_SECRET" \
|
|
33
|
-
--set image.name="$COMPONENT_NAME" \
|
|
34
|
-
--set image.tag="$IMAGE_TAG" \
|
|
35
|
-
--set image.pullPolicy=IfNotPresent \
|
|
36
|
-
--set storybook.enabled=$STORYBOOK \
|
|
37
|
-
--set application.hostCanonical="$HOST_CANONICAL" \
|
|
38
|
-
--set mongodb.enabled=$MONGODB_ENABLED \
|
|
39
|
-
--set mongodb.backup.enabled=$MONGODB_BACKUP_ENABLED \
|
|
40
|
-
--set mongodb-replicaset.replicas=$MONGODB_REPLICAS \
|
|
41
|
-
--set mongodb-replicaset.fullnameOverride=$KUBE_APP_NAME-mongodb-replicaset \
|
|
42
|
-
--set mongodb-replicaset.persistentVolume.storageClass="$MONGODB_STORAGE_CLASS" \
|
|
43
|
-
--set mailhog.fullnameOverride=$KUBE_APP_NAME-mailhog \
|
|
44
|
-
--set prisma.enabled=$PRISMA_ENABLED \
|
|
45
|
-
--set gitlab.visualReviewEnabled="$GITLAB_VISUAL_REVIEW_ENABLED" \
|
|
46
|
-
--set gitlab.app="$CI_PROJECT_PATH_SLUG" \
|
|
47
|
-
--set gitlab.projectPath="$CI_PROJECT_PATH" \
|
|
48
|
-
--set gitlab.mergeRequestId="$CI_MERGE_REQUEST_IID" \
|
|
49
|
-
--set gitlab.projectId="$CI_PROJECT_ID" \
|
|
50
|
-
--set gitlab.env="$CI_ENVIRONMENT_SLUG" \
|
|
51
|
-
--set namespace="$KUBE_NAMESPACE" \
|
|
52
|
-
--namespace="$KUBE_NAMESPACE" \
|
|
53
|
-
${helmArgsArray[@]} \
|
|
54
|
-
--values __all_values.yml
|
|
55
|
-
echo "Deployment successful 😻"
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { GitlabJobs } from "../types/gitlab-types";
|
|
2
|
-
import { Context } from "../types/context";
|
|
3
|
-
import { createNodeJobs, getNodeDefaults } from "./node";
|
|
4
|
-
import { BuildConfig } from "./types";
|
|
5
|
-
|
|
6
|
-
export const buildJobCreators: {
|
|
7
|
-
[type in BuildConfig["type"]]: (context: Context) => GitlabJobs;
|
|
8
|
-
} = {
|
|
9
|
-
node: createNodeJobs,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const getBuildDefaults: {
|
|
13
|
-
[type in BuildConfig["type"]]: () => Partial<BuildConfig>;
|
|
14
|
-
} = {
|
|
15
|
-
node: getNodeDefaults,
|
|
16
|
-
};
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
GitlabJobDef,
|
|
3
|
-
GitlabJobCache,
|
|
4
|
-
GitlabJobs,
|
|
5
|
-
Retry,
|
|
6
|
-
} from "../types/gitlab-types";
|
|
7
|
-
import { Context } from "../types/context";
|
|
8
|
-
import { createDockerBuildJob } from "./docker";
|
|
9
|
-
import { BuildConfigNode, isOfType } from "./types";
|
|
10
|
-
|
|
11
|
-
const baseRetry: Retry = {
|
|
12
|
-
max: 2,
|
|
13
|
-
when: ["runner_system_failure", "stuck_or_timeout_failure"],
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const getYarnInstall = (context: Context) => [
|
|
17
|
-
`cd ${context.componentConfig.dir}`,
|
|
18
|
-
"if [ -f ./.nvmrc ]; then source /root/.nvm/nvm.sh && nvm install <<< .nvmrc; fi",
|
|
19
|
-
"yarn install --frozen-lockfile",
|
|
20
|
-
];
|
|
21
|
-
const createNodeTestJobs = (context: Context): GitlabJobs => {
|
|
22
|
-
const cache: GitlabJobCache[] = [
|
|
23
|
-
{
|
|
24
|
-
key: "node-modules",
|
|
25
|
-
policy: "pull-push",
|
|
26
|
-
paths: ["node_modules", "**/node_modules/"],
|
|
27
|
-
},
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
const base: Omit<GitlabJobDef, "script"> = {
|
|
31
|
-
variables: {
|
|
32
|
-
APP_PATH: context.componentConfig.dir,
|
|
33
|
-
},
|
|
34
|
-
cache,
|
|
35
|
-
stage: "test",
|
|
36
|
-
interruptible: true,
|
|
37
|
-
needs: [],
|
|
38
|
-
retry: baseRetry,
|
|
39
|
-
};
|
|
40
|
-
const yarnInstall = getYarnInstall(context);
|
|
41
|
-
return [
|
|
42
|
-
{
|
|
43
|
-
name: "audit",
|
|
44
|
-
perEnv: false,
|
|
45
|
-
job: {
|
|
46
|
-
...base,
|
|
47
|
-
script: [...yarnInstall, "yarn audit"],
|
|
48
|
-
allow_failure: true,
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
name: "lint",
|
|
53
|
-
perEnv: false,
|
|
54
|
-
job: {
|
|
55
|
-
...base,
|
|
56
|
-
script: [...yarnInstall, "yarn lint"],
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
name: "test",
|
|
61
|
-
perEnv: false,
|
|
62
|
-
job: {
|
|
63
|
-
...base,
|
|
64
|
-
script: [...yarnInstall, "yarn test"],
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
];
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const createNodeBuildJobs = (context: Context): GitlabJobs => {
|
|
71
|
-
const buildConfig = context.componentConfig.build;
|
|
72
|
-
if (!isOfType(buildConfig, "node")) {
|
|
73
|
-
// should not happen
|
|
74
|
-
throw new Error("deploy config is not kubernetes");
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const buildInfo = [
|
|
78
|
-
". getCommitInfo", // TODO: inline
|
|
79
|
-
`echo '{"id":"'$BUILD_ID'","commit":"'$BUILD_COMMIT'","tag":"'$BUILD_TAG'","time":"'$BUILD_TIME'"}' > ${context.componentConfig.dir}/__build_info.json`,
|
|
80
|
-
];
|
|
81
|
-
|
|
82
|
-
const yarnInstall = getYarnInstall(context);
|
|
83
|
-
|
|
84
|
-
return [
|
|
85
|
-
{
|
|
86
|
-
name: "app-build",
|
|
87
|
-
job: {
|
|
88
|
-
needs: [],
|
|
89
|
-
variables: context.environment.variables,
|
|
90
|
-
retry: baseRetry,
|
|
91
|
-
interruptible: true,
|
|
92
|
-
stage: "build",
|
|
93
|
-
script: [...buildInfo, ...yarnInstall, buildConfig.buildCommand!],
|
|
94
|
-
artifacts: {
|
|
95
|
-
paths: [
|
|
96
|
-
context.componentConfig.dir + "/__build_info.json",
|
|
97
|
-
context.componentConfig.dir + "/dist",
|
|
98
|
-
context.componentConfig.dir + "/.next",
|
|
99
|
-
],
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
name: "docker-build",
|
|
105
|
-
|
|
106
|
-
job: {
|
|
107
|
-
...createDockerBuildJob(context, {
|
|
108
|
-
script: [
|
|
109
|
-
buildConfig.runtime === "static"
|
|
110
|
-
? "ensureNginxDockerfile"
|
|
111
|
-
: "ensureNodeDockerfile",
|
|
112
|
-
], // TOOD: inline
|
|
113
|
-
}),
|
|
114
|
-
needs: ["app-build"],
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
];
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export const createNodeJobs = (context: Context): GitlabJobs => {
|
|
121
|
-
return [...createNodeTestJobs(context), ...createNodeBuildJobs(context)];
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
export const getNodeDefaults = (): Partial<BuildConfigNode> => {
|
|
125
|
-
return {
|
|
126
|
-
startCommand: "yarn start",
|
|
127
|
-
runtime: "dynamic",
|
|
128
|
-
buildCommand: "yarn build",
|
|
129
|
-
};
|
|
130
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export type BuildConfigBase = {
|
|
2
|
-
startCommand?: string;
|
|
3
|
-
};
|
|
4
|
-
export type BuildConfigNode = {
|
|
5
|
-
type: "node";
|
|
6
|
-
runtime?: "dynamic" | "static"; // defaults to dynamic
|
|
7
|
-
buildCommand?: string;
|
|
8
|
-
} & BuildConfigBase;
|
|
9
|
-
|
|
10
|
-
export type BuildConfig = BuildConfigNode;
|
|
11
|
-
|
|
12
|
-
export const isOfType = <T extends BuildConfig["type"]>(
|
|
13
|
-
t: BuildConfig,
|
|
14
|
-
type: T
|
|
15
|
-
): t is Extract<BuildConfig, { type: T }> => {
|
|
16
|
-
return t.type === type;
|
|
17
|
-
};
|