From 79db76b9218e3fb41308147ce8d6f5d039866a91 Mon Sep 17 00:00:00 2001 From: Gitlab Runner Date: Fri, 26 Nov 2021 14:37:13 +0000 Subject: [PATCH 01/34] adjust PIPELINE_IMAGE_TAG --- .../scripts/extractValuesFromEnvVars.ts | 19 --- dockerfiles/pipeline/scripts/kubernetesDeploy | 18 +-- .../pipeline/scripts/monorepoGenerate.ts | 117 +++++++++++------- .../pipeline/scripts/printAllValues.ts | 16 +++ .../scripts/utils/extractAllValues.ts | 27 ++++ .../scripts/utils/extractValuesFromEnvVars.ts | 23 ++++ .../{ => utils}/extractValuesFromMr.ts | 13 +- .../tests/extractValuesFromMr.test.ts | 2 +- helm-chart.yml | 2 +- includes/rules.yml | 6 + monorepo.yml | 7 +- panter-kubernetes-base.yml | 2 +- 12 files changed, 167 insertions(+), 85 deletions(-) delete mode 100755 dockerfiles/pipeline/scripts/extractValuesFromEnvVars.ts create mode 100644 dockerfiles/pipeline/scripts/printAllValues.ts create mode 100644 dockerfiles/pipeline/scripts/utils/extractAllValues.ts create mode 100755 dockerfiles/pipeline/scripts/utils/extractValuesFromEnvVars.ts rename dockerfiles/pipeline/scripts/{ => utils}/extractValuesFromMr.ts (80%) diff --git a/dockerfiles/pipeline/scripts/extractValuesFromEnvVars.ts b/dockerfiles/pipeline/scripts/extractValuesFromEnvVars.ts deleted file mode 100755 index 5bf2fc1..0000000 --- a/dockerfiles/pipeline/scripts/extractValuesFromEnvVars.ts +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env ts-node -import { set } from "lodash"; -const values = {}; - -const PREFIX = "DEFAULT_VALUE_"; -for (const [key, value] of Object.entries(process.env).filter(([key]) => - key.startsWith(PREFIX) -)) { - const path = key.replace(PREFIX, "").split("_"); - let theValue; - try { - theValue = JSON.parse(value ?? ""); - } catch (e) { - theValue = value; - } - set(values, path, theValue); -} - -console.log(JSON.stringify(values, null, 2) ?? ""); diff --git a/dockerfiles/pipeline/scripts/kubernetesDeploy b/dockerfiles/pipeline/scripts/kubernetesDeploy index 5a57828..f8f517a 100755 --- a/dockerfiles/pipeline/scripts/kubernetesDeploy +++ b/dockerfiles/pipeline/scripts/kubernetesDeploy @@ -16,20 +16,10 @@ readarray -t helmArgsArray <<<"$helmArgsEvaluated" #Log the time until selfdestruct in case of review environment if [[ ${ENV_SHORT} == "review" ]]; then echo "NOTE - This deployment will stop itself after 2 weeks"; fi -# find all values files and generate an array out of it -extractValuesFromEnvVars.ts >$VALUES_PATH/default-values-from-env.yml +echo "reading values files from $VALUES_PATH for $ENV_SHORT" -if [[ ! -z "$CI_MERGE_REQUEST_IID" ]]; then - echo "extra values from mr:" - extractValuesFromMr.ts - extractValuesFromMr.ts >$VALUES_PATH/values-from-mr.yml - echo "----------------------" -fi - -files=(default-values-from-env.yml values.yml values-$ENV_SHORT.yml values-$CI_ENVIRONMENT_SLUG.yml values-from-mr.yml) -values=() -for i in "${files[@]}"; do if [ -f $VALUES_PATH/$i ]; then values+=(--values $VALUES_PATH/$i); fi; done -echo "reading values files from $VALUES_PATH. found ${values[@]}" +printAllValues.ts -d $VALUES_PATH -e $ENV_SHORT +printAllValues.ts -d $VALUES_PATH -e $ENV_SHORT >__all_values.yml echo "doing helm upgrade" helm3 upgrade --install "$RELEASE_NAME" /tmp/$HELM_GITLAB_CHART_NAME \ @@ -63,5 +53,5 @@ helm3 upgrade --install "$RELEASE_NAME" /tmp/$HELM_GITLAB_CHART_NAME \ --set namespace="$NAMESPACE" \ --namespace="$NAMESPACE" \ ${helmArgsArray[@]} \ - ${values[@]} + --valeues __all_values.yml echo "Deployment successful 😻" diff --git a/dockerfiles/pipeline/scripts/monorepoGenerate.ts b/dockerfiles/pipeline/scripts/monorepoGenerate.ts index 28f5439..72777b0 100755 --- a/dockerfiles/pipeline/scripts/monorepoGenerate.ts +++ b/dockerfiles/pipeline/scripts/monorepoGenerate.ts @@ -7,7 +7,10 @@ import yargs from "yargs"; import { hideBin } from "yargs/helpers"; type Type = "test" | "deploy"; -const args = yargs(hideBin(process.argv)).argv as Record; +const args = yargs(hideBin(process.argv)).array("env").argv as Record< + string, + unknown +>; const thisGitlabCi = parse( readFileSync(".gitlab-ci.yml", { encoding: "utf-8" }) ); @@ -20,51 +23,81 @@ const subcis = readdirSync(".") })) .filter(({ ci }) => existsSync(ci)); -const generateSubPipelein = (type: Type) => { - return subcis.reduce((acc, { dirname, ci }) => { - const changes = [dirname + "/**/*"]; - const rules = [ - // same as rules "always", but with `changes` to only trigger changed branches - { if: "$CI_COMMIT_TAG" }, - { - if: "$CI_COMMIT_MESSAGE =~ /^chore(release).*/", - when: "never", - }, - { if: "$CI_COMMIT_BRANCH =~ /^[0-9]+.([0-9]+|x).x$/" }, - { - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH", - changes, - }, - // add it manually when no changes - { - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH", - when: "manual", - }, - { if: "$CI_MERGE_REQUEST_ID", changes }, - // add it manually when no changes - { if: "$CI_MERGE_REQUEST_ID", when: "manual" }, - ]; +const makeConfig = ({ + subapp, + type, + ci, + env, +}: { + subapp: string; + type: Type; + env: string; + ci: string; +}) => { + const changes = [subapp + "/**/*"]; + const rules = [ + // same as rules "always", but with `changes` to only trigger changed branches + { if: "$CI_COMMIT_TAG" }, + { + if: "$CI_COMMIT_MESSAGE =~ /^chore(release).*/", + when: "never", + }, + { if: "$CI_COMMIT_BRANCH =~ /^[0-9]+.([0-9]+|x).x$/" }, + { + if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH", + changes, + }, + // add it manually when no changes + { + if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH", + when: "manual", + }, + { if: "$CI_MERGE_REQUEST_ID", changes }, + // add it manually when no changes + { if: "$CI_MERGE_REQUEST_ID", when: "manual" }, + ]; + return { + variables: { + // merge + ...thisGitlabCi.variables, + APP_DIR: subapp, + VALUES_DIR: subapp, + COMPONENT_NAME: subapp, + [type.toUpperCase() + "_ONLY"]: "1", + }, + stage: type, + rules: rules, + trigger: { + include: ci, + strategy: "depend", + }, + }; +}; +const generateSubPipelein = (type: Type, envs: string[]) => { + return subcis.reduce((acc, { dirname, ci }) => { return { ...acc, - [type + " " + dirname]: { - variables: { - // merge - ...thisGitlabCi.variables, - APP_DIR: dirname, - VALUES_DIR: dirname, - COMPONENT_NAME: dirname, - [type.toUpperCase() + "_ONLY"]: "1", - }, - stage: type, - rules: rules, - trigger: { - include: ci, - strategy: "depend", - }, - }, + ...envs.reduce( + (inneracc, env) => ({ + ...inneracc, + [type + " " + dirname + " " + env]: makeConfig({ + subapp: dirname, + ci, + type, + env, + }), + }), + {} + ), }; }, {}); }; -console.log(JSON.stringify(generateSubPipelein(args.t as Type), null, 2)); +console.log( + JSON.stringify( + generateSubPipelein(args.t as Type, args.env as string[]), + null, + 2 + ) +); diff --git a/dockerfiles/pipeline/scripts/printAllValues.ts b/dockerfiles/pipeline/scripts/printAllValues.ts new file mode 100644 index 0000000..ef9b131 --- /dev/null +++ b/dockerfiles/pipeline/scripts/printAllValues.ts @@ -0,0 +1,16 @@ +import yargs from "yargs"; +import { hideBin } from "yargs/helpers"; +import { extractAllValues } from "./utils/extractAllValues"; + +type Type = "test" | "deploy"; +const args = yargs(hideBin(process.argv)).argv as Record; + +extractAllValues(args.d as string, args.e as string) + .then(async (values) => { + console.log(JSON.stringify(values, null, 2) ?? ""); + }) + .catch((e) => { + console.error("could not extract values", { + error: e, + }); + }); diff --git a/dockerfiles/pipeline/scripts/utils/extractAllValues.ts b/dockerfiles/pipeline/scripts/utils/extractAllValues.ts new file mode 100644 index 0000000..a7423a0 --- /dev/null +++ b/dockerfiles/pipeline/scripts/utils/extractAllValues.ts @@ -0,0 +1,27 @@ +import { readFileSync } from "fs"; +import { merge } from "lodash"; +import { parse } from "yaml"; +import { extractValuesFromEnvVars } from "./extractValuesFromEnvVars"; +import { extractValuesFromMr } from "./extractValuesFromMr"; + +const { NODE_ENV, CI_PROJECT_ID, CI_MERGE_REQUEST_IID } = process.env; + +const readYaml = (path: string) => { + try { + return parse(readFileSync(path, { encoding: "utf-8" })); + } catch (e) { + return {}; + } +}; + +export const extractAllValues = async (componentName: string, env: string) => { + const valuesFromEnvVars = extractValuesFromEnvVars(); + const valuesDefault = readYaml(componentName + "/values.yml"); + const valuesEnv = readYaml(componentName + "/values-" + env + ".yml"); + const valuesFromMR = + CI_PROJECT_ID && CI_MERGE_REQUEST_IID + ? await extractValuesFromMr(CI_PROJECT_ID, Number(CI_MERGE_REQUEST_IID)) + : {}; + + return merge({}, valuesFromEnvVars, valuesDefault, valuesEnv, valuesFromMR); +}; diff --git a/dockerfiles/pipeline/scripts/utils/extractValuesFromEnvVars.ts b/dockerfiles/pipeline/scripts/utils/extractValuesFromEnvVars.ts new file mode 100755 index 0000000..8e538ab --- /dev/null +++ b/dockerfiles/pipeline/scripts/utils/extractValuesFromEnvVars.ts @@ -0,0 +1,23 @@ +#!/usr/bin/env ts-node +import { set } from "lodash"; + +export const extractValuesFromEnvVars = () => { + const values = {}; + + const PREFIX = "DEFAULT_VALUE_"; + for (const [key, value] of Object.entries(process.env).filter(([key]) => + key.startsWith(PREFIX) + )) { + const path = key.replace(PREFIX, "").split("_"); + let theValue; + try { + theValue = JSON.parse(value ?? ""); + } catch (e) { + theValue = value; + } + set(values, path, theValue); + } + return values; +}; + +console.log(JSON.stringify(extractValuesFromEnvVars(), null, 2) ?? ""); diff --git a/dockerfiles/pipeline/scripts/extractValuesFromMr.ts b/dockerfiles/pipeline/scripts/utils/extractValuesFromMr.ts similarity index 80% rename from dockerfiles/pipeline/scripts/extractValuesFromMr.ts rename to dockerfiles/pipeline/scripts/utils/extractValuesFromMr.ts index 38347e4..603cec7 100755 --- a/dockerfiles/pipeline/scripts/extractValuesFromMr.ts +++ b/dockerfiles/pipeline/scripts/utils/extractValuesFromMr.ts @@ -38,10 +38,17 @@ export const extractValuesFromMRMessage = (mrMessage: string) => { }, {}); }; +export const extractValuesFromMr = async ( + projectId: string, + mergeRequestId: number +) => { + const mrInfo = await getMRInfo(projectId, mergeRequestId); + return extractValuesFromMRMessage(mrInfo.description); +}; + if (NODE_ENV !== "test" && CI_PROJECT_ID && CI_MERGE_REQUEST_IID) { - getMRInfo(CI_PROJECT_ID, Number(CI_MERGE_REQUEST_IID)) - .then(async (r) => { - const values = extractValuesFromMRMessage(r.description); + extractValuesFromMr(CI_PROJECT_ID, Number(CI_MERGE_REQUEST_IID)) + .then(async (values) => { console.log(JSON.stringify(values, null, 2) ?? ""); }) .catch((e) => { diff --git a/dockerfiles/pipeline/tests/extractValuesFromMr.test.ts b/dockerfiles/pipeline/tests/extractValuesFromMr.test.ts index 735be21..561c7bf 100644 --- a/dockerfiles/pipeline/tests/extractValuesFromMr.test.ts +++ b/dockerfiles/pipeline/tests/extractValuesFromMr.test.ts @@ -1,4 +1,4 @@ -import { extractValuesFromMRMessage } from "../scripts/extractValuesFromMr"; +import { extractValuesFromMRMessage } from "../scripts/utils/extractValuesFromMr"; describe("extractValuesFromMr", () => { describe("extractValuesFromMRMessage", () => { diff --git a/helm-chart.yml b/helm-chart.yml index 43d2d4e..56b844c 100644 --- a/helm-chart.yml +++ b/helm-chart.yml @@ -11,7 +11,7 @@ image: variables: HELM_EXPERIMENTAL_OCI: 1 AUTO_RELEASE: "true" - PIPELINE_IMAGE_TAG: dcda17fdc37f0e368ed2ef4482cfdd71e2cb3d77 + PIPELINE_IMAGE_TAG: 7f8c96799c22ffda371e02932470779e1496dd92 stages: - lint diff --git a/includes/rules.yml b/includes/rules.yml index d762c9d..2a0344a 100644 --- a/includes/rules.yml +++ b/includes/rules.yml @@ -38,6 +38,8 @@ .rules-dev-deploy: rules: + - if: $CUSTOM_BUILD_ENV + when: never - if: $TEST_ONLY when: never - if: $CI_COMMIT_TAG # after releases @@ -51,6 +53,8 @@ .rules-stage-deploy: rules: + - if: $CUSTOM_BUILD_ENV + when: never - if: $TEST_ONLY when: never - if: $CI_COMMIT_TAG && $CI_COMMIT_MESSAGE =~ /^chore\(maintenance\).*/ # d @@ -60,6 +64,8 @@ .rules-prod-deploy: rules: + - if: $CUSTOM_BUILD_ENV + when: never - if: $TEST_ONLY when: never - if: $CI_COMMIT_TAG && $CI_COMMIT_MESSAGE =~ /^chore\(maintenance\).*/ # d diff --git a/monorepo.yml b/monorepo.yml index 34b91ad..ec474b4 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -12,7 +12,7 @@ include: - /includes/open-mr.yml variables: - PIPELINE_IMAGE_TAG: dcda17fdc37f0e368ed2ef4482cfdd71e2cb3d77 + PIPELINE_IMAGE_TAG: 7f8c96799c22ffda371e02932470779e1496dd92 image: git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG @@ -28,10 +28,9 @@ setup: extends: - .rules-build-and-deploy script: - - monorepoGenerate.ts -t=test - monorepoGenerate.ts -t=test > generated-test-config.yml - - monorepoGenerate.ts -t=deploy - - monorepoGenerate.ts -t=deploy > generated-deploy-config.yml + - monorepoGenerate.ts -t=deploy --env dev stage prod + - monorepoGenerate.ts -t=deploy --env dev stage prod> generated-deploy-config.yml artifacts: paths: - generated-test-config.yml diff --git a/panter-kubernetes-base.yml b/panter-kubernetes-base.yml index ad8e61c..80602a6 100644 --- a/panter-kubernetes-base.yml +++ b/panter-kubernetes-base.yml @@ -12,7 +12,7 @@ include: - /includes/open-mr.yml variables: - PIPELINE_IMAGE_TAG: dcda17fdc37f0e368ed2ef4482cfdd71e2cb3d77 + PIPELINE_IMAGE_TAG: 7f8c96799c22ffda371e02932470779e1496dd92 CUSTOMER_NAME: panter APP_NAME: demo COMPONENT_NAME: web -- GitLab From 84b27f56c897a90ea152285a6cf970ef6a0e46c6 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Sat, 27 Nov 2021 19:07:20 +0100 Subject: [PATCH 02/34] wip --- .../pipeline/scripts/monorepoGenerate.ts | 31 +++++++++---------- .../pipeline/scripts/printAllValues.ts | 1 - .../scripts/utils/extractAllValues.ts | 8 ++--- .../scripts/utils/extractValuesFromMr.ts | 22 +------------ 4 files changed, 20 insertions(+), 42 deletions(-) diff --git a/dockerfiles/pipeline/scripts/monorepoGenerate.ts b/dockerfiles/pipeline/scripts/monorepoGenerate.ts index 72777b0..dd86d77 100755 --- a/dockerfiles/pipeline/scripts/monorepoGenerate.ts +++ b/dockerfiles/pipeline/scripts/monorepoGenerate.ts @@ -6,11 +6,13 @@ import { parse } from "yaml"; import yargs from "yargs"; import { hideBin } from "yargs/helpers"; +import { extractAllValues } from "./utils/extractAllValues"; type Type = "test" | "deploy"; const args = yargs(hideBin(process.argv)).array("env").argv as Record< string, unknown >; + const thisGitlabCi = parse( readFileSync(".gitlab-ci.yml", { encoding: "utf-8" }) ); @@ -23,7 +25,7 @@ const subcis = readdirSync(".") })) .filter(({ ci }) => existsSync(ci)); -const makeConfig = ({ +const makeConfig = async ({ subapp, type, ci, @@ -65,6 +67,7 @@ const makeConfig = ({ VALUES_DIR: subapp, COMPONENT_NAME: subapp, [type.toUpperCase() + "_ONLY"]: "1", + ...(await extractAllValues(subapp, env)), }, stage: type, rules: rules, @@ -75,29 +78,25 @@ const makeConfig = ({ }; }; const generateSubPipelein = (type: Type, envs: string[]) => { - return subcis.reduce((acc, { dirname, ci }) => { + return subcis.reduce(async (acc, { dirname, ci }) => { return { - ...acc, - ...envs.reduce( - (inneracc, env) => ({ - ...inneracc, - [type + " " + dirname + " " + env]: makeConfig({ + ...(await acc), + ...(await envs.reduce( + async (inneracc, env) => ({ + ...(await inneracc), + [type + " " + dirname + " " + env]: await makeConfig({ subapp: dirname, ci, type, env, }), }), - {} - ), + {} as Promise> + )), }; - }, {}); + }, {} as Promise>); }; -console.log( - JSON.stringify( - generateSubPipelein(args.t as Type, args.env as string[]), - null, - 2 - ) +generateSubPipelein(args.t as Type, args.env as string[]).then((p) => + console.log(JSON.stringify(p, null, 2)) ); diff --git a/dockerfiles/pipeline/scripts/printAllValues.ts b/dockerfiles/pipeline/scripts/printAllValues.ts index ef9b131..e5006e0 100644 --- a/dockerfiles/pipeline/scripts/printAllValues.ts +++ b/dockerfiles/pipeline/scripts/printAllValues.ts @@ -2,7 +2,6 @@ import yargs from "yargs"; import { hideBin } from "yargs/helpers"; import { extractAllValues } from "./utils/extractAllValues"; -type Type = "test" | "deploy"; const args = yargs(hideBin(process.argv)).argv as Record; extractAllValues(args.d as string, args.e as string) diff --git a/dockerfiles/pipeline/scripts/utils/extractAllValues.ts b/dockerfiles/pipeline/scripts/utils/extractAllValues.ts index a7423a0..68170c6 100644 --- a/dockerfiles/pipeline/scripts/utils/extractAllValues.ts +++ b/dockerfiles/pipeline/scripts/utils/extractAllValues.ts @@ -4,7 +4,7 @@ import { parse } from "yaml"; import { extractValuesFromEnvVars } from "./extractValuesFromEnvVars"; import { extractValuesFromMr } from "./extractValuesFromMr"; -const { NODE_ENV, CI_PROJECT_ID, CI_MERGE_REQUEST_IID } = process.env; +const { CI_PROJECT_ID, CI_MERGE_REQUEST_IID } = process.env; const readYaml = (path: string) => { try { @@ -14,10 +14,10 @@ const readYaml = (path: string) => { } }; -export const extractAllValues = async (componentName: string, env: string) => { +export const extractAllValues = async (appDirectory: string, env: string) => { const valuesFromEnvVars = extractValuesFromEnvVars(); - const valuesDefault = readYaml(componentName + "/values.yml"); - const valuesEnv = readYaml(componentName + "/values-" + env + ".yml"); + const valuesDefault = readYaml(appDirectory + "/values.yml"); + const valuesEnv = readYaml(appDirectory + "/values-" + env + ".yml"); const valuesFromMR = CI_PROJECT_ID && CI_MERGE_REQUEST_IID ? await extractValuesFromMr(CI_PROJECT_ID, Number(CI_MERGE_REQUEST_IID)) diff --git a/dockerfiles/pipeline/scripts/utils/extractValuesFromMr.ts b/dockerfiles/pipeline/scripts/utils/extractValuesFromMr.ts index 603cec7..28a088e 100755 --- a/dockerfiles/pipeline/scripts/utils/extractValuesFromMr.ts +++ b/dockerfiles/pipeline/scripts/utils/extractValuesFromMr.ts @@ -4,13 +4,7 @@ import { Gitlab } from "@gitbeaker/node"; // Just the Project Resource import { parse } from "yaml"; import { merge } from "lodash"; -const { - NODE_ENV, - GL_TOKEN, - CI_SERVER_URL, - CI_PROJECT_ID, - CI_MERGE_REQUEST_IID, -} = process.env; +const { GL_TOKEN, CI_SERVER_URL } = process.env; const gitlabApi = new Gitlab({ token: GL_TOKEN, @@ -45,17 +39,3 @@ export const extractValuesFromMr = async ( const mrInfo = await getMRInfo(projectId, mergeRequestId); return extractValuesFromMRMessage(mrInfo.description); }; - -if (NODE_ENV !== "test" && CI_PROJECT_ID && CI_MERGE_REQUEST_IID) { - extractValuesFromMr(CI_PROJECT_ID, Number(CI_MERGE_REQUEST_IID)) - .then(async (values) => { - console.log(JSON.stringify(values, null, 2) ?? ""); - }) - .catch((e) => { - console.error("could not extract values from mr", { - CI_PROJECT_ID, - CI_MERGE_REQUEST_IID, - error: e, - }); - }); -} -- GitLab From 54a3a67a44da38fcd89bccb0be7e8f1923cec9ec Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Sat, 27 Nov 2021 20:40:13 +0100 Subject: [PATCH 03/34] vry wip --- dockerfiles/pipeline/package.json | 3 +- .../pipeline/scripts/monorepoGenerate.ts | 4 +- dockerfiles/pipeline/scripts/printBuildEnv.ts | 20 +++++ .../scripts/utils/extractAllValues.ts | 9 +- .../pipeline/scripts/utils/extractBuildEnv.ts | 84 +++++++++++++++++++ includes/setup.yml | 1 + yarn.lock | 5 ++ 7 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 dockerfiles/pipeline/scripts/printBuildEnv.ts create mode 100644 dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts diff --git a/dockerfiles/pipeline/package.json b/dockerfiles/pipeline/package.json index 0930813..63423d0 100644 --- a/dockerfiles/pipeline/package.json +++ b/dockerfiles/pipeline/package.json @@ -10,6 +10,7 @@ "@gitbeaker/node": "^32.1.2", "lodash": "^4.17.21", "yaml": "^1.10.2", - "yargs": "^17.2.1" + "yargs": "^17.2.1", + "slugify": "^1.6.3" } } diff --git a/dockerfiles/pipeline/scripts/monorepoGenerate.ts b/dockerfiles/pipeline/scripts/monorepoGenerate.ts index dd86d77..a6faeb0 100755 --- a/dockerfiles/pipeline/scripts/monorepoGenerate.ts +++ b/dockerfiles/pipeline/scripts/monorepoGenerate.ts @@ -6,7 +6,7 @@ import { parse } from "yaml"; import yargs from "yargs"; import { hideBin } from "yargs/helpers"; -import { extractAllValues } from "./utils/extractAllValues"; +import { extractBuildEnv } from "./utils/extractBuildEnv"; type Type = "test" | "deploy"; const args = yargs(hideBin(process.argv)).array("env").argv as Record< string, @@ -67,7 +67,7 @@ const makeConfig = async ({ VALUES_DIR: subapp, COMPONENT_NAME: subapp, [type.toUpperCase() + "_ONLY"]: "1", - ...(await extractAllValues(subapp, env)), + ...(await extractBuildEnv(subapp, env)), }, stage: type, rules: rules, diff --git a/dockerfiles/pipeline/scripts/printBuildEnv.ts b/dockerfiles/pipeline/scripts/printBuildEnv.ts new file mode 100644 index 0000000..7b9f83b --- /dev/null +++ b/dockerfiles/pipeline/scripts/printBuildEnv.ts @@ -0,0 +1,20 @@ +import { isObject } from "lodash"; +import yargs from "yargs"; +import { hideBin } from "yargs/helpers"; +import { extractBuildEnv } from "./utils/extractBuildEnv"; + +const args = yargs(hideBin(process.argv)).argv as Record; + +extractBuildEnv(args.d as string, args.e as string) + .then(async (values) => { + Object.entries(values).forEach(([key, value]) => + console.log( + `${key}: "${isObject(value) ? JSON.stringify(value) : value}"` + ) + ); + }) + .catch((e) => { + console.error("could not extract values", { + error: e, + }); + }); diff --git a/dockerfiles/pipeline/scripts/utils/extractAllValues.ts b/dockerfiles/pipeline/scripts/utils/extractAllValues.ts index 68170c6..36f7d4b 100644 --- a/dockerfiles/pipeline/scripts/utils/extractAllValues.ts +++ b/dockerfiles/pipeline/scripts/utils/extractAllValues.ts @@ -14,10 +14,15 @@ const readYaml = (path: string) => { } }; -export const extractAllValues = async (appDirectory: string, env: string) => { +export const extractAllValues = async ( + appDirectory: string, + env: string | null +) => { const valuesFromEnvVars = extractValuesFromEnvVars(); const valuesDefault = readYaml(appDirectory + "/values.yml"); - const valuesEnv = readYaml(appDirectory + "/values-" + env + ".yml"); + const valuesEnv = env + ? readYaml(appDirectory + "/values-" + env + ".yml") + : {}; const valuesFromMR = CI_PROJECT_ID && CI_MERGE_REQUEST_IID ? await extractValuesFromMr(CI_PROJECT_ID, Number(CI_MERGE_REQUEST_IID)) diff --git a/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts b/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts new file mode 100644 index 0000000..122068e --- /dev/null +++ b/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts @@ -0,0 +1,84 @@ +import { extractAllValues } from "./extractAllValues"; +import slugify from "slugify"; + +type EnvVars = Record; +export const extractBuildEnv = async ( + componentName: string, + env: string | null, + visitedReferencedApps: { [app: string]: EnvVars } = {} // this is just to avoid infinit recursion +): Promise => { + const values = await extractAllValues(componentName, env); + const { + APP_NAME, + CUSTOMER_NAME, + CI_COMMIT_REF_SLUG, + CI_MERGE_REQUEST_IID, + CI_ENVIRONMENT_SLUG, + } = process.env; + + const isNotMonorepo = componentName === "."; + + const KUBE_APP_NAME = CI_MERGE_REQUEST_IID + ? `${componentName}-${CI_COMMIT_REF_SLUG}` + : componentName; + const KUBE_APP_SLUG = isNotMonorepo + ? CI_ENVIRONMENT_SLUG + : slugify(KUBE_APP_NAME); + const CANONICAL_URL = `https://${APP_NAME}-${KUBE_APP_SLUG}.${CUSTOMER_NAME}.panter.cloud`; + const defaultBuildEnv = { + KUBE_APP_NAME, + CANONICAL_URL, + IMAGE_PULL_SECRET: `gitlab-registry-${componentName}}`, + ROOT_URL: values?.application?.host || CANONICAL_URL, + }; + const buildEnv = values?.buiildEnv?.public ?? {}; + const merged = { + ...defaultBuildEnv, + ...buildEnv, + }; + // extract referenced build env (only works in monorepo + // like this + /* + fromComponents: + vendure: + API_URL: ROOT_URL +*/ + const fromComponents: { + [otherApp: string]: { + [ourKey: string]: string; + }; + } = values.build?.fromComponents ?? {}; + const referencedBuildEnv = await Object.entries(fromComponents).reduce( + async (acc, [otherApp, mapping]) => { + if (!mapping) { + return await acc; + } + + // prevent infinit loop + const otherBuildEnv = + visitedReferencedApps[otherApp] ?? + (await extractBuildEnv(otherApp, env, { + ...visitedReferencedApps, + [componentName]: merged, + })); + + // resolve mapping + return { + ...(await acc), + ...Object.entries(mapping).reduce( + (inneracc, [ourKey, otherKey]) => ({ + ...inneracc, + [ourKey]: otherBuildEnv[otherKey], + }), + {} as EnvVars + ), + }; + }, + {} as Promise + ); + + return { + ...merged, + ...referencedBuildEnv, + }; +}; diff --git a/includes/setup.yml b/includes/setup.yml index bd3d7b8..e5ee8e6 100644 --- a/includes/setup.yml +++ b/includes/setup.yml @@ -10,6 +10,7 @@ - BUILD_ID="$COMPONENT_NAME-$BUILD_TAG" - BUILD_COMMIT="$(git rev-parse HEAD)" - BUILD_TIME="$(date)" + - extractBuildEnv.ts -d >> build.env - echo "BUILD_TAG=$BUILD_TAG" >> build.env - echo "BUILD_ID=$BUILD_ID" >> build.env - echo "BUILD_COMMIT=$BUILD_COMMIT" >> build.env diff --git a/yarn.lock b/yarn.lock index 3f45637..9204b9e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2465,6 +2465,11 @@ slash@^3.0.0: resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q== +slugify@^1.6.3: + version "1.6.3" + resolved "https://registry.yarnpkg.com/slugify/-/slugify-1.6.3.tgz#325aec50871acfb17976f2d3cb09ee1e7ab563be" + integrity sha512-1MPyqnIhgiq+/0iDJyqSJHENdnH5MMIlgJIBxmkRMzTNKlS/QsN5dXsB+MdDq4E6w0g9jFA4XOTRkVDjDae/2w== + source-map-support@^0.5.6: version "0.5.19" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61" -- GitLab From f89c0756b4f3137d7f96e0721c8d5d941915d059 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Sat, 27 Nov 2021 20:49:32 +0100 Subject: [PATCH 04/34] fudi --- dockerfiles/pipeline/scripts/utils/extractValuesFromEnvVars.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/dockerfiles/pipeline/scripts/utils/extractValuesFromEnvVars.ts b/dockerfiles/pipeline/scripts/utils/extractValuesFromEnvVars.ts index 8e538ab..2d65e65 100755 --- a/dockerfiles/pipeline/scripts/utils/extractValuesFromEnvVars.ts +++ b/dockerfiles/pipeline/scripts/utils/extractValuesFromEnvVars.ts @@ -19,5 +19,3 @@ export const extractValuesFromEnvVars = () => { } return values; }; - -console.log(JSON.stringify(extractValuesFromEnvVars(), null, 2) ?? ""); -- GitLab From c7a605676f3d9673ca1b5c1ba1589333ee1aa7cc Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Sat, 27 Nov 2021 20:52:43 +0100 Subject: [PATCH 05/34] wip --- dockerfiles/pipeline/scripts/monorepoGenerate.ts | 6 +++--- monorepo.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dockerfiles/pipeline/scripts/monorepoGenerate.ts b/dockerfiles/pipeline/scripts/monorepoGenerate.ts index a6faeb0..529b069 100755 --- a/dockerfiles/pipeline/scripts/monorepoGenerate.ts +++ b/dockerfiles/pipeline/scripts/monorepoGenerate.ts @@ -77,8 +77,8 @@ const makeConfig = async ({ }, }; }; -const generateSubPipelein = (type: Type, envs: string[]) => { - return subcis.reduce(async (acc, { dirname, ci }) => { +const generateSubPipeline = async (type: Type, envs: string[]) => { + return await subcis.reduce(async (acc, { dirname, ci }) => { return { ...(await acc), ...(await envs.reduce( @@ -97,6 +97,6 @@ const generateSubPipelein = (type: Type, envs: string[]) => { }, {} as Promise>); }; -generateSubPipelein(args.t as Type, args.env as string[]).then((p) => +generateSubPipeline(args.t as Type, args.env as string[]).then((p) => console.log(JSON.stringify(p, null, 2)) ); diff --git a/monorepo.yml b/monorepo.yml index ec474b4..7e090a7 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -28,7 +28,7 @@ setup: extends: - .rules-build-and-deploy script: - - monorepoGenerate.ts -t=test > generated-test-config.yml + - monorepoGenerate.ts -t=test --env dev > generated-test-config.yml - monorepoGenerate.ts -t=deploy --env dev stage prod - monorepoGenerate.ts -t=deploy --env dev stage prod> generated-deploy-config.yml artifacts: -- GitLab From 987c0cf69cb216f2245a5bf087c5469baeef9f97 Mon Sep 17 00:00:00 2001 From: Gitlab Runner Date: Sat, 27 Nov 2021 19:56:56 +0000 Subject: [PATCH 06/34] adjust PIPELINE_IMAGE_TAG --- helm-chart.yml | 2 +- monorepo.yml | 2 +- panter-kubernetes-base.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helm-chart.yml b/helm-chart.yml index 56b844c..83fcfe3 100644 --- a/helm-chart.yml +++ b/helm-chart.yml @@ -11,7 +11,7 @@ image: variables: HELM_EXPERIMENTAL_OCI: 1 AUTO_RELEASE: "true" - PIPELINE_IMAGE_TAG: 7f8c96799c22ffda371e02932470779e1496dd92 + PIPELINE_IMAGE_TAG: c7a605676f3d9673ca1b5c1ba1589333ee1aa7cc stages: - lint diff --git a/monorepo.yml b/monorepo.yml index 7e090a7..aa5987a 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -12,7 +12,7 @@ include: - /includes/open-mr.yml variables: - PIPELINE_IMAGE_TAG: 7f8c96799c22ffda371e02932470779e1496dd92 + PIPELINE_IMAGE_TAG: c7a605676f3d9673ca1b5c1ba1589333ee1aa7cc image: git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG diff --git a/panter-kubernetes-base.yml b/panter-kubernetes-base.yml index 80602a6..ce5a20b 100644 --- a/panter-kubernetes-base.yml +++ b/panter-kubernetes-base.yml @@ -12,7 +12,7 @@ include: - /includes/open-mr.yml variables: - PIPELINE_IMAGE_TAG: 7f8c96799c22ffda371e02932470779e1496dd92 + PIPELINE_IMAGE_TAG: c7a605676f3d9673ca1b5c1ba1589333ee1aa7cc CUSTOMER_NAME: panter APP_NAME: demo COMPONENT_NAME: web -- GitLab From 479a4b5568b5445aded3e63d695f74477155c29c Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Sat, 27 Nov 2021 20:58:42 +0100 Subject: [PATCH 07/34] =?UTF-8?q?f=C3=BCdli?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dockerfiles/pipeline/scripts/printAllValues.ts | 2 ++ dockerfiles/pipeline/scripts/printBuildEnv.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/dockerfiles/pipeline/scripts/printAllValues.ts b/dockerfiles/pipeline/scripts/printAllValues.ts index e5006e0..a06a2de 100644 --- a/dockerfiles/pipeline/scripts/printAllValues.ts +++ b/dockerfiles/pipeline/scripts/printAllValues.ts @@ -1,3 +1,5 @@ +#!/usr/bin/env ts-node + import yargs from "yargs"; import { hideBin } from "yargs/helpers"; import { extractAllValues } from "./utils/extractAllValues"; diff --git a/dockerfiles/pipeline/scripts/printBuildEnv.ts b/dockerfiles/pipeline/scripts/printBuildEnv.ts index 7b9f83b..cfc04f3 100644 --- a/dockerfiles/pipeline/scripts/printBuildEnv.ts +++ b/dockerfiles/pipeline/scripts/printBuildEnv.ts @@ -1,3 +1,4 @@ +#!/usr/bin/env ts-node import { isObject } from "lodash"; import yargs from "yargs"; import { hideBin } from "yargs/helpers"; -- GitLab From ba9ed9c241f7a5b7ff4da08e012ab669dfc5da87 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Sat, 27 Nov 2021 20:59:37 +0100 Subject: [PATCH 08/34] fix --- dockerfiles/pipeline/scripts/utils/extractValuesFromMr.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/dockerfiles/pipeline/scripts/utils/extractValuesFromMr.ts b/dockerfiles/pipeline/scripts/utils/extractValuesFromMr.ts index 28a088e..8d4e73b 100755 --- a/dockerfiles/pipeline/scripts/utils/extractValuesFromMr.ts +++ b/dockerfiles/pipeline/scripts/utils/extractValuesFromMr.ts @@ -1,5 +1,3 @@ -#!/usr/bin/env ts-node - import { Gitlab } from "@gitbeaker/node"; // Just the Project Resource import { parse } from "yaml"; import { merge } from "lodash"; -- GitLab From a6d3438fa6f2d57d0833c97bb18ee72263298f9f Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Sat, 27 Nov 2021 21:01:26 +0100 Subject: [PATCH 09/34] fix? --- dockerfiles/pipeline/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfiles/pipeline/Dockerfile b/dockerfiles/pipeline/Dockerfile index 7496fa7..f2e8e89 100644 --- a/dockerfiles/pipeline/Dockerfile +++ b/dockerfiles/pipeline/Dockerfile @@ -74,7 +74,7 @@ RUN curl https://install.meteor.com/ | sh && \ RUN yarn global add ts-node typescript RUN mkdir p /scripts -COPY ./scripts/* /scripts/ +COPY ./scripts/ /scripts/ RUN chmod +x /scripts/* COPY package.json /scripts/ -- GitLab From fc601444e32d6ea36e3fb2ee9129f508e29b60d1 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Sat, 27 Nov 2021 21:08:06 +0100 Subject: [PATCH 10/34] wtf --- dockerfiles/pipeline/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfiles/pipeline/Dockerfile b/dockerfiles/pipeline/Dockerfile index f2e8e89..4ac74d3 100644 --- a/dockerfiles/pipeline/Dockerfile +++ b/dockerfiles/pipeline/Dockerfile @@ -73,7 +73,7 @@ RUN curl https://install.meteor.com/ | sh && \ RUN yarn global add ts-node typescript -RUN mkdir p /scripts +RUN mkdir -p /scripts COPY ./scripts/ /scripts/ RUN chmod +x /scripts/* -- GitLab From 665e63b1da14bac24bf4a056fed11a14b746135a Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Sat, 27 Nov 2021 21:10:09 +0100 Subject: [PATCH 11/34] fix --- dockerfiles/pipeline/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dockerfiles/pipeline/Dockerfile b/dockerfiles/pipeline/Dockerfile index 4ac74d3..8a1aeaa 100644 --- a/dockerfiles/pipeline/Dockerfile +++ b/dockerfiles/pipeline/Dockerfile @@ -73,8 +73,7 @@ RUN curl https://install.meteor.com/ | sh && \ RUN yarn global add ts-node typescript -RUN mkdir -p /scripts -COPY ./scripts/ /scripts/ +COPY ./scripts / RUN chmod +x /scripts/* COPY package.json /scripts/ -- GitLab From f95251e2e0c8cf84f0bc7c0f004062794b6f6783 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Sat, 27 Nov 2021 21:14:30 +0100 Subject: [PATCH 12/34] fudi --- dockerfiles/pipeline/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfiles/pipeline/Dockerfile b/dockerfiles/pipeline/Dockerfile index 8a1aeaa..66274de 100644 --- a/dockerfiles/pipeline/Dockerfile +++ b/dockerfiles/pipeline/Dockerfile @@ -73,7 +73,7 @@ RUN curl https://install.meteor.com/ | sh && \ RUN yarn global add ts-node typescript -COPY ./scripts / +COPY ./scripts /scripts RUN chmod +x /scripts/* COPY package.json /scripts/ -- GitLab From 3e71d348cf07f64899118137ca8b4aa21a7b7194 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Sat, 27 Nov 2021 21:24:48 +0100 Subject: [PATCH 13/34] wip --- dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts | 11 ++++++++++- monorepo.yml | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts b/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts index 122068e..12b2977 100644 --- a/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts +++ b/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts @@ -1,5 +1,6 @@ import { extractAllValues } from "./extractAllValues"; import slugify from "slugify"; +import { Console } from "console"; type EnvVars = Record; export const extractBuildEnv = async ( @@ -36,6 +37,9 @@ export const extractBuildEnv = async ( ...defaultBuildEnv, ...buildEnv, }; + if (process.env.DEBUG) { + console.log({ values, defaultBuildEnv, buildEnv }); + } // extract referenced build env (only works in monorepo // like this /* @@ -50,6 +54,9 @@ export const extractBuildEnv = async ( } = values.build?.fromComponents ?? {}; const referencedBuildEnv = await Object.entries(fromComponents).reduce( async (acc, [otherApp, mapping]) => { + if (process.env.DEBUG) { + console.log("extract reference build env", otherApp, mapping); + } if (!mapping) { return await acc; } @@ -61,7 +68,9 @@ export const extractBuildEnv = async ( ...visitedReferencedApps, [componentName]: merged, })); - + if (process.env.DEBUG) { + console.log({ otherBuildEnv }); + } // resolve mapping return { ...(await acc), diff --git a/monorepo.yml b/monorepo.yml index aa5987a..d6ba012 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -29,7 +29,7 @@ setup: - .rules-build-and-deploy script: - monorepoGenerate.ts -t=test --env dev > generated-test-config.yml - - monorepoGenerate.ts -t=deploy --env dev stage prod + - DEBUG=1 monorepoGenerate.ts -t=deploy --env dev stage prod - monorepoGenerate.ts -t=deploy --env dev stage prod> generated-deploy-config.yml artifacts: paths: -- GitLab From e27de162d36184aef403af34b2b89db550a9411a Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Sat, 27 Nov 2021 21:32:25 +0100 Subject: [PATCH 14/34] fix --- dockerfiles/pipeline/scripts/printBuildEnv.ts | 1 + dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts | 8 ++++---- includes/setup.yml | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dockerfiles/pipeline/scripts/printBuildEnv.ts b/dockerfiles/pipeline/scripts/printBuildEnv.ts index cfc04f3..209527a 100644 --- a/dockerfiles/pipeline/scripts/printBuildEnv.ts +++ b/dockerfiles/pipeline/scripts/printBuildEnv.ts @@ -1,4 +1,5 @@ #!/usr/bin/env ts-node + import { isObject } from "lodash"; import yargs from "yargs"; import { hideBin } from "yargs/helpers"; diff --git a/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts b/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts index 12b2977..9a84841 100644 --- a/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts +++ b/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts @@ -32,13 +32,13 @@ export const extractBuildEnv = async ( IMAGE_PULL_SECRET: `gitlab-registry-${componentName}}`, ROOT_URL: values?.application?.host || CANONICAL_URL, }; - const buildEnv = values?.buiildEnv?.public ?? {}; + const publicBuildEnv = values?.buildEnv?.public ?? {}; const merged = { ...defaultBuildEnv, - ...buildEnv, + ...publicBuildEnv, }; if (process.env.DEBUG) { - console.log({ values, defaultBuildEnv, buildEnv }); + console.log({ values, defaultBuildEnv, publicBuildEnv }); } // extract referenced build env (only works in monorepo // like this @@ -51,7 +51,7 @@ export const extractBuildEnv = async ( [otherApp: string]: { [ourKey: string]: string; }; - } = values.build?.fromComponents ?? {}; + } = values?.buildEnv?.fromComponents ?? {}; const referencedBuildEnv = await Object.entries(fromComponents).reduce( async (acc, [otherApp, mapping]) => { if (process.env.DEBUG) { diff --git a/includes/setup.yml b/includes/setup.yml index e5ee8e6..a9740f9 100644 --- a/includes/setup.yml +++ b/includes/setup.yml @@ -10,7 +10,7 @@ - BUILD_ID="$COMPONENT_NAME-$BUILD_TAG" - BUILD_COMMIT="$(git rev-parse HEAD)" - BUILD_TIME="$(date)" - - extractBuildEnv.ts -d >> build.env + - printBuildEnv.ts -d >> build.env - echo "BUILD_TAG=$BUILD_TAG" >> build.env - echo "BUILD_ID=$BUILD_ID" >> build.env - echo "BUILD_COMMIT=$BUILD_COMMIT" >> build.env -- GitLab From 1f49854fd4efba85f0549262f290a2eead786302 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Sat, 27 Nov 2021 21:52:48 +0100 Subject: [PATCH 15/34] wip --- dockerfiles/pipeline/scripts/monorepoGenerate.ts | 8 ++++---- dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dockerfiles/pipeline/scripts/monorepoGenerate.ts b/dockerfiles/pipeline/scripts/monorepoGenerate.ts index 529b069..5749904 100755 --- a/dockerfiles/pipeline/scripts/monorepoGenerate.ts +++ b/dockerfiles/pipeline/scripts/monorepoGenerate.ts @@ -78,13 +78,13 @@ const makeConfig = async ({ }; }; const generateSubPipeline = async (type: Type, envs: string[]) => { - return await subcis.reduce(async (acc, { dirname, ci }) => { + return await envs.reduce(async (acc, env) => { return { ...(await acc), - ...(await envs.reduce( - async (inneracc, env) => ({ + ...(await subcis.reduce( + async (inneracc, { dirname, ci }) => ({ ...(await inneracc), - [type + " " + dirname + " " + env]: await makeConfig({ + [`${env}-${dirname} ${type}`]: await makeConfig({ subapp: dirname, ci, type, diff --git a/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts b/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts index 9a84841..b5fda0e 100644 --- a/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts +++ b/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts @@ -29,7 +29,7 @@ export const extractBuildEnv = async ( const defaultBuildEnv = { KUBE_APP_NAME, CANONICAL_URL, - IMAGE_PULL_SECRET: `gitlab-registry-${componentName}}`, + IMAGE_PULL_SECRET: `gitlab-registry-${componentName}`, ROOT_URL: values?.application?.host || CANONICAL_URL, }; const publicBuildEnv = values?.buildEnv?.public ?? {}; -- GitLab From 819610b52f15c9d031508a86ac575f1ac7ee3309 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Tue, 30 Nov 2021 15:35:43 +0100 Subject: [PATCH 16/34] remove --- dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts b/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts index b5fda0e..37fd4c5 100644 --- a/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts +++ b/dockerfiles/pipeline/scripts/utils/extractBuildEnv.ts @@ -1,6 +1,5 @@ import { extractAllValues } from "./extractAllValues"; import slugify from "slugify"; -import { Console } from "console"; type EnvVars = Record; export const extractBuildEnv = async ( -- GitLab From 8a7c81d60fcac515e43bfea0699f7df484b947e2 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Tue, 30 Nov 2021 15:44:42 +0100 Subject: [PATCH 17/34] wip --- dockerfiles/pipeline/scripts/getCommitInfo | 11 +++++++++ includes/setup.yml | 13 ++++------- monorepo.yml | 26 +++++++++++++++++----- 3 files changed, 36 insertions(+), 14 deletions(-) create mode 100755 dockerfiles/pipeline/scripts/getCommitInfo diff --git a/dockerfiles/pipeline/scripts/getCommitInfo b/dockerfiles/pipeline/scripts/getCommitInfo new file mode 100755 index 0000000..f308aba --- /dev/null +++ b/dockerfiles/pipeline/scripts/getCommitInfo @@ -0,0 +1,11 @@ +#!/bin/bash + +export BUILD_TAG="$(git describe --tags || git rev-parse HEAD)" +export BUILD_ID="$COMPONENT_NAME-$BUILD_TAG" +export BUILD_COMMIT="$(git rev-parse HEAD)" +export BUILD_TIME="$(date)" +echo "BUILD_TAG=$BUILD_TAG" >>build.env +echo "BUILD_ID=$BUILD_ID" >>build.env +echo "BUILD_COMMIT=$BUILD_COMMIT" >>build.env +echo "BUILD_TIME=$BUILD_TIME" >>build.env +echo '{"id":"'$BUILD_ID'","commit":"'$BUILD_COMMIT'","tag":"'$BUILD_TAG'","time":"'$BUILD_TIME'"}' >__build_info.json diff --git a/includes/setup.yml b/includes/setup.yml index a9740f9..c056924 100644 --- a/includes/setup.yml +++ b/includes/setup.yml @@ -1,20 +1,15 @@ .setup-build-info: stage: setup interruptible: true + rules: + - if: $IS_MONOREPO # we do this differently in monorepos + when: never extends: - .retry-default - .rules-build-and-deploy script: - - echo "triggered by $CI_PIPELINE_SOURCE" - - BUILD_TAG="$(git describe --tags || git rev-parse HEAD)" - - BUILD_ID="$COMPONENT_NAME-$BUILD_TAG" - - BUILD_COMMIT="$(git rev-parse HEAD)" - - BUILD_TIME="$(date)" + - . ./dockerfiles/pipeline/scripts/getCommitInfo - printBuildEnv.ts -d >> build.env - - echo "BUILD_TAG=$BUILD_TAG" >> build.env - - echo "BUILD_ID=$BUILD_ID" >> build.env - - echo "BUILD_COMMIT=$BUILD_COMMIT" >> build.env - - echo "BUILD_TIME=$BUILD_TIME" >> build.env - echo '{"id":"'$BUILD_ID'","commit":"'$BUILD_COMMIT'","tag":"'$BUILD_TAG'","time":"'$BUILD_TIME'"}' > $APP_DIR/__build_info.json artifacts: paths: diff --git a/monorepo.yml b/monorepo.yml index d6ba012..3072c17 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -12,6 +12,7 @@ include: - /includes/open-mr.yml variables: + IS_MONOREPO: 1 PIPELINE_IMAGE_TAG: c7a605676f3d9673ca1b5c1ba1589333ee1aa7cc image: git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG @@ -23,8 +24,23 @@ stages: - verify - create-release -setup: +setup-build-info: stage: setup + interruptible: true + extends: + - .retry-default + - .rules-build-and-deploy + script: + - . ./dockerfiles/pipeline/scripts/getCommitInfo + artifacts: + paths: + - $CI_PROJECT_DIR/__build_info.json + reports: + dotenv: build.env + +create-pipeline: + stage: setup + interruptible: true extends: - .rules-build-and-deploy script: @@ -38,25 +54,25 @@ setup: test: stage: test - needs: [setup] + needs: [create-pipeline] extends: - .rules-always trigger: strategy: depend include: - artifact: generated-test-config.yml - job: setup + job: create-pipeline deploy: stage: deploy - needs: [setup] + needs: [setup-build-info, create-pipeline] extends: - .rules-always trigger: strategy: depend include: - artifact: generated-deploy-config.yml - job: setup + job: create-pipeline create-release: extends: .create-release -- GitLab From 2cc4f365674114ab9f412cea054799ece1624f9d Mon Sep 17 00:00:00 2001 From: Gitlab Runner Date: Tue, 30 Nov 2021 14:49:59 +0000 Subject: [PATCH 18/34] adjust PIPELINE_IMAGE_TAG --- helm-chart.yml | 2 +- monorepo.yml | 2 +- panter-kubernetes-base.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helm-chart.yml b/helm-chart.yml index 83fcfe3..e1e4881 100644 --- a/helm-chart.yml +++ b/helm-chart.yml @@ -11,7 +11,7 @@ image: variables: HELM_EXPERIMENTAL_OCI: 1 AUTO_RELEASE: "true" - PIPELINE_IMAGE_TAG: c7a605676f3d9673ca1b5c1ba1589333ee1aa7cc + PIPELINE_IMAGE_TAG: 8a7c81d60fcac515e43bfea0699f7df484b947e2 stages: - lint diff --git a/monorepo.yml b/monorepo.yml index 3072c17..1b0bf40 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -13,7 +13,7 @@ include: variables: IS_MONOREPO: 1 - PIPELINE_IMAGE_TAG: c7a605676f3d9673ca1b5c1ba1589333ee1aa7cc + PIPELINE_IMAGE_TAG: 8a7c81d60fcac515e43bfea0699f7df484b947e2 image: git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG diff --git a/panter-kubernetes-base.yml b/panter-kubernetes-base.yml index ce5a20b..aec62d1 100644 --- a/panter-kubernetes-base.yml +++ b/panter-kubernetes-base.yml @@ -12,7 +12,7 @@ include: - /includes/open-mr.yml variables: - PIPELINE_IMAGE_TAG: c7a605676f3d9673ca1b5c1ba1589333ee1aa7cc + PIPELINE_IMAGE_TAG: 8a7c81d60fcac515e43bfea0699f7df484b947e2 CUSTOMER_NAME: panter APP_NAME: demo COMPONENT_NAME: web -- GitLab From 1f10ce362fb8ed09942561aee1f9c274f3e29313 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Tue, 30 Nov 2021 15:53:50 +0100 Subject: [PATCH 19/34] fix --- includes/setup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/setup.yml b/includes/setup.yml index c056924..6cfafba 100644 --- a/includes/setup.yml +++ b/includes/setup.yml @@ -8,7 +8,7 @@ - .retry-default - .rules-build-and-deploy script: - - . ./dockerfiles/pipeline/scripts/getCommitInfo + - . getCommitInfo - printBuildEnv.ts -d >> build.env - echo '{"id":"'$BUILD_ID'","commit":"'$BUILD_COMMIT'","tag":"'$BUILD_TAG'","time":"'$BUILD_TIME'"}' > $APP_DIR/__build_info.json artifacts: -- GitLab From 2f386ed1d358bbba9af0d7702df7bba352a84878 Mon Sep 17 00:00:00 2001 From: Gitlab Runner Date: Tue, 30 Nov 2021 14:57:32 +0000 Subject: [PATCH 20/34] adjust PIPELINE_IMAGE_TAG --- helm-chart.yml | 2 +- monorepo.yml | 2 +- panter-kubernetes-base.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helm-chart.yml b/helm-chart.yml index e1e4881..2a1b929 100644 --- a/helm-chart.yml +++ b/helm-chart.yml @@ -11,7 +11,7 @@ image: variables: HELM_EXPERIMENTAL_OCI: 1 AUTO_RELEASE: "true" - PIPELINE_IMAGE_TAG: 8a7c81d60fcac515e43bfea0699f7df484b947e2 + PIPELINE_IMAGE_TAG: 1f10ce362fb8ed09942561aee1f9c274f3e29313 stages: - lint diff --git a/monorepo.yml b/monorepo.yml index 1b0bf40..9257cd5 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -13,7 +13,7 @@ include: variables: IS_MONOREPO: 1 - PIPELINE_IMAGE_TAG: 8a7c81d60fcac515e43bfea0699f7df484b947e2 + PIPELINE_IMAGE_TAG: 1f10ce362fb8ed09942561aee1f9c274f3e29313 image: git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG diff --git a/panter-kubernetes-base.yml b/panter-kubernetes-base.yml index aec62d1..7860e40 100644 --- a/panter-kubernetes-base.yml +++ b/panter-kubernetes-base.yml @@ -12,7 +12,7 @@ include: - /includes/open-mr.yml variables: - PIPELINE_IMAGE_TAG: 8a7c81d60fcac515e43bfea0699f7df484b947e2 + PIPELINE_IMAGE_TAG: 1f10ce362fb8ed09942561aee1f9c274f3e29313 CUSTOMER_NAME: panter APP_NAME: demo COMPONENT_NAME: web -- GitLab From c635fe1059020b51455a461d4ec93bd2f4f8d3f5 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Tue, 30 Nov 2021 15:57:52 +0100 Subject: [PATCH 21/34] asrsdf --- monorepo.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monorepo.yml b/monorepo.yml index 9257cd5..d344da1 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -31,7 +31,7 @@ setup-build-info: - .retry-default - .rules-build-and-deploy script: - - . ./dockerfiles/pipeline/scripts/getCommitInfo + - . getCommitInfo artifacts: paths: - $CI_PROJECT_DIR/__build_info.json -- GitLab From 52a4c7478f0530f2280123899f9ca2de527dbd6d Mon Sep 17 00:00:00 2001 From: Gitlab Runner Date: Tue, 30 Nov 2021 15:02:47 +0000 Subject: [PATCH 22/34] adjust PIPELINE_IMAGE_TAG --- helm-chart.yml | 2 +- monorepo.yml | 2 +- panter-kubernetes-base.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helm-chart.yml b/helm-chart.yml index 2a1b929..95a8030 100644 --- a/helm-chart.yml +++ b/helm-chart.yml @@ -11,7 +11,7 @@ image: variables: HELM_EXPERIMENTAL_OCI: 1 AUTO_RELEASE: "true" - PIPELINE_IMAGE_TAG: 1f10ce362fb8ed09942561aee1f9c274f3e29313 + PIPELINE_IMAGE_TAG: c635fe1059020b51455a461d4ec93bd2f4f8d3f5 stages: - lint diff --git a/monorepo.yml b/monorepo.yml index d344da1..b09e17f 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -13,7 +13,7 @@ include: variables: IS_MONOREPO: 1 - PIPELINE_IMAGE_TAG: 1f10ce362fb8ed09942561aee1f9c274f3e29313 + PIPELINE_IMAGE_TAG: c635fe1059020b51455a461d4ec93bd2f4f8d3f5 image: git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG diff --git a/panter-kubernetes-base.yml b/panter-kubernetes-base.yml index 7860e40..102ffc1 100644 --- a/panter-kubernetes-base.yml +++ b/panter-kubernetes-base.yml @@ -12,7 +12,7 @@ include: - /includes/open-mr.yml variables: - PIPELINE_IMAGE_TAG: 1f10ce362fb8ed09942561aee1f9c274f3e29313 + PIPELINE_IMAGE_TAG: c635fe1059020b51455a461d4ec93bd2f4f8d3f5 CUSTOMER_NAME: panter APP_NAME: demo COMPONENT_NAME: web -- GitLab From 60b8a3a3951b84022c4ccb4d4cba3a49e4e4b677 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Tue, 30 Nov 2021 16:12:38 +0100 Subject: [PATCH 23/34] pushitfix --- dockerfiles/pipeline/scripts/getCommitInfo | 7 ++++++- monorepo.yml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dockerfiles/pipeline/scripts/getCommitInfo b/dockerfiles/pipeline/scripts/getCommitInfo index f308aba..43f17a6 100755 --- a/dockerfiles/pipeline/scripts/getCommitInfo +++ b/dockerfiles/pipeline/scripts/getCommitInfo @@ -1,7 +1,12 @@ #!/bin/bash export BUILD_TAG="$(git describe --tags || git rev-parse HEAD)" -export BUILD_ID="$COMPONENT_NAME-$BUILD_TAG" +if [[ -z "${COMPONENT_NAME}" ]]; then + export BUILD_ID="$BUILD_TAG" +else + export BUILD_ID="$COMPONENT_NAME-$BUILD_TAG" +fi + export BUILD_COMMIT="$(git rev-parse HEAD)" export BUILD_TIME="$(date)" echo "BUILD_TAG=$BUILD_TAG" >>build.env diff --git a/monorepo.yml b/monorepo.yml index b09e17f..76da559 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -13,7 +13,7 @@ include: variables: IS_MONOREPO: 1 - PIPELINE_IMAGE_TAG: c635fe1059020b51455a461d4ec93bd2f4f8d3f5 + PIPELINE_IMAGE_TAG: 8a7c81d60fcac515e43bfea0699f7df484b947e2 image: git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG -- GitLab From ee999c06dfc9c15551291d3d30e842b0933fa392 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Tue, 30 Nov 2021 16:12:20 +0100 Subject: [PATCH 24/34] pushit --- panter-kubernetes-base.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/panter-kubernetes-base.yml b/panter-kubernetes-base.yml index 102ffc1..d7b4f7f 100644 --- a/panter-kubernetes-base.yml +++ b/panter-kubernetes-base.yml @@ -119,7 +119,9 @@ image: git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG extends: - .retry-default - .rules-build-and-deploy - needs: ["setup-build-info"] + needs: + - job: setup-build-info + optional: true .app-build: extends: .app-build-base -- GitLab From e61576ba756ed42babe44149bf9a953d824a79e6 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Tue, 30 Nov 2021 16:20:57 +0100 Subject: [PATCH 25/34] fix? --- dockerfiles/pipeline/scripts/getCommitInfo | 7 +------ dockerfiles/pipeline/scripts/monorepoGenerate.ts | 1 + includes/docker-build.yml | 7 ++++++- includes/verify.yml | 9 +++++---- panter-kubernetes-base.yml | 3 +++ 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/dockerfiles/pipeline/scripts/getCommitInfo b/dockerfiles/pipeline/scripts/getCommitInfo index 43f17a6..f906ba9 100755 --- a/dockerfiles/pipeline/scripts/getCommitInfo +++ b/dockerfiles/pipeline/scripts/getCommitInfo @@ -1,12 +1,7 @@ #!/bin/bash export BUILD_TAG="$(git describe --tags || git rev-parse HEAD)" -if [[ -z "${COMPONENT_NAME}" ]]; then - export BUILD_ID="$BUILD_TAG" -else - export BUILD_ID="$COMPONENT_NAME-$BUILD_TAG" -fi - +export BUILD_ID="$BUILD_TAG" export BUILD_COMMIT="$(git rev-parse HEAD)" export BUILD_TIME="$(date)" echo "BUILD_TAG=$BUILD_TAG" >>build.env diff --git a/dockerfiles/pipeline/scripts/monorepoGenerate.ts b/dockerfiles/pipeline/scripts/monorepoGenerate.ts index 5749904..4f2e98b 100755 --- a/dockerfiles/pipeline/scripts/monorepoGenerate.ts +++ b/dockerfiles/pipeline/scripts/monorepoGenerate.ts @@ -66,6 +66,7 @@ const makeConfig = async ({ APP_DIR: subapp, VALUES_DIR: subapp, COMPONENT_NAME: subapp, + PARENT_PIPELINE_ID: "$CI_PIPELINE_ID", [type.toUpperCase() + "_ONLY"]: "1", ...(await extractBuildEnv(subapp, env)), }, diff --git a/includes/docker-build.yml b/includes/docker-build.yml index efee71f..9832107 100644 --- a/includes/docker-build.yml +++ b/includes/docker-build.yml @@ -75,7 +75,12 @@ variables: - .before-script-yarn stage: build - needs: ["setup-build-info"] + needs: + - job: setup-build-info + optional: true + - job: setup-build-info + optional: true + pipeline: $pipeline # don't do it after the semantic release commit, but do it after tag script: - cd $APP_PATH diff --git a/includes/verify.yml b/includes/verify.yml index 86cd865..681aa3c 100644 --- a/includes/verify.yml +++ b/includes/verify.yml @@ -32,6 +32,7 @@ .verify-base: before_script: + - . getCommitInfo - set +e # Disable exit on error - *checkBuildId - set -e # Enable exit on error @@ -50,14 +51,14 @@ - if: $TEST_ONLY when: never - if: $CI_MERGE_REQUEST_ID - needs: ["review-deploy", "setup-build-info"] + needs: ["review-deploy"] .verify-dev: stage: verify extends: - .verify-base - .env-dev - needs: ["dev-deploy", "setup-build-info"] + needs: ["dev-deploy"] rules: - if: $TEST_ONLY when: never @@ -71,7 +72,7 @@ extends: - .verify-base - .env-stage - needs: ["stage-deploy", "setup-build-info"] + needs: ["stage-deploy"] rules: - if: $TEST_ONLY when: never @@ -82,7 +83,7 @@ extends: - .verify-base - .env-prod - needs: ["prod-deploy", "setup-build-info"] + needs: ["prod-deploy"] rules: - if: $TEST_ONLY when: never diff --git a/panter-kubernetes-base.yml b/panter-kubernetes-base.yml index d7b4f7f..029d436 100644 --- a/panter-kubernetes-base.yml +++ b/panter-kubernetes-base.yml @@ -122,6 +122,9 @@ image: git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG needs: - job: setup-build-info optional: true + - job: setup-build-info + optional: true + pipeline: $pipeline .app-build: extends: .app-build-base -- GitLab From 4587bdb55a6d1e90eb08277eb9b143b5c58c3bf7 Mon Sep 17 00:00:00 2001 From: Gitlab Runner Date: Tue, 30 Nov 2021 15:25:00 +0000 Subject: [PATCH 26/34] adjust PIPELINE_IMAGE_TAG --- helm-chart.yml | 2 +- monorepo.yml | 2 +- panter-kubernetes-base.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helm-chart.yml b/helm-chart.yml index 95a8030..fdf3252 100644 --- a/helm-chart.yml +++ b/helm-chart.yml @@ -11,7 +11,7 @@ image: variables: HELM_EXPERIMENTAL_OCI: 1 AUTO_RELEASE: "true" - PIPELINE_IMAGE_TAG: c635fe1059020b51455a461d4ec93bd2f4f8d3f5 + PIPELINE_IMAGE_TAG: e61576ba756ed42babe44149bf9a953d824a79e6 stages: - lint diff --git a/monorepo.yml b/monorepo.yml index 76da559..d4815b5 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -13,7 +13,7 @@ include: variables: IS_MONOREPO: 1 - PIPELINE_IMAGE_TAG: 8a7c81d60fcac515e43bfea0699f7df484b947e2 + PIPELINE_IMAGE_TAG: e61576ba756ed42babe44149bf9a953d824a79e6 image: git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG diff --git a/panter-kubernetes-base.yml b/panter-kubernetes-base.yml index 029d436..d58502a 100644 --- a/panter-kubernetes-base.yml +++ b/panter-kubernetes-base.yml @@ -12,7 +12,7 @@ include: - /includes/open-mr.yml variables: - PIPELINE_IMAGE_TAG: c635fe1059020b51455a461d4ec93bd2f4f8d3f5 + PIPELINE_IMAGE_TAG: e61576ba756ed42babe44149bf9a953d824a79e6 CUSTOMER_NAME: panter APP_NAME: demo COMPONENT_NAME: web -- GitLab From cb3b476085e3001943d213b19c5276fc10fc917f Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Tue, 30 Nov 2021 16:30:31 +0100 Subject: [PATCH 27/34] undo --- includes/docker-build.yml | 7 +------ includes/setup.yml | 3 --- monorepo.yml | 16 +--------------- panter-kubernetes-base.yml | 7 +------ 4 files changed, 3 insertions(+), 30 deletions(-) diff --git a/includes/docker-build.yml b/includes/docker-build.yml index 9832107..efee71f 100644 --- a/includes/docker-build.yml +++ b/includes/docker-build.yml @@ -75,12 +75,7 @@ variables: - .before-script-yarn stage: build - needs: - - job: setup-build-info - optional: true - - job: setup-build-info - optional: true - pipeline: $pipeline + needs: ["setup-build-info"] # don't do it after the semantic release commit, but do it after tag script: - cd $APP_PATH diff --git a/includes/setup.yml b/includes/setup.yml index 6cfafba..f425dfd 100644 --- a/includes/setup.yml +++ b/includes/setup.yml @@ -1,9 +1,6 @@ .setup-build-info: stage: setup interruptible: true - rules: - - if: $IS_MONOREPO # we do this differently in monorepos - when: never extends: - .retry-default - .rules-build-and-deploy diff --git a/monorepo.yml b/monorepo.yml index d4815b5..28b874a 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -24,20 +24,6 @@ stages: - verify - create-release -setup-build-info: - stage: setup - interruptible: true - extends: - - .retry-default - - .rules-build-and-deploy - script: - - . getCommitInfo - artifacts: - paths: - - $CI_PROJECT_DIR/__build_info.json - reports: - dotenv: build.env - create-pipeline: stage: setup interruptible: true @@ -65,7 +51,7 @@ test: deploy: stage: deploy - needs: [setup-build-info, create-pipeline] + needs: [create-pipeline] extends: - .rules-always trigger: diff --git a/panter-kubernetes-base.yml b/panter-kubernetes-base.yml index d58502a..a7e6ed2 100644 --- a/panter-kubernetes-base.yml +++ b/panter-kubernetes-base.yml @@ -119,12 +119,7 @@ image: git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG extends: - .retry-default - .rules-build-and-deploy - needs: - - job: setup-build-info - optional: true - - job: setup-build-info - optional: true - pipeline: $pipeline + needs: ["setup-build-info"] .app-build: extends: .app-build-base -- GitLab From 1a5f08b568d200068742cbc6a78536025f972d22 Mon Sep 17 00:00:00 2001 From: Gitlab Runner Date: Tue, 30 Nov 2021 15:34:29 +0000 Subject: [PATCH 28/34] adjust PIPELINE_IMAGE_TAG --- helm-chart.yml | 2 +- monorepo.yml | 2 +- panter-kubernetes-base.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helm-chart.yml b/helm-chart.yml index fdf3252..b74e96c 100644 --- a/helm-chart.yml +++ b/helm-chart.yml @@ -11,7 +11,7 @@ image: variables: HELM_EXPERIMENTAL_OCI: 1 AUTO_RELEASE: "true" - PIPELINE_IMAGE_TAG: e61576ba756ed42babe44149bf9a953d824a79e6 + PIPELINE_IMAGE_TAG: cb3b476085e3001943d213b19c5276fc10fc917f stages: - lint diff --git a/monorepo.yml b/monorepo.yml index 28b874a..5268bc3 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -13,7 +13,7 @@ include: variables: IS_MONOREPO: 1 - PIPELINE_IMAGE_TAG: e61576ba756ed42babe44149bf9a953d824a79e6 + PIPELINE_IMAGE_TAG: cb3b476085e3001943d213b19c5276fc10fc917f image: git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG diff --git a/panter-kubernetes-base.yml b/panter-kubernetes-base.yml index a7e6ed2..32c9b8d 100644 --- a/panter-kubernetes-base.yml +++ b/panter-kubernetes-base.yml @@ -12,7 +12,7 @@ include: - /includes/open-mr.yml variables: - PIPELINE_IMAGE_TAG: e61576ba756ed42babe44149bf9a953d824a79e6 + PIPELINE_IMAGE_TAG: cb3b476085e3001943d213b19c5276fc10fc917f CUSTOMER_NAME: panter APP_NAME: demo COMPONENT_NAME: web -- GitLab From 3f8eafb2d3848e23d11f337fd9e0f60ebccd01f2 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Tue, 30 Nov 2021 18:01:31 +0100 Subject: [PATCH 29/34] fix --- includes/setup.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/setup.yml b/includes/setup.yml index f425dfd..25ccef6 100644 --- a/includes/setup.yml +++ b/includes/setup.yml @@ -6,7 +6,6 @@ - .rules-build-and-deploy script: - . getCommitInfo - - printBuildEnv.ts -d >> build.env - echo '{"id":"'$BUILD_ID'","commit":"'$BUILD_COMMIT'","tag":"'$BUILD_TAG'","time":"'$BUILD_TIME'"}' > $APP_DIR/__build_info.json artifacts: paths: -- GitLab From 8c3943671876270fc31fad747ec50738b29c17f2 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Tue, 30 Nov 2021 18:04:53 +0100 Subject: [PATCH 30/34] fudi --- dockerfiles/pipeline/scripts/monorepoGenerate.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dockerfiles/pipeline/scripts/monorepoGenerate.ts b/dockerfiles/pipeline/scripts/monorepoGenerate.ts index 4f2e98b..0a24a9f 100755 --- a/dockerfiles/pipeline/scripts/monorepoGenerate.ts +++ b/dockerfiles/pipeline/scripts/monorepoGenerate.ts @@ -85,6 +85,10 @@ const generateSubPipeline = async (type: Type, envs: string[]) => { ...(await subcis.reduce( async (inneracc, { dirname, ci }) => ({ ...(await inneracc), + fudi: { + stage: "test", + script: ["env"], + }, [`${env}-${dirname} ${type}`]: await makeConfig({ subapp: dirname, ci, -- GitLab From 212983cacca55303c751629215ebd91af7a711db Mon Sep 17 00:00:00 2001 From: Gitlab Runner Date: Tue, 30 Nov 2021 17:08:59 +0000 Subject: [PATCH 31/34] adjust PIPELINE_IMAGE_TAG --- helm-chart.yml | 2 +- monorepo.yml | 2 +- panter-kubernetes-base.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helm-chart.yml b/helm-chart.yml index b74e96c..7e148e6 100644 --- a/helm-chart.yml +++ b/helm-chart.yml @@ -11,7 +11,7 @@ image: variables: HELM_EXPERIMENTAL_OCI: 1 AUTO_RELEASE: "true" - PIPELINE_IMAGE_TAG: cb3b476085e3001943d213b19c5276fc10fc917f + PIPELINE_IMAGE_TAG: 8c3943671876270fc31fad747ec50738b29c17f2 stages: - lint diff --git a/monorepo.yml b/monorepo.yml index 5268bc3..df0356a 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -13,7 +13,7 @@ include: variables: IS_MONOREPO: 1 - PIPELINE_IMAGE_TAG: cb3b476085e3001943d213b19c5276fc10fc917f + PIPELINE_IMAGE_TAG: 8c3943671876270fc31fad747ec50738b29c17f2 image: git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG diff --git a/panter-kubernetes-base.yml b/panter-kubernetes-base.yml index 32c9b8d..9a09b14 100644 --- a/panter-kubernetes-base.yml +++ b/panter-kubernetes-base.yml @@ -12,7 +12,7 @@ include: - /includes/open-mr.yml variables: - PIPELINE_IMAGE_TAG: cb3b476085e3001943d213b19c5276fc10fc917f + PIPELINE_IMAGE_TAG: 8c3943671876270fc31fad747ec50738b29c17f2 CUSTOMER_NAME: panter APP_NAME: demo COMPONENT_NAME: web -- GitLab From 4cf95f0c32462e05ee2d9ddd6e852aa31a9d8819 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Tue, 30 Nov 2021 18:26:03 +0100 Subject: [PATCH 32/34] test --- dockerfiles/pipeline/scripts/monorepoGenerate.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dockerfiles/pipeline/scripts/monorepoGenerate.ts b/dockerfiles/pipeline/scripts/monorepoGenerate.ts index 0a24a9f..4d739aa 100755 --- a/dockerfiles/pipeline/scripts/monorepoGenerate.ts +++ b/dockerfiles/pipeline/scripts/monorepoGenerate.ts @@ -89,12 +89,14 @@ const generateSubPipeline = async (type: Type, envs: string[]) => { stage: "test", script: ["env"], }, + /* [`${env}-${dirname} ${type}`]: await makeConfig({ subapp: dirname, ci, type, env, }), + */ }), {} as Promise> )), -- GitLab From c88ce3adb43135b527482bf24a9420bc4fbd0d62 Mon Sep 17 00:00:00 2001 From: Marco Wettstein Date: Tue, 30 Nov 2021 18:33:53 +0100 Subject: [PATCH 33/34] test --- dockerfiles/pipeline/scripts/monorepoGenerate.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/dockerfiles/pipeline/scripts/monorepoGenerate.ts b/dockerfiles/pipeline/scripts/monorepoGenerate.ts index 4d739aa..8a2c533 100755 --- a/dockerfiles/pipeline/scripts/monorepoGenerate.ts +++ b/dockerfiles/pipeline/scripts/monorepoGenerate.ts @@ -88,6 +88,7 @@ const generateSubPipeline = async (type: Type, envs: string[]) => { fudi: { stage: "test", script: ["env"], + rules: [{ if: "$CI_MERGE_REQUEST_ID" }], }, /* [`${env}-${dirname} ${type}`]: await makeConfig({ -- GitLab From 60e230490902d24872f1a3a18cbd5e00bf5fa2db Mon Sep 17 00:00:00 2001 From: Gitlab Runner Date: Tue, 30 Nov 2021 17:37:59 +0000 Subject: [PATCH 34/34] adjust PIPELINE_IMAGE_TAG --- helm-chart.yml | 2 +- monorepo.yml | 2 +- panter-kubernetes-base.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helm-chart.yml b/helm-chart.yml index 7e148e6..ef4733d 100644 --- a/helm-chart.yml +++ b/helm-chart.yml @@ -11,7 +11,7 @@ image: variables: HELM_EXPERIMENTAL_OCI: 1 AUTO_RELEASE: "true" - PIPELINE_IMAGE_TAG: 8c3943671876270fc31fad747ec50738b29c17f2 + PIPELINE_IMAGE_TAG: c88ce3adb43135b527482bf24a9420bc4fbd0d62 stages: - lint diff --git a/monorepo.yml b/monorepo.yml index df0356a..0b522de 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -13,7 +13,7 @@ include: variables: IS_MONOREPO: 1 - PIPELINE_IMAGE_TAG: 8c3943671876270fc31fad747ec50738b29c17f2 + PIPELINE_IMAGE_TAG: c88ce3adb43135b527482bf24a9420bc4fbd0d62 image: git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG diff --git a/panter-kubernetes-base.yml b/panter-kubernetes-base.yml index 9a09b14..25a14b1 100644 --- a/panter-kubernetes-base.yml +++ b/panter-kubernetes-base.yml @@ -12,7 +12,7 @@ include: - /includes/open-mr.yml variables: - PIPELINE_IMAGE_TAG: 8c3943671876270fc31fad747ec50738b29c17f2 + PIPELINE_IMAGE_TAG: c88ce3adb43135b527482bf24a9420bc4fbd0d62 CUSTOMER_NAME: panter APP_NAME: demo COMPONENT_NAME: web -- GitLab