@catladder/pipeline 1.53.0 → 1.55.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,12 +1,37 @@
1
1
  import type { DeployTypeDefinition } from "..";
2
- import { createDeployJob } from "./deployJob";
2
+ import { getSecretVarName } from "../../context";
3
+ import { createGoogleCloudRunDeployJobs } from "./deployJob";
3
4
 
4
5
  export const GCLOUD_DEPLOY_CREDENTIALS_KEY = "GCLOUD_DEPLOY_credentialsKey";
5
6
 
6
7
  export const GCLOUD_RUN_CANONICAL_HOST_SUFFIX =
7
8
  "GCLOUD_RUN_canonicalHostSuffix";
9
+
8
10
  export const GCLOUD_RUN_DEPLOY_TYPE: DeployTypeDefinition<"google-cloudrun"> = {
9
- jobs: createDeployJob,
11
+ jobs: createGoogleCloudRunDeployJobs,
10
12
  defaults: () => ({}),
11
13
  additionalSecretKeys: () => [GCLOUD_DEPLOY_CREDENTIALS_KEY],
14
+ getAdditionalEnvVars: ({ fullName, env, componentName, deployConfig }) => {
15
+ const HOST_CANONICAL =
16
+ fullName.toLowerCase() +
17
+ "-" +
18
+ process.env[
19
+ getSecretVarName(env, componentName, GCLOUD_RUN_CANONICAL_HOST_SUFFIX)
20
+ ];
21
+
22
+ const jobTriggers =
23
+ deployConfig && deployConfig.jobs
24
+ ? Object.fromEntries(
25
+ Object.entries(deployConfig.jobs).map(([name, job]) => [
26
+ "CLOUD_RUN_JOB_TRIGGER_URL_" + name,
27
+ `https://${deployConfig.region}-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${deployConfig.projectId}/jobs/${name}:run`,
28
+ ])
29
+ )
30
+ : {};
31
+
32
+ return {
33
+ HOST_CANONICAL,
34
+ ...jobTriggers,
35
+ };
36
+ },
12
37
  };
@@ -5,4 +5,5 @@ export const CUSTOM_DEPLOY_TYPE: DeployTypeDefinition<"custom"> = {
5
5
  jobs: createCustomDeployJobs,
6
6
  defaults: () => ({}),
7
7
  additionalSecretKeys: () => [],
8
+ getAdditionalEnvVars: () => ({}),
8
9
  };
@@ -5,4 +5,5 @@ export const DOCKER_TAG_DEPLOY_TYPE: DeployTypeDefinition<"dockerTag"> = {
5
5
  jobs: createDockerTagDeployJobs,
6
6
  defaults: () => ({}),
7
7
  additionalSecretKeys: () => [],
8
+ getAdditionalEnvVars: () => ({}),
8
9
  };
@@ -1,4 +1,5 @@
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
4
  import { GCLOUD_RUN_DEPLOY_TYPE } from "./cloudRun";
4
5
  import { CUSTOM_DEPLOY_TYPE } from "./custom";
@@ -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
+ "google-cloudrun": GCLOUD_RUN_DEPLOY_TYPE,
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,10 +37,27 @@ export type Gcloudregion =
37
37
  | "us-west3"
38
38
  | "us-west4";
39
39
 
40
+ export type DeployConfigCloudRunService = {
41
+ /**
42
+ * command / entrypoint, fallsback to buildConfig.startcommand
43
+ */
44
+ command?: string;
45
+ };
46
+
47
+ export type DeployConfigCloudRunJob = {
48
+ /**
49
+ * command
50
+ */
51
+ command: string;
52
+
53
+ when: "manual" | "postDeploy";
54
+ };
40
55
  export type DeployConfigCloudRun = {
41
56
  /**
42
57
  * EXPERIMENTAL cloud run deployment.
43
58
  *
59
+ * This will deploy a cloud run service.
60
+ *
44
61
  * Requires that cloud run is enabled on the project, as well as cloud run api and artifacts registry.
45
62
  */
46
63
  type: "google-cloudrun";
@@ -52,4 +69,13 @@ export type DeployConfigCloudRun = {
52
69
  * the region. Set to europe-west6 for switzerland
53
70
  */
54
71
  region: Gcloudregion;
72
+
73
+ /**
74
+ * whether to enable the service, defaults to true
75
+ */
76
+ service?: boolean | DeployConfigCloudRunService;
77
+
78
+ jobs?: {
79
+ [name: string]: DeployConfigCloudRunJob;
80
+ };
55
81
  } & DeployConfigBase;