Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • catladder/catladder
1 result
Show changes
Commits on Source (4)
# [1.20.0](https://git.panter.ch/catladder/catladder/compare/v1.19.1...v1.20.0) (2022-04-12)
### Bug Fixes
* endless loop in resolve references ([7e63586](https://git.panter.ch/catladder/catladder/commit/7e63586a0e47a2bbc505e516efb7e288a5e518c8))
### Features
* allow to force manual/auto deploy per env ([45fcace](https://git.panter.ch/catladder/catladder/commit/45fcace89e85ea74d483f000eb22225fe949d036))
## [1.19.1](https://git.panter.ch/catladder/catladder/compare/v1.19.0...v1.19.1) (2022-04-08)
......
......@@ -30,7 +30,8 @@ export const getEnvironment = (
config: Config,
componentName: string,
env: string,
commitInfo?: CommitInfo
commitInfo?: CommitInfo,
alreadyVisited: Record<string, Record<string, boolean>> = {} // to prevent endless loop
): Environment => {
const componentConfig = config.components[componentName];
if (!componentConfig) {
......@@ -151,15 +152,17 @@ export const getEnvironment = (
const envVars = resolveReferences(
envVarsRaw,
(componentName, variableName) => {
(componentName, variableName, alreadyVisited) => {
const { envVars } = getEnvironment(
config,
componentName,
env,
commitInfo
commitInfo,
alreadyVisited
);
return envVars[variableName];
}
},
alreadyVisited
);
return {
envType,
......
......@@ -6,32 +6,37 @@ export const resolveReferences = (
vars: Record<string, string>,
getOtherVariables?: (
componentName: string,
variableName: string
) => string | null
variableName: string,
alreadyVisited: Record<string, Record<string, boolean>>
) => string | null,
alreadyVisitedBase: Record<string, Record<string, boolean>> = {}
) => {
console.log("resolve", alreadyVisitedBase);
const replaceSingleValue = (
value: string,
alreadyVisited: Record<string, Record<string, boolean>> = {}
alreadyVisited: Record<string, Record<string, boolean>> = alreadyVisitedBase
): string => {
if (REGEX.test(value)) {
return value.replace(REGEX, (match, _, componentName, variableName) => {
if (alreadyVisited[componentName]?.[variableName]) {
return match; // prevent endless loop
}
const newAlreadyVisited = merge({}, alreadyVisited, {
[componentName]: {
[variableName]: true,
},
});
const result = componentName
? getOtherVariables?.(componentName, variableName) ?? null
? getOtherVariables?.(
componentName,
variableName,
newAlreadyVisited
) ?? null
: vars[variableName]; // is self reference
const replaced =
result !== null && result !== undefined
? replaceSingleValue(
result,
merge({}, alreadyVisited, {
[componentName]: {
[variableName]: true,
},
})
)
? replaceSingleValue(result, newAlreadyVisited)
: match;
return replaced;
......
......@@ -19,17 +19,24 @@ export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
const autoStop =
context.environment.envType === "review"
? "2 weeks"
? "3 days" // auto stop is not working properly when branch is merged, so we do
: context.environment.envType === "dev"
? "3 weeks"
: undefined;
// automatically run deploy job, unless its prod and stage is active
const autoDeploy =
// if auto or manual is configured explicitly, use that
const whenDeployDefined =
context.componentConfig.deploy && context.componentConfig.deploy.when
? context.componentConfig.deploy.when
: undefined;
// otherwise auto deploy if env is not prod. If its prod, deploy automatically if stage is disabled
const whenDeployDefault =
context.environment.envType !== "prod"
? true // is not stage, auto deploy
? "auto" // is not stage, auto deploy
: context.componentConfig.env?.stage === false
? true // is prod, but no staging, auto deploy
: false; // manually deploy
? "auto" // is prod, but no staging, auto deploy
: "manual"; // manually deploy
const whenDeploy = whenDeployDefined ? whenDeployDefined : whenDeployDefault;
return {
name: DEPLOY_JOB_NAME,
envMode: "stagePerEnv", // makes it easier to run manual tasks er env
......@@ -46,7 +53,7 @@ export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
], // workaround for https://gitlab.com/gitlab-org/gitlab/-/issues/220758
rules: [
autoDeploy
whenDeploy === "auto"
? {
when: "on_success",
}
......
......@@ -134,6 +134,12 @@ export type DeployConfigKubernetes = {
* values to configure the app
*/
values?: DeployConfigKubernetesValues;
/**
* whether to deploy automatically or manual. If not defined, these rules apply:
* - prod: manual
* - all other envs: auto
*/
when?: "manual" | "auto";
} & DeployConfigBase;
type CustomDeployConfig = {
......