@catladder/pipeline 1.52.2 → 1.54.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.
@@ -1,6 +1,7 @@
1
- import type { Context } from "../types/context";
1
+ import type { Config, EnvType } from "../types";
2
+ import type { CommitInfo, Context } from "../types/context";
2
3
  import type { CatladderJob } from "../types/jobs";
3
- import { GCLOUD_RUN_DEPLOY_TYPE } from "./cloudRun";
4
+ import { GCLOUD_RUN_DEPLOY_TYPES } from "./cloudRun";
4
5
  import { CUSTOM_DEPLOY_TYPE } from "./custom";
5
6
  import { DOCKER_TAG_DEPLOY_TYPE } from "./dockerTag";
6
7
  import { KUBERNETES_DEPLOY_TYPE } from "./kubernetes";
@@ -9,10 +10,27 @@ export * from "./kubernetes";
9
10
  export * from "./types";
10
11
  export * from "./utils";
11
12
 
13
+ export type EnvVarContext<D extends DeployConfigType> = {
14
+ deployConfig: false | DeployConfigGeneric<D>;
15
+ commitInfo?: CommitInfo;
16
+ env: string;
17
+ envType: EnvType;
18
+ componentName: string;
19
+ fullName: string;
20
+
21
+ /**
22
+ * the full catladder config
23
+ */
24
+ fullConfig: Config;
25
+ };
26
+
12
27
  export type DeployTypeDefinition<T extends DeployConfigType> = {
13
28
  jobs: (context: Context) => CatladderJob[];
14
29
  defaults: () => Partial<DeployConfigGeneric<T>>;
15
- additionalSecretKeys: (config: DeployConfigGeneric<T>) => string[];
30
+ additionalSecretKeys: (envVarContext: EnvVarContext<T>) => string[];
31
+ getAdditionalEnvVars: (
32
+ envVarContext: EnvVarContext<T>
33
+ ) => Record<string, string | undefined | null>;
16
34
  };
17
35
  export * from "./cloudSql";
18
36
  export * from "./cloudRun";
@@ -23,6 +41,6 @@ export type DeployTypes = {
23
41
  export const DEPLOY_TYPES: DeployTypes = {
24
42
  kubernetes: KUBERNETES_DEPLOY_TYPE,
25
43
  custom: CUSTOM_DEPLOY_TYPE,
26
- "google-cloudrun": GCLOUD_RUN_DEPLOY_TYPE,
27
44
  dockerTag: DOCKER_TAG_DEPLOY_TYPE,
45
+ ...GCLOUD_RUN_DEPLOY_TYPES,
28
46
  };
@@ -1,17 +1,20 @@
1
- import type { DeployConfigKubernetes } from "../types";
1
+ import type { EnvVarContext } from "..";
2
2
 
3
- export const additionalKubernetesSecretKeys = (
4
- config: DeployConfigKubernetes
5
- ) => {
3
+ export const additionalKubernetesSecretKeys = ({
4
+ deployConfig,
5
+ }: EnvVarContext<"kubernetes">) => {
6
+ if (!deployConfig) {
7
+ return [];
8
+ }
6
9
  const keys = [];
7
- if (config.values?.mongodb?.enabled) {
10
+ if (deployConfig.values?.mongodb?.enabled) {
8
11
  keys.push("MONGODB_ROOT_PASSWORD");
9
- if (config.values.mongodb.architecture === "replicaset") {
12
+ if (deployConfig.values.mongodb.architecture === "replicaset") {
10
13
  keys.push("MONGODB_REPLICASET_KEY");
11
14
  }
12
15
  }
13
16
 
14
- if (config.values?.cloudsql?.enabled) {
17
+ if (deployConfig.values?.cloudsql?.enabled) {
15
18
  keys.push("POSTGRESQL_PASSWORD");
16
19
  keys.push("cloudsqlProxyCredentials");
17
20
  }
@@ -1,4 +1,6 @@
1
+ import slugify from "slugify";
1
2
  import type { DeployTypeDefinition } from "..";
3
+ import { getKubernetesNamespace } from "..";
2
4
  import { additionalKubernetesSecretKeys } from "./additionalSecretKeys";
3
5
  import { createKubernetesDeployJobs } from "./deployJob";
4
6
 
@@ -6,4 +8,35 @@ export const KUBERNETES_DEPLOY_TYPE: DeployTypeDefinition<"kubernetes"> = {
6
8
  jobs: createKubernetesDeployJobs,
7
9
  defaults: () => ({}),
8
10
  additionalSecretKeys: additionalKubernetesSecretKeys,
11
+ getAdditionalEnvVars: ({
12
+ componentName,
13
+ fullConfig,
14
+ deployConfig,
15
+ env,
16
+ envType,
17
+ commitInfo,
18
+ }) => {
19
+ const KUBE_APP_NAME_PREFIX =
20
+ envType === "review" && commitInfo ? `${commitInfo.reviewSlug}-` : "";
21
+ const KUBE_APP_NAME = `${KUBE_APP_NAME_PREFIX}${componentName}`;
22
+ const KUBE_NAMESPACE = getKubernetesNamespace(fullConfig, env);
23
+ const componentSlug = slugify(componentName);
24
+ const envInUrl =
25
+ envType === "review" && commitInfo
26
+ ? `${commitInfo.reviewSlug}.${env}`
27
+ : env;
28
+
29
+ const domainCanonical =
30
+ (deployConfig && deployConfig.cluster?.domainCanonical) || // for convenience, we allow clusters to define a canonical domain, because a cluster has a fixed ip and you will usually have a domain pointing to that cluster
31
+ fullConfig.domainCanonical ||
32
+ "panter.cloud";
33
+ const HOST_CANONICAL = `${componentSlug}.${envInUrl}.${fullConfig.appName}.${fullConfig.customerName}.${domainCanonical}`; // default for kubernetes and rest
34
+
35
+ return {
36
+ KUBE_NAMESPACE,
37
+ KUBE_APP_NAME,
38
+ KUBE_APP_NAME_PREFIX,
39
+ HOST_CANONICAL,
40
+ };
41
+ },
9
42
  };
@@ -37,13 +37,7 @@ export type Gcloudregion =
37
37
  | "us-west3"
38
38
  | "us-west4";
39
39
 
40
- export type DeployConfigCloudRun = {
41
- /**
42
- * EXPERIMENTAL cloud run deployment.
43
- *
44
- * Requires that cloud run is enabled on the project, as well as cloud run api and artifacts registry.
45
- */
46
- type: "google-cloudrun";
40
+ export type DeployConfigCloudRunBase = {
47
41
  /**
48
42
  * the google cloud porject id
49
43
  */
@@ -52,4 +46,34 @@ export type DeployConfigCloudRun = {
52
46
  * the region. Set to europe-west6 for switzerland
53
47
  */
54
48
  region: Gcloudregion;
49
+
50
+ /**
51
+ * command / entrypoint, fallsback to buildConfig.startcommand
52
+ */
53
+ command?: string;
55
54
  } & DeployConfigBase;
55
+ export type DeployConfigCloudRunService = {
56
+ /**
57
+ * EXPERIMENTAL cloud run deployment.
58
+ *
59
+ * This will deploy a cloud run service.
60
+ *
61
+ * Requires that cloud run is enabled on the project, as well as cloud run api and artifacts registry.
62
+ */
63
+ type: "google-cloudrun";
64
+ } & DeployConfigCloudRunBase;
65
+
66
+ export type DeployConfigCloudRunJob = {
67
+ /**
68
+ * EXPERIMENTAL cloud run job.
69
+ *
70
+ * This will deploy a cloud run job. This does not do much currently, but will be later used for cronjobs
71
+ *
72
+ * Requires that cloud run is enabled on the project, as well as cloud run api and artifacts registry.
73
+ */
74
+ type: "google-cloudrun-job";
75
+ } & DeployConfigCloudRunBase;
76
+
77
+ export type DeployConfigCloudRun =
78
+ | DeployConfigCloudRunService
79
+ | DeployConfigCloudRunJob;