@catladder/pipeline 1.82.2 → 1.83.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 +1 -1
- package/dist/constants.js +1 -1
- package/dist/context/getEnvironment.js +1 -0
- package/dist/context/getEnvironmentContext.js +5 -3
- package/dist/deploy/cloudRun/index.js +5 -5
- package/dist/deploy/types/googleCloudRun.d.ts +5 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/context.d.ts +1 -0
- package/dist/types/environmentContext.d.ts +7 -0
- package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +3116 -0
- package/examples/cloud-run-with-sql-reuse-db.ts +54 -0
- package/package.json +1 -1
- package/src/context/getEnvironment.ts +1 -0
- package/src/context/getEnvironmentContext.ts +6 -6
- package/src/deploy/cloudRun/index.ts +3 -2
- package/src/deploy/types/googleCloudRun.ts +6 -1
- package/src/types/context.ts +1 -0
- package/src/types/environmentContext.ts +7 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Config, DeployConfigCloudRunCloudSql } from "../src";
|
|
2
|
+
import { createAllPipelines } from "./__utils__/helpers";
|
|
3
|
+
|
|
4
|
+
const CLOUD_SQL: DeployConfigCloudRunCloudSql = {
|
|
5
|
+
type: "unmanaged",
|
|
6
|
+
instanceConnectionName: "projectId:region:instancename",
|
|
7
|
+
dbUser: "my-user",
|
|
8
|
+
};
|
|
9
|
+
const config: Config = {
|
|
10
|
+
appName: "test-app",
|
|
11
|
+
customerName: "pan",
|
|
12
|
+
components: {
|
|
13
|
+
api: {
|
|
14
|
+
dir: "api",
|
|
15
|
+
build: {
|
|
16
|
+
type: "node",
|
|
17
|
+
},
|
|
18
|
+
deploy: {
|
|
19
|
+
type: "google-cloudrun",
|
|
20
|
+
projectId: "google-project-id",
|
|
21
|
+
region: "europe-west6",
|
|
22
|
+
cloudSql: CLOUD_SQL,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
worker: {
|
|
26
|
+
dir: "api",
|
|
27
|
+
build: {
|
|
28
|
+
type: "node",
|
|
29
|
+
buildCommand: "yarn build:worker",
|
|
30
|
+
},
|
|
31
|
+
deploy: {
|
|
32
|
+
type: "google-cloudrun",
|
|
33
|
+
projectId: "google-project-id",
|
|
34
|
+
region: "europe-west6",
|
|
35
|
+
cloudSql: {
|
|
36
|
+
...CLOUD_SQL,
|
|
37
|
+
// override the db base name to the other component's name
|
|
38
|
+
// if ommited, this defaults to the component's name
|
|
39
|
+
dbBaseName: "api",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
vars: {
|
|
43
|
+
public: {
|
|
44
|
+
// need to reference the password
|
|
45
|
+
DB_PASSWORD: "${api:DB_PASSWORD}",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
it("matches snapshot", async () => {
|
|
53
|
+
expect(await createAllPipelines(config)).toMatchSnapshot();
|
|
54
|
+
});
|
package/package.json
CHANGED
|
@@ -5,17 +5,16 @@ import type { EnvironmentContext } from "../types/environmentContext";
|
|
|
5
5
|
import { getEnvConfig } from "./getEnvConfig";
|
|
6
6
|
import { getEnvType } from "./getEnvType";
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const getEnvironmentSlugPrefix = (
|
|
9
9
|
envConfig: EnvConfigWithComponent,
|
|
10
10
|
env: string,
|
|
11
|
-
componentName: string,
|
|
12
11
|
commitInfo?: CommitInfo
|
|
13
12
|
) => {
|
|
14
13
|
const envType = getEnvType(env, envConfig);
|
|
15
14
|
|
|
16
15
|
return envType === "review" && commitInfo
|
|
17
|
-
? `${env}-${commitInfo.reviewSlug}
|
|
18
|
-
: `${env}
|
|
16
|
+
? `${env}-${commitInfo.reviewSlug}`
|
|
17
|
+
: `${env}`;
|
|
19
18
|
};
|
|
20
19
|
|
|
21
20
|
export const getEnvironmentContext = (
|
|
@@ -27,13 +26,13 @@ export const getEnvironmentContext = (
|
|
|
27
26
|
const envConfigRaw = getEnvConfig(config, componentName, env);
|
|
28
27
|
const envType = getEnvType(env, envConfigRaw);
|
|
29
28
|
|
|
30
|
-
const
|
|
29
|
+
const environmentSlugPrefix = getEnvironmentSlugPrefix(
|
|
31
30
|
envConfigRaw,
|
|
32
31
|
env,
|
|
33
|
-
componentName,
|
|
34
32
|
commitInfo
|
|
35
33
|
);
|
|
36
34
|
|
|
35
|
+
const environmentSlug = `${environmentSlugPrefix}-${componentName}`;
|
|
37
36
|
const gitlabEnvironmentName =
|
|
38
37
|
envType === "review" && commitInfo
|
|
39
38
|
? `${env}/${commitInfo.refName}/${componentName}`
|
|
@@ -45,6 +44,7 @@ export const getEnvironmentContext = (
|
|
|
45
44
|
envConfigRaw,
|
|
46
45
|
deployConfigRaw: envConfigRaw.deploy,
|
|
47
46
|
buildConfigRaw: envConfigRaw.build,
|
|
47
|
+
environmentSlugPrefix,
|
|
48
48
|
environmentSlug,
|
|
49
49
|
gitlabEnvironmentName,
|
|
50
50
|
fullName,
|
|
@@ -12,7 +12,7 @@ export const GCLOUD_RUN_CANONICAL_HOST_SUFFIX =
|
|
|
12
12
|
|
|
13
13
|
const getCloudSqlVariables = ({
|
|
14
14
|
deployConfigRaw,
|
|
15
|
-
|
|
15
|
+
environmentSlugPrefix,
|
|
16
16
|
env,
|
|
17
17
|
componentName,
|
|
18
18
|
fullConfig,
|
|
@@ -21,7 +21,8 @@ const getCloudSqlVariables = ({
|
|
|
21
21
|
const DB_NAME = [
|
|
22
22
|
deployConfigRaw.cloudSql.dbNamePrefix ??
|
|
23
23
|
`${fullConfig.customerName}-${fullConfig.appName}`,
|
|
24
|
-
|
|
24
|
+
environmentSlugPrefix,
|
|
25
|
+
deployConfigRaw.cloudSql.dbBaseName ?? componentName,
|
|
25
26
|
]
|
|
26
27
|
.filter(Boolean)
|
|
27
28
|
.join("-");
|
|
@@ -46,11 +46,16 @@ export type DeployConfigCloudRunCloudSql = {
|
|
|
46
46
|
dbUser?: string;
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
* the prefix of the database, the full db name is this plus the environment slug
|
|
49
|
+
* the prefix of the database, the full db name is this plus the environment slug prefix plus the componentName
|
|
50
50
|
*
|
|
51
51
|
* defaults to customerName-appName
|
|
52
52
|
*/
|
|
53
53
|
dbNamePrefix?: string | false;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* the base name of the db, defaults to the componentName
|
|
57
|
+
*/
|
|
58
|
+
dbBaseName?: string;
|
|
54
59
|
/**
|
|
55
60
|
* whether to delete the database if the environment is stopped
|
|
56
61
|
* defaults to true for review envs, to false for every other environment
|
package/src/types/context.ts
CHANGED
|
@@ -16,6 +16,13 @@ export type EnvironmentContext<
|
|
|
16
16
|
envType: EnvType;
|
|
17
17
|
componentName: string;
|
|
18
18
|
fullName: string;
|
|
19
|
+
/**
|
|
20
|
+
* the environment slug without component name.
|
|
21
|
+
*/
|
|
22
|
+
environmentSlugPrefix: string;
|
|
23
|
+
/**
|
|
24
|
+
* the full environment slug, including the componentName
|
|
25
|
+
*/
|
|
19
26
|
environmentSlug: string;
|
|
20
27
|
gitlabEnvironmentName: string;
|
|
21
28
|
|