@catladder/pipeline 1.89.4 → 1.91.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/dist/bundles/catladder-gitlab/index.js +3 -3
- package/dist/constants.js +1 -1
- package/dist/context/getEnvironmentVariables.d.ts +5 -1
- package/dist/context/getEnvironmentVariables.js +7 -2
- package/dist/deploy/cloudRun/index.js +14 -5
- package/dist/deploy/cloudSql/utils.d.ts +3 -0
- package/dist/deploy/cloudSql/utils.js +9 -0
- package/dist/deploy/custom/deployJob.js +6 -3
- package/dist/deploy/index.d.ts +2 -1
- package/dist/deploy/kubernetes/additionalSecretKeys.d.ts +3 -1
- package/dist/deploy/kubernetes/additionalSecretKeys.js +5 -1
- package/dist/deploy/kubernetes/cloudSql/index.d.ts +10 -10
- package/dist/deploy/kubernetes/cloudSql/index.js +36 -15
- package/dist/deploy/kubernetes/kubeValues.d.ts +1 -6
- package/dist/deploy/kubernetes/kubeValues.js +1 -1
- package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +1 -6
- package/dist/deploy/types/kubernetes.d.ts +54 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +3 -3
- package/dist/types/context.d.ts +2 -1
- package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +24 -12
- package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +24 -12
- package/examples/__snapshots__/cloud-run-non-public.ts.snap +24 -12
- package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +48 -24
- package/examples/__snapshots__/cloud-run-with-sql.ts.snap +48 -24
- package/examples/__snapshots__/custom-build-job.ts.snap +24 -12
- package/examples/__snapshots__/custom-deploy.ts.snap +1384 -0
- package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.ts.snap +48 -12
- package/examples/__snapshots__/kubernetes-with-cloud-sql.ts.snap +2252 -0
- package/examples/__snapshots__/rails-k8s-with-worker.ts.snap +48 -12
- package/examples/custom-deploy.ts +25 -0
- package/examples/kubernetes-with-cloud-sql.ts +35 -0
- package/package.json +1 -1
- package/src/context/getEnvironmentVariables.ts +9 -4
- package/src/deploy/cloudRun/deployJob.ts +1 -1
- package/src/deploy/cloudRun/index.ts +16 -10
- package/src/deploy/cloudSql/utils.ts +23 -0
- package/src/deploy/custom/deployJob.ts +9 -1
- package/src/deploy/index.ts +4 -1
- package/src/deploy/kubernetes/additionalSecretKeys.ts +1 -1
- package/src/deploy/kubernetes/cloudSql/index.ts +58 -14
- package/src/deploy/kubernetes/kubeValues.ts +7 -2
- package/src/deploy/types/kubernetes.ts +59 -6
- package/src/types/context.ts +2 -1
|
@@ -89,8 +89,11 @@ application:
|
|
|
89
89
|
enabled: true
|
|
90
90
|
command: 'launcher bundle exec rake jobs:work'
|
|
91
91
|
cloudsql:
|
|
92
|
-
proxyCredentials: '$CL_dev_app_cloudsqlProxyCredentials'
|
|
93
92
|
enabled: true
|
|
93
|
+
dbUser: 'postgres'
|
|
94
|
+
instanceConnectionName: 'some-project-id:europe-west6:pan-test-app-dev'
|
|
95
|
+
proxyCredentials: '$CL_dev_app_cloudsqlProxyCredentials'
|
|
96
|
+
fullDbName: 'app'
|
|
94
97
|
projectId: 'some-project-id'
|
|
95
98
|
jobs:
|
|
96
99
|
db-migrate:
|
|
@@ -297,8 +300,11 @@ application:
|
|
|
297
300
|
enabled: true
|
|
298
301
|
command: 'launcher bundle exec rake jobs:work'
|
|
299
302
|
cloudsql:
|
|
300
|
-
proxyCredentials: '$CL_dev_app_cloudsqlProxyCredentials'
|
|
301
303
|
enabled: true
|
|
304
|
+
dbUser: 'postgres'
|
|
305
|
+
instanceConnectionName: 'some-project-id:europe-west6:pan-test-app-dev'
|
|
306
|
+
proxyCredentials: '$CL_dev_app_cloudsqlProxyCredentials'
|
|
307
|
+
fullDbName: 'app'
|
|
302
308
|
projectId: 'some-project-id'
|
|
303
309
|
jobs:
|
|
304
310
|
db-migrate:
|
|
@@ -403,8 +409,11 @@ application:
|
|
|
403
409
|
enabled: true
|
|
404
410
|
command: 'launcher bundle exec rake jobs:work'
|
|
405
411
|
cloudsql:
|
|
406
|
-
proxyCredentials: '$CL_dev_app_cloudsqlProxyCredentials'
|
|
407
412
|
enabled: true
|
|
413
|
+
dbUser: 'postgres'
|
|
414
|
+
instanceConnectionName: 'some-project-id:europe-west6:pan-test-app-dev'
|
|
415
|
+
proxyCredentials: '$CL_dev_app_cloudsqlProxyCredentials'
|
|
416
|
+
fullDbName: 'app'
|
|
408
417
|
projectId: 'some-project-id'
|
|
409
418
|
jobs:
|
|
410
419
|
db-migrate:
|
|
@@ -630,8 +639,11 @@ application:
|
|
|
630
639
|
enabled: true
|
|
631
640
|
command: 'launcher bundle exec rake jobs:work'
|
|
632
641
|
cloudsql:
|
|
633
|
-
proxyCredentials: '$CL_review_app_cloudsqlProxyCredentials'
|
|
634
642
|
enabled: true
|
|
643
|
+
dbUser: 'postgres'
|
|
644
|
+
instanceConnectionName: 'some-project-id:europe-west6:pan-test-app-review'
|
|
645
|
+
proxyCredentials: '$CL_review_app_cloudsqlProxyCredentials'
|
|
646
|
+
fullDbName: 'mr1234-app'
|
|
635
647
|
projectId: 'some-project-id'
|
|
636
648
|
jobs:
|
|
637
649
|
db-migrate:
|
|
@@ -841,8 +853,11 @@ application:
|
|
|
841
853
|
enabled: true
|
|
842
854
|
command: 'launcher bundle exec rake jobs:work'
|
|
843
855
|
cloudsql:
|
|
844
|
-
proxyCredentials: '$CL_review_app_cloudsqlProxyCredentials'
|
|
845
856
|
enabled: true
|
|
857
|
+
dbUser: 'postgres'
|
|
858
|
+
instanceConnectionName: 'some-project-id:europe-west6:pan-test-app-review'
|
|
859
|
+
proxyCredentials: '$CL_review_app_cloudsqlProxyCredentials'
|
|
860
|
+
fullDbName: 'mr1234-app'
|
|
846
861
|
projectId: 'some-project-id'
|
|
847
862
|
jobs:
|
|
848
863
|
db-migrate:
|
|
@@ -950,8 +965,11 @@ application:
|
|
|
950
965
|
enabled: true
|
|
951
966
|
command: 'launcher bundle exec rake jobs:work'
|
|
952
967
|
cloudsql:
|
|
953
|
-
proxyCredentials: '$CL_review_app_cloudsqlProxyCredentials'
|
|
954
968
|
enabled: true
|
|
969
|
+
dbUser: 'postgres'
|
|
970
|
+
instanceConnectionName: 'some-project-id:europe-west6:pan-test-app-review'
|
|
971
|
+
proxyCredentials: '$CL_review_app_cloudsqlProxyCredentials'
|
|
972
|
+
fullDbName: 'mr1234-app'
|
|
955
973
|
projectId: 'some-project-id'
|
|
956
974
|
jobs:
|
|
957
975
|
db-migrate:
|
|
@@ -1180,8 +1198,11 @@ application:
|
|
|
1180
1198
|
enabled: true
|
|
1181
1199
|
command: 'launcher bundle exec rake jobs:work'
|
|
1182
1200
|
cloudsql:
|
|
1183
|
-
proxyCredentials: '$CL_prod_app_cloudsqlProxyCredentials'
|
|
1184
1201
|
enabled: true
|
|
1202
|
+
dbUser: 'postgres'
|
|
1203
|
+
instanceConnectionName: 'some-project-id:europe-west6:pan-test-app-prod'
|
|
1204
|
+
proxyCredentials: '$CL_prod_app_cloudsqlProxyCredentials'
|
|
1205
|
+
fullDbName: 'app'
|
|
1185
1206
|
projectId: 'some-project-id'
|
|
1186
1207
|
jobs:
|
|
1187
1208
|
db-migrate:
|
|
@@ -1281,8 +1302,11 @@ application:
|
|
|
1281
1302
|
enabled: true
|
|
1282
1303
|
command: 'launcher bundle exec rake jobs:work'
|
|
1283
1304
|
cloudsql:
|
|
1284
|
-
proxyCredentials: '$CL_stage_app_cloudsqlProxyCredentials'
|
|
1285
1305
|
enabled: true
|
|
1306
|
+
dbUser: 'postgres'
|
|
1307
|
+
instanceConnectionName: 'some-project-id:europe-west6:pan-test-app-stage'
|
|
1308
|
+
proxyCredentials: '$CL_stage_app_cloudsqlProxyCredentials'
|
|
1309
|
+
fullDbName: 'app'
|
|
1286
1310
|
projectId: 'some-project-id'
|
|
1287
1311
|
jobs:
|
|
1288
1312
|
db-migrate:
|
|
@@ -1495,8 +1519,11 @@ application:
|
|
|
1495
1519
|
enabled: true
|
|
1496
1520
|
command: 'launcher bundle exec rake jobs:work'
|
|
1497
1521
|
cloudsql:
|
|
1498
|
-
proxyCredentials: '$CL_prod_app_cloudsqlProxyCredentials'
|
|
1499
1522
|
enabled: true
|
|
1523
|
+
dbUser: 'postgres'
|
|
1524
|
+
instanceConnectionName: 'some-project-id:europe-west6:pan-test-app-prod'
|
|
1525
|
+
proxyCredentials: '$CL_prod_app_cloudsqlProxyCredentials'
|
|
1526
|
+
fullDbName: 'app'
|
|
1500
1527
|
projectId: 'some-project-id'
|
|
1501
1528
|
jobs:
|
|
1502
1529
|
db-migrate:
|
|
@@ -1609,8 +1636,11 @@ application:
|
|
|
1609
1636
|
enabled: true
|
|
1610
1637
|
command: 'launcher bundle exec rake jobs:work'
|
|
1611
1638
|
cloudsql:
|
|
1612
|
-
proxyCredentials: '$CL_stage_app_cloudsqlProxyCredentials'
|
|
1613
1639
|
enabled: true
|
|
1640
|
+
dbUser: 'postgres'
|
|
1641
|
+
instanceConnectionName: 'some-project-id:europe-west6:pan-test-app-stage'
|
|
1642
|
+
proxyCredentials: '$CL_stage_app_cloudsqlProxyCredentials'
|
|
1643
|
+
fullDbName: 'app'
|
|
1614
1644
|
projectId: 'some-project-id'
|
|
1615
1645
|
jobs:
|
|
1616
1646
|
db-migrate:
|
|
@@ -1715,8 +1745,11 @@ application:
|
|
|
1715
1745
|
enabled: true
|
|
1716
1746
|
command: 'launcher bundle exec rake jobs:work'
|
|
1717
1747
|
cloudsql:
|
|
1718
|
-
proxyCredentials: '$CL_prod_app_cloudsqlProxyCredentials'
|
|
1719
1748
|
enabled: true
|
|
1749
|
+
dbUser: 'postgres'
|
|
1750
|
+
instanceConnectionName: 'some-project-id:europe-west6:pan-test-app-prod'
|
|
1751
|
+
proxyCredentials: '$CL_prod_app_cloudsqlProxyCredentials'
|
|
1752
|
+
fullDbName: 'app'
|
|
1720
1753
|
projectId: 'some-project-id'
|
|
1721
1754
|
jobs:
|
|
1722
1755
|
db-migrate:
|
|
@@ -1821,8 +1854,11 @@ application:
|
|
|
1821
1854
|
enabled: true
|
|
1822
1855
|
command: 'launcher bundle exec rake jobs:work'
|
|
1823
1856
|
cloudsql:
|
|
1824
|
-
proxyCredentials: '$CL_stage_app_cloudsqlProxyCredentials'
|
|
1825
1857
|
enabled: true
|
|
1858
|
+
dbUser: 'postgres'
|
|
1859
|
+
instanceConnectionName: 'some-project-id:europe-west6:pan-test-app-stage'
|
|
1860
|
+
proxyCredentials: '$CL_stage_app_cloudsqlProxyCredentials'
|
|
1861
|
+
fullDbName: 'app'
|
|
1826
1862
|
projectId: 'some-project-id'
|
|
1827
1863
|
jobs:
|
|
1828
1864
|
db-migrate:
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Config } from "../src";
|
|
2
|
+
import { createAllPipelines } from "./__utils__/helpers";
|
|
3
|
+
|
|
4
|
+
const config: Config = {
|
|
5
|
+
appName: "test-app",
|
|
6
|
+
customerName: "pan",
|
|
7
|
+
components: {
|
|
8
|
+
www: {
|
|
9
|
+
dir: "www",
|
|
10
|
+
build: {
|
|
11
|
+
type: "node",
|
|
12
|
+
},
|
|
13
|
+
deploy: {
|
|
14
|
+
type: "custom",
|
|
15
|
+
requiresDocker: true,
|
|
16
|
+
script: ["echo 'would deploy'"],
|
|
17
|
+
stopScript: ["echo 'would stop'"],
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
it("matches snapshot", async () => {
|
|
24
|
+
expect(await createAllPipelines(config)).toMatchSnapshot();
|
|
25
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Config } from "../src";
|
|
2
|
+
import { createAllPipelines } from "./__utils__/helpers";
|
|
3
|
+
const config: Config = {
|
|
4
|
+
appName: "test-app",
|
|
5
|
+
customerName: "pan",
|
|
6
|
+
components: {
|
|
7
|
+
api: {
|
|
8
|
+
dir: "api",
|
|
9
|
+
build: {
|
|
10
|
+
type: "node",
|
|
11
|
+
},
|
|
12
|
+
deploy: {
|
|
13
|
+
type: "kubernetes",
|
|
14
|
+
cluster: {
|
|
15
|
+
name: "some-cluster-name",
|
|
16
|
+
region: "europe-west6",
|
|
17
|
+
projectId: "some-project-id",
|
|
18
|
+
type: "gcloud",
|
|
19
|
+
domainCanonical: "panter.cloud",
|
|
20
|
+
},
|
|
21
|
+
values: {
|
|
22
|
+
cloudsql: {
|
|
23
|
+
enabled: true,
|
|
24
|
+
type: "unmanaged",
|
|
25
|
+
instanceConnectionName: "myproject:europe-west6:instance-name",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
it("matches snapshot", async () => {
|
|
34
|
+
expect(await createAllPipelines(config)).toMatchSnapshot();
|
|
35
|
+
});
|
package/package.json
CHANGED
|
@@ -9,6 +9,11 @@ import {
|
|
|
9
9
|
translateLegacyFromComponents,
|
|
10
10
|
} from "./resolveReferences";
|
|
11
11
|
|
|
12
|
+
export type SecretEnvVar = {
|
|
13
|
+
key: string;
|
|
14
|
+
// hidden env vars are not shown in config-secrets
|
|
15
|
+
hidden?: boolean;
|
|
16
|
+
};
|
|
12
17
|
export const getEnvironmentVariables = async (
|
|
13
18
|
config: Config,
|
|
14
19
|
componentName: string,
|
|
@@ -17,7 +22,7 @@ export const getEnvironmentVariables = async (
|
|
|
17
22
|
alreadyVisited: Record<string, Record<string, boolean>> = {} // to prevent endless loop
|
|
18
23
|
): Promise<{
|
|
19
24
|
envVars: Record<string, string>;
|
|
20
|
-
secretEnvVarKeys:
|
|
25
|
+
secretEnvVarKeys: SecretEnvVar[];
|
|
21
26
|
host: string;
|
|
22
27
|
url: string;
|
|
23
28
|
}> => {
|
|
@@ -81,12 +86,12 @@ export const getEnvironmentVariables = async (
|
|
|
81
86
|
)
|
|
82
87
|
: [];
|
|
83
88
|
|
|
84
|
-
const secretEnvVarKeys = [
|
|
85
|
-
...(envConfigRaw.vars?.secret ?? []),
|
|
89
|
+
const secretEnvVarKeys: SecretEnvVar[] = [
|
|
90
|
+
...(envConfigRaw.vars?.secret ?? []).map((key) => ({ key })),
|
|
86
91
|
...additionalSecretKeys,
|
|
87
92
|
];
|
|
88
93
|
const secretEnvVars = Object.fromEntries(
|
|
89
|
-
secretEnvVarKeys.map((key) => [
|
|
94
|
+
secretEnvVarKeys.map(({ key }) => [
|
|
90
95
|
key,
|
|
91
96
|
`$${getSecretVarName(env, componentName, key)}`,
|
|
92
97
|
])
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dump } from "js-yaml";
|
|
2
|
-
import {
|
|
2
|
+
import { merge, omit } from "lodash";
|
|
3
3
|
import { GCLOUD_DEPLOY_CREDENTIALS_KEY } from ".";
|
|
4
4
|
import { getDockerJobBaseProps, gitlabDockerLogin } from "../../build/docker";
|
|
5
5
|
import { getLabels } from "../../context/getLabels";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { DeployTypeDefinition } from "..";
|
|
2
2
|
import { getSecretVarName } from "../../context";
|
|
3
|
-
import { sanitizeForBashVariable } from "../../utils/gitlab";
|
|
4
3
|
import type { EnvironmentContext } from "../../types/environmentContext";
|
|
4
|
+
import { sanitizeForBashVariable } from "../../utils/gitlab";
|
|
5
|
+
import { getFullDbName } from "../cloudSql/utils";
|
|
5
6
|
import { createGoogleCloudRunDeployJobs } from "./deployJob";
|
|
6
7
|
import { getCloudRunJobName } from "./utils/jobName";
|
|
7
8
|
|
|
@@ -18,14 +19,12 @@ const getCloudSqlVariables = ({
|
|
|
18
19
|
fullConfig,
|
|
19
20
|
}: EnvironmentContext<any, "google-cloudrun">) => {
|
|
20
21
|
if (deployConfigRaw && deployConfigRaw.cloudSql) {
|
|
21
|
-
const DB_NAME =
|
|
22
|
-
deployConfigRaw.cloudSql
|
|
23
|
-
|
|
22
|
+
const DB_NAME = getFullDbName(
|
|
23
|
+
deployConfigRaw.cloudSql,
|
|
24
|
+
fullConfig,
|
|
24
25
|
environmentSlugPrefix,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
.filter(Boolean)
|
|
28
|
-
.join("-");
|
|
26
|
+
componentName
|
|
27
|
+
);
|
|
29
28
|
|
|
30
29
|
const additionalQueryParamsString = Object.entries(
|
|
31
30
|
deployConfigRaw.cloudSql.dbAdditionalQueryParams ?? {}
|
|
@@ -58,9 +57,16 @@ export const GCLOUD_RUN_DEPLOY_TYPE: DeployTypeDefinition<"google-cloudrun"> = {
|
|
|
58
57
|
return {};
|
|
59
58
|
},
|
|
60
59
|
additionalSecretKeys: (ctx) => [
|
|
61
|
-
|
|
60
|
+
{
|
|
61
|
+
key: GCLOUD_DEPLOY_CREDENTIALS_KEY,
|
|
62
|
+
hidden: true,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
key: GCLOUD_RUN_CANONICAL_HOST_SUFFIX,
|
|
66
|
+
hidden: true,
|
|
67
|
+
},
|
|
62
68
|
...(ctx.deployConfigRaw && ctx.deployConfigRaw.cloudSql
|
|
63
|
-
? ["DB_PASSWORD"]
|
|
69
|
+
? [{ key: "DB_PASSWORD" }]
|
|
64
70
|
: []),
|
|
65
71
|
],
|
|
66
72
|
getAdditionalEnvVars: (ctx) => {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Config } from "../..";
|
|
2
|
+
import type {
|
|
3
|
+
DeployConfigCloudRunCloudSql,
|
|
4
|
+
DeployConfigKubernetesValuesCloudSQLUnmanaged,
|
|
5
|
+
} from "../types";
|
|
6
|
+
|
|
7
|
+
export const getFullDbName = (
|
|
8
|
+
cloudSqlConfig:
|
|
9
|
+
| DeployConfigCloudRunCloudSql
|
|
10
|
+
| DeployConfigKubernetesValuesCloudSQLUnmanaged,
|
|
11
|
+
fullConfig: Config<never>,
|
|
12
|
+
environmentSlugPrefix: string,
|
|
13
|
+
componentName: string
|
|
14
|
+
) => {
|
|
15
|
+
return [
|
|
16
|
+
cloudSqlConfig.dbNamePrefix ??
|
|
17
|
+
`${fullConfig.customerName}-${fullConfig.appName}`,
|
|
18
|
+
environmentSlugPrefix,
|
|
19
|
+
cloudSqlConfig.dbBaseName ?? componentName,
|
|
20
|
+
]
|
|
21
|
+
.filter(Boolean)
|
|
22
|
+
.join("-");
|
|
23
|
+
};
|
|
@@ -4,7 +4,7 @@ import { getYarnInstall } from "../../build/node/yarn";
|
|
|
4
4
|
import { getRunnerImage } from "../../runner";
|
|
5
5
|
import type { Context } from "../../types/context";
|
|
6
6
|
import type { CatladderJob } from "../../types/jobs";
|
|
7
|
-
import { getBaseDeploymentJob } from "../base";
|
|
7
|
+
import { getBaseDeploymentJob, getBaseDeploymentStopJob } from "../base";
|
|
8
8
|
import { isOfDeployType } from "../types";
|
|
9
9
|
|
|
10
10
|
export const createCustomDeployJobs = (context: Context): CatladderJob[] => {
|
|
@@ -29,5 +29,13 @@ export const createCustomDeployJobs = (context: Context): CatladderJob[] => {
|
|
|
29
29
|
...deployConfig.script,
|
|
30
30
|
],
|
|
31
31
|
}),
|
|
32
|
+
...(deployConfig.stopScript
|
|
33
|
+
? [
|
|
34
|
+
merge({}, getBaseDeploymentStopJob(context), {
|
|
35
|
+
image: deployConfig.jobImage ?? getRunnerImage("jobs-default"),
|
|
36
|
+
script: deployConfig.stopScript,
|
|
37
|
+
}),
|
|
38
|
+
]
|
|
39
|
+
: []),
|
|
32
40
|
];
|
|
33
41
|
};
|
package/src/deploy/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SecretEnvVar } from "..";
|
|
1
2
|
import type { Context } from "../types/context";
|
|
2
3
|
import type { EnvironmentContext } from "../types/environmentContext";
|
|
3
4
|
import type { CatladderJob } from "../types/jobs";
|
|
@@ -17,7 +18,9 @@ export type DeployTypeDefinition<T extends DeployConfigType> = {
|
|
|
17
18
|
defaults: (
|
|
18
19
|
envContext: EnvironmentContext<any, T>
|
|
19
20
|
) => PartialDeep<DeployConfigGeneric<T>>;
|
|
20
|
-
additionalSecretKeys: (
|
|
21
|
+
additionalSecretKeys: (
|
|
22
|
+
envContext: EnvironmentContext<any, T>
|
|
23
|
+
) => SecretEnvVar[];
|
|
21
24
|
getAdditionalEnvVars: (
|
|
22
25
|
envContext: EnvironmentContext<any, T>
|
|
23
26
|
) => Record<string, string | undefined | null>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getSecretVarNameForContext } from "../../../context";
|
|
2
2
|
import type { Context } from "../../../types";
|
|
3
|
+
import { getFullDbName } from "../../cloudSql/utils";
|
|
3
4
|
import { isOfDeployType } from "../../types";
|
|
4
5
|
|
|
5
6
|
export const hasKubernetesCloudSQL = (context: Context) => {
|
|
@@ -9,20 +10,63 @@ export const hasKubernetesCloudSQL = (context: Context) => {
|
|
|
9
10
|
return false;
|
|
10
11
|
};
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
type CloudSqlValues = {
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
proxyCredentials: string;
|
|
16
|
+
|
|
17
|
+
instanceConnectionName: string;
|
|
18
|
+
fullDbName: string;
|
|
19
|
+
dbUser: string;
|
|
17
20
|
};
|
|
21
|
+
export const createKubernetesCloudsqlBaseValues = (
|
|
22
|
+
context: Context
|
|
23
|
+
): {
|
|
24
|
+
cloudsql: CloudSqlValues;
|
|
25
|
+
} => {
|
|
26
|
+
if (!isOfDeployType(context.componentConfig.deploy, "kubernetes")) {
|
|
27
|
+
throw new Error("cannot get cloud sql config");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const config = context.componentConfig.deploy.values?.cloudsql;
|
|
18
31
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
if (!config) {
|
|
33
|
+
throw new Error("cannot get cloud sql config");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const proxyCredentials = `$${getSecretVarNameForContext(
|
|
37
|
+
context,
|
|
38
|
+
"cloudsqlProxyCredentials"
|
|
39
|
+
)}`;
|
|
40
|
+
if (config?.type !== "unmanaged") {
|
|
41
|
+
const instanceConnectionName = `${config.projectId ?? "skynet-164509"}:${
|
|
42
|
+
config.region ?? "europe-west6"
|
|
43
|
+
}:${config.instanceId ?? context.environment.envVars.KUBE_NAMESPACE}`;
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
cloudsql: {
|
|
47
|
+
enabled: config.enabled,
|
|
48
|
+
dbUser: "postgres",
|
|
49
|
+
instanceConnectionName,
|
|
50
|
+
proxyCredentials,
|
|
51
|
+
fullDbName: context.environment.envVars.KUBE_APP_NAME,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
} else if (config.type === "unmanaged") {
|
|
55
|
+
return {
|
|
56
|
+
cloudsql: {
|
|
57
|
+
enabled: config.enabled,
|
|
58
|
+
dbUser: config.dbUser ?? "postgres",
|
|
59
|
+
instanceConnectionName: config.instanceConnectionName,
|
|
60
|
+
proxyCredentials,
|
|
61
|
+
fullDbName: getFullDbName(
|
|
62
|
+
config,
|
|
63
|
+
context.fullConfig,
|
|
64
|
+
context.environment.slugPrefix,
|
|
65
|
+
context.componentName
|
|
66
|
+
),
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
} else {
|
|
70
|
+
throw new Error("unknonw type");
|
|
71
|
+
}
|
|
28
72
|
};
|
|
@@ -4,7 +4,10 @@ import type { Context } from "../../types/context";
|
|
|
4
4
|
import { mergeWithMergingArrays } from "../../utils";
|
|
5
5
|
import type { DeployConfigKubernetesValues } from "../types";
|
|
6
6
|
import { isOfDeployType } from "../types";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
hasKubernetesCloudSQL,
|
|
9
|
+
createKubernetesCloudsqlBaseValues,
|
|
10
|
+
} from "./cloudSql";
|
|
8
11
|
|
|
9
12
|
import { createKubeEnv } from "./kubeEnv";
|
|
10
13
|
import { createMongodbBaseConfig } from "./mongodb";
|
|
@@ -77,7 +80,9 @@ export const createKubeValues = (context: Context) => {
|
|
|
77
80
|
env,
|
|
78
81
|
application: createAppConfig(context, application),
|
|
79
82
|
},
|
|
80
|
-
hasKubernetesCloudSQL(context)
|
|
83
|
+
hasKubernetesCloudSQL(context)
|
|
84
|
+
? createKubernetesCloudsqlBaseValues(context)
|
|
85
|
+
: {},
|
|
81
86
|
deployConfig.values?.mongodb?.enabled
|
|
82
87
|
? createMongodbBaseConfig(context)
|
|
83
88
|
: {}
|
|
@@ -128,16 +128,69 @@ export type DeployConfigMongodbReplicaset = {
|
|
|
128
128
|
export type DeployConfigMongodb = DeployConfigMongodbBase &
|
|
129
129
|
(DeployConfigMongodbStandalone | DeployConfigMongodbReplicaset);
|
|
130
130
|
|
|
131
|
+
/**
|
|
132
|
+
* @deprecated use config with instanceConnectionName
|
|
133
|
+
*/
|
|
134
|
+
type DeployConfigKubernetesValuesCloudSQLLegacy = {
|
|
135
|
+
enabled: boolean;
|
|
136
|
+
/**
|
|
137
|
+
* @deprecated use config with instanceConnectionName
|
|
138
|
+
*/
|
|
139
|
+
instanceId?: string;
|
|
140
|
+
/**
|
|
141
|
+
* @deprecated use config with instanceConnectionName
|
|
142
|
+
*/
|
|
143
|
+
projectId?: string;
|
|
144
|
+
/**
|
|
145
|
+
* @deprecated use config with instanceConnectionName
|
|
146
|
+
*/
|
|
147
|
+
region?: string;
|
|
148
|
+
/**
|
|
149
|
+
* @deprecated use type "unmanaged".
|
|
150
|
+
*
|
|
151
|
+
* Be aware that "unmanaged" is not fully backward compatible with "legacy".
|
|
152
|
+
*
|
|
153
|
+
*
|
|
154
|
+
*/
|
|
155
|
+
type?: "legacy";
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export type DeployConfigKubernetesValuesCloudSQLUnmanaged = {
|
|
159
|
+
enabled: boolean;
|
|
160
|
+
instanceConnectionName: string;
|
|
161
|
+
/**
|
|
162
|
+
* the recommended type for the config.
|
|
163
|
+
*
|
|
164
|
+
* this mode is similar to cloudrun and declares fully-qualified db names including env.
|
|
165
|
+
*
|
|
166
|
+
* This makes it easier to share db instances across envs and dbs
|
|
167
|
+
*/
|
|
168
|
+
type: "unmanaged";
|
|
169
|
+
/**
|
|
170
|
+
* the database username, defaults to "postgres"
|
|
171
|
+
*/
|
|
172
|
+
dbUser?: string;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* the prefix of the database, the full db name is this plus the environment slug prefix plus the componentName
|
|
176
|
+
*
|
|
177
|
+
* defaults to customerName-appName
|
|
178
|
+
*/
|
|
179
|
+
dbNamePrefix?: string | false;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* the base name of the db, defaults to the componentName
|
|
183
|
+
*/
|
|
184
|
+
dbBaseName?: string;
|
|
185
|
+
};
|
|
186
|
+
export type DeployConfigKubernetesValuesCloudSQL =
|
|
187
|
+
| DeployConfigKubernetesValuesCloudSQLLegacy
|
|
188
|
+
| DeployConfigKubernetesValuesCloudSQLUnmanaged;
|
|
131
189
|
export type DeployConfigKubernetesValues = AllowUnknownProps<{
|
|
132
190
|
/**
|
|
133
191
|
* enable cloudsql db. Currently you have to manually set it up
|
|
134
192
|
*/
|
|
135
|
-
cloudsql?:
|
|
136
|
-
enabled: boolean;
|
|
137
|
-
instanceId?: string;
|
|
138
|
-
projectId?: string;
|
|
139
|
-
region?: string;
|
|
140
|
-
};
|
|
193
|
+
cloudsql?: DeployConfigKubernetesValuesCloudSQL;
|
|
141
194
|
/**
|
|
142
195
|
* enable mongodb. The mongodb is deployed using a helm chart.
|
|
143
196
|
* See https://github.com/bitnami/charts/tree/master/bitnami/mongodb
|
package/src/types/context.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SecretEnvVar } from "../context";
|
|
1
2
|
import type {
|
|
2
3
|
PipelineTrigger,
|
|
3
4
|
ComponentConfig,
|
|
@@ -25,7 +26,7 @@ export type Environment = {
|
|
|
25
26
|
*/
|
|
26
27
|
envVars: Record<string, string>;
|
|
27
28
|
envType: EnvType;
|
|
28
|
-
secretEnvVarKeys:
|
|
29
|
+
secretEnvVarKeys: SecretEnvVar[];
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
export type CommitInfo = {
|