@catladder/pipeline 0.0.0-refactor-gcloud-api-5bd4bbed → 0.0.0-refactor-needs-aae6e67d
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/build/custom/buildJob.js +1 -0
- package/dist/build/index.js +7 -1
- package/dist/build/rails/build.js +41 -16
- package/dist/build/rails/index.d.ts +2 -2
- package/dist/build/types.d.ts +36 -4
- package/dist/bundles/catladder-gitlab/index.js +125 -54
- package/dist/constants.js +1 -1
- package/dist/context/__tests__/resolveReferences.test.js +15 -20
- package/dist/context/getEnvironment.js +1 -0
- package/dist/context/getEnvironmentContext.js +5 -3
- package/dist/context/getEnvironmentVariables.js +2 -2
- package/dist/context/resolveReferences.d.ts +1 -1
- package/dist/context/resolveReferences.js +3 -1
- package/dist/deploy/base.js +1 -1
- package/dist/deploy/cloudRun/deployJob.js +9 -7
- package/dist/deploy/cloudRun/index.js +7 -6
- package/dist/deploy/cloudRun/utils/createArgsString.d.ts +1 -1
- package/dist/deploy/cloudRun/utils/createArgsString.js +6 -1
- package/dist/deploy/kubernetes/deployJob.js +4 -4
- package/dist/deploy/kubernetes/kubeValues.d.ts +3 -0
- package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +3 -0
- package/dist/deploy/types/custom.d.ts +2 -1
- package/dist/deploy/types/googleCloudRun.d.ts +11 -2
- package/dist/deploy/types/kubernetes.d.ts +11 -0
- package/dist/pipeline/createJobs.js +4 -9
- package/dist/pipeline/gitlab/makeGitlabJob.js +33 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/context.d.ts +1 -0
- package/dist/types/environmentContext.d.ts +7 -0
- package/dist/types/gitlab-types.d.ts +25 -1
- package/dist/types/jobs.d.ts +9 -2
- package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +1572 -0
- package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +1572 -0
- package/examples/__snapshots__/cloud-run-non-public.ts.snap +48 -48
- package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +3116 -0
- package/examples/__snapshots__/cloud-run-with-sql.ts.snap +108 -108
- package/examples/__snapshots__/custom-build-job.ts.snap +48 -48
- package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +24 -24
- package/examples/__snapshots__/rails-k8s-with-worker.ts.snap +1911 -0
- package/examples/cloud-run-memory-limit.ts +28 -0
- package/examples/cloud-run-no-cpu-throttling.ts +33 -0
- package/examples/cloud-run-with-sql-reuse-db.ts +54 -0
- package/examples/cloud-run-with-sql.ts +1 -1
- package/examples/rails-k8s-with-worker.ts +95 -0
- package/package.json +1 -1
- package/src/build/custom/buildJob.ts +1 -0
- package/src/build/index.ts +7 -1
- package/src/build/rails/build.ts +17 -10
- package/src/build/rails/index.ts +2 -2
- package/src/build/types.ts +40 -5
- package/src/context/__tests__/resolveReferences.test.ts +15 -30
- package/src/context/getEnvironment.ts +1 -0
- package/src/context/getEnvironmentContext.ts +6 -6
- package/src/context/getEnvironmentVariables.ts +7 -5
- package/src/context/resolveReferences.ts +3 -6
- package/src/deploy/base.ts +1 -1
- package/src/deploy/cloudRun/deployJob.ts +9 -11
- package/src/deploy/cloudRun/index.ts +5 -4
- package/src/deploy/cloudRun/utils/createArgsString.ts +9 -2
- package/src/deploy/kubernetes/deployJob.ts +1 -1
- package/src/deploy/types/custom.ts +2 -1
- package/src/deploy/types/googleCloudRun.ts +14 -2
- package/src/deploy/types/kubernetes.ts +12 -0
- package/src/pipeline/createJobs.ts +14 -17
- package/src/pipeline/gitlab/makeGitlabJob.ts +3 -1
- package/src/types/context.ts +1 -0
- package/src/types/environmentContext.ts +7 -0
- package/src/types/gitlab-types.ts +18 -1
- package/src/types/jobs.ts +11 -2
|
@@ -0,0 +1,28 @@
|
|
|
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: "google-cloudrun",
|
|
14
|
+
projectId: "google-project-id",
|
|
15
|
+
region: "europe-west6",
|
|
16
|
+
|
|
17
|
+
service: {
|
|
18
|
+
// defaults to 512Mi
|
|
19
|
+
memory: "1024Mi",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
it("matches snapshot", async () => {
|
|
27
|
+
expect(await createAllPipelines(config)).toMatchSnapshot();
|
|
28
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
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: "google-cloudrun",
|
|
14
|
+
projectId: "google-project-id",
|
|
15
|
+
region: "europe-west6",
|
|
16
|
+
|
|
17
|
+
service: {
|
|
18
|
+
minInstances: 1,
|
|
19
|
+
// careful, this is expensive!
|
|
20
|
+
// this will always allocate the cpu
|
|
21
|
+
// use this if you have background tasks.
|
|
22
|
+
|
|
23
|
+
// consider using cloud task instead of this
|
|
24
|
+
noCpuThrottling: true,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
it("matches snapshot", async () => {
|
|
32
|
+
expect(await createAllPipelines(config)).toMatchSnapshot();
|
|
33
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { Config } from "../src";
|
|
2
|
+
import { createAllPipelines } from "./__utils__/helpers";
|
|
3
|
+
|
|
4
|
+
// the image version should match your `.ruby-version`
|
|
5
|
+
const RAILS_TEST_STAGE_IMAGE = "ruby:3.2.1"
|
|
6
|
+
|
|
7
|
+
const config: Config = {
|
|
8
|
+
appName: "test-app",
|
|
9
|
+
customerName: "pan",
|
|
10
|
+
components: {
|
|
11
|
+
app: {
|
|
12
|
+
dir: ".",
|
|
13
|
+
vars: {
|
|
14
|
+
public: {
|
|
15
|
+
RAILS_ENV: "production",
|
|
16
|
+
},
|
|
17
|
+
secret: [
|
|
18
|
+
"SECRET_KEY_BASE",
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
build: {
|
|
22
|
+
type: "rails",
|
|
23
|
+
test: {
|
|
24
|
+
// if operating system dependencies are required you can either
|
|
25
|
+
// - build a dedicated image
|
|
26
|
+
// - use `command` to apt-get install them before running the test command
|
|
27
|
+
jobImage: RAILS_TEST_STAGE_IMAGE,
|
|
28
|
+
},
|
|
29
|
+
lint: {
|
|
30
|
+
jobImage: RAILS_TEST_STAGE_IMAGE,
|
|
31
|
+
},
|
|
32
|
+
audit: {
|
|
33
|
+
jobImage: RAILS_TEST_STAGE_IMAGE,
|
|
34
|
+
},
|
|
35
|
+
cnbBuilder: {
|
|
36
|
+
buildVars: { SECRET_KEY_BASE: "dummy-value" },
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
deploy: {
|
|
40
|
+
type: "kubernetes",
|
|
41
|
+
cluster: {
|
|
42
|
+
name: "some-cluster-name",
|
|
43
|
+
region: "europe-west6",
|
|
44
|
+
projectId: "some-project-id",
|
|
45
|
+
type: "gcloud",
|
|
46
|
+
domainCanonical: "panter.cloud",
|
|
47
|
+
},
|
|
48
|
+
values: {
|
|
49
|
+
cloudsql: { enabled: true, projectId: "some-project-id" },
|
|
50
|
+
application: {
|
|
51
|
+
// if deployed to Google Cloud Run use a gem like cloudtasker instead of a permanently running expensive worker
|
|
52
|
+
worker: {
|
|
53
|
+
enabled: true,
|
|
54
|
+
command: "launcher bundle exec rake jobs:work",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
jobs: {
|
|
58
|
+
"db-migrate": {
|
|
59
|
+
hook: "post-install,post-upgrade",
|
|
60
|
+
command:
|
|
61
|
+
"launcher bundle exec rake db:migrate",
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
env: {
|
|
67
|
+
review: {
|
|
68
|
+
deploy: {
|
|
69
|
+
values: {
|
|
70
|
+
jobs: {
|
|
71
|
+
"db-prepare-seed": {
|
|
72
|
+
hook: "post-install",
|
|
73
|
+
command:
|
|
74
|
+
"launcher bundle exec rake db:prepare db:seed",
|
|
75
|
+
},
|
|
76
|
+
"db-migrate": {
|
|
77
|
+
hook: "post-upgrade",
|
|
78
|
+
command:
|
|
79
|
+
"launcher bundle exec rake db:migrate",
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
prod: {
|
|
86
|
+
host: "my-fancy-website.com"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
it("matches snapshot", async () => {
|
|
94
|
+
expect(await createAllPipelines(config)).toMatchSnapshot();
|
|
95
|
+
});
|
package/package.json
CHANGED
|
@@ -29,6 +29,7 @@ export const createCustomBuildJobs = (context: Context): CatladderJob[] => {
|
|
|
29
29
|
variables: {
|
|
30
30
|
...RUNNER_BUILD_VARIABLES,
|
|
31
31
|
},
|
|
32
|
+
cache: buildConfig.jobCache,
|
|
32
33
|
services: buildConfig.jobServices,
|
|
33
34
|
script: [...(ensureArray(buildConfig.buildCommand) ?? [])],
|
|
34
35
|
artifacts: {
|
package/src/build/index.ts
CHANGED
|
@@ -51,6 +51,12 @@ export const BUILD_TYPES: BuildTypes = {
|
|
|
51
51
|
},
|
|
52
52
|
rails: {
|
|
53
53
|
jobs: createRailsJobs,
|
|
54
|
-
defaults: () => ({
|
|
54
|
+
defaults: () => ({
|
|
55
|
+
startCommand: "/cnb/process/web",
|
|
56
|
+
cnbBuilder: {
|
|
57
|
+
image: "heroku/buildpacks:20",
|
|
58
|
+
packVersion: "0.28.0",
|
|
59
|
+
}
|
|
60
|
+
}),
|
|
55
61
|
},
|
|
56
62
|
};
|
package/src/build/rails/build.ts
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
import type { Context } from "../..";
|
|
2
|
+
import { isOfBuildType } from "../types";
|
|
2
3
|
import type { CatladderJob } from "../../types/jobs";
|
|
3
4
|
import { createDockerBuildJobBase, gitlabDockerLogin } from "../docker";
|
|
4
5
|
|
|
5
6
|
export const createRailsBuildJobs = (context: Context): CatladderJob[] => {
|
|
7
|
+
const buildConfig = context.componentConfig.build
|
|
8
|
+
if (!isOfBuildType(buildConfig, "rails")) {
|
|
9
|
+
// should not happen
|
|
10
|
+
throw new Error("build type is not rails");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const cnbConf = buildConfig.cnbBuilder;
|
|
14
|
+
|
|
15
|
+
// backwards compatabilty with CNB_ENV_VARS
|
|
16
|
+
// TODO: remove when all projects are migrated
|
|
17
|
+
const packEnvArgs = buildConfig.extraVars?.CNB_ENV_VARS?.split(" ").map(v => `--env '${v}'`)
|
|
18
|
+
?? Object.entries(cnbConf?.buildVars ?? {}).map(([k, v]) => `--env '${k}${v ? `=${v}` : ""}'`)
|
|
19
|
+
|
|
6
20
|
return [
|
|
7
21
|
createDockerBuildJobBase(context, {
|
|
8
|
-
variables:
|
|
9
|
-
CNB_BUILDER: "heroku/buildpacks:18",
|
|
10
|
-
CNB_ENV_VARS: "BUNDLE_GIT__PANTER__CH",
|
|
11
|
-
CNB_EXTRA_ARGS: "",
|
|
12
|
-
CNB_PACK_VERSION: "0.20.0",
|
|
13
|
-
...context.componentConfig.build.extraVars,
|
|
14
|
-
},
|
|
22
|
+
variables: context.componentConfig.build.extraVars,
|
|
15
23
|
// custom script
|
|
16
24
|
script: [
|
|
17
25
|
gitlabDockerLogin,
|
|
18
26
|
`docker pull $DOCKER_CACHE_IMAGE || true`,
|
|
19
|
-
`wget --output-document=- https://github.com/buildpacks/pack/releases/download/v$
|
|
27
|
+
`wget --output-document=- https://github.com/buildpacks/pack/releases/download/v${cnbConf?.packVersion}/pack-v${cnbConf?.packVersion}-linux.tgz | tar -zx --directory /usr/local/bin pack`,
|
|
20
28
|
`chmod +x /usr/local/bin/pack`,
|
|
21
29
|
// replace private git ssh gem sources with https to make bundler with credentials via env var work
|
|
22
30
|
`sed --in-place 's|git@\\([^:]*\\):|https://\\1/|g' Gemfile Gemfile.lock`,
|
|
23
|
-
`
|
|
24
|
-
`pack build $DOCKER_IMAGE:$DOCKER_IMAGE_TAG --builder $CNB_BUILDER --publish --cache-image $DOCKER_CACHE_IMAGE $env_args $CNB_EXTRA_ARGS`,
|
|
31
|
+
`pack build "$DOCKER_IMAGE:$DOCKER_IMAGE_TAG" --builder '${cnbConf?.image}' --publish --cache-image "$DOCKER_CACHE_IMAGE" ${packEnvArgs.join(" ")} ${cnbConf?.packExtraArgs?.join(" ") ?? ""}`
|
|
25
32
|
],
|
|
26
33
|
}),
|
|
27
34
|
];
|
package/src/build/rails/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Context } from "../../types";
|
|
2
|
-
import { CatladderJob } from "../../types/jobs";
|
|
1
|
+
import type { Context } from "../../types";
|
|
2
|
+
import type { CatladderJob } from "../../types/jobs";
|
|
3
3
|
import { createRailsBuildJobs } from "./build";
|
|
4
4
|
import { createRailsTestJobs } from "./test";
|
|
5
5
|
|
package/src/build/types.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { GitlabJobService } from "../types";
|
|
1
|
+
import type { GitlabJobImage, GitlabJobService } from "../types";
|
|
2
|
+
|
|
3
|
+
import type { CatladderJob } from "../types/jobs";
|
|
2
4
|
|
|
3
5
|
export type BuildConfigBase = {
|
|
4
6
|
/**
|
|
@@ -29,7 +31,7 @@ export type BuildConfigBase = {
|
|
|
29
31
|
| false
|
|
30
32
|
| {
|
|
31
33
|
command?: string | string[];
|
|
32
|
-
jobImage?:
|
|
34
|
+
jobImage?: GitlabJobImage;
|
|
33
35
|
};
|
|
34
36
|
|
|
35
37
|
/**
|
|
@@ -39,7 +41,7 @@ export type BuildConfigBase = {
|
|
|
39
41
|
| false
|
|
40
42
|
| {
|
|
41
43
|
command?: string | string[];
|
|
42
|
-
jobImage?:
|
|
44
|
+
jobImage?: GitlabJobImage;
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
/**
|
|
@@ -49,7 +51,7 @@ export type BuildConfigBase = {
|
|
|
49
51
|
| false
|
|
50
52
|
| {
|
|
51
53
|
command?: string | string[];
|
|
52
|
-
jobImage?:
|
|
54
|
+
jobImage?: GitlabJobImage;
|
|
53
55
|
};
|
|
54
56
|
|
|
55
57
|
/**
|
|
@@ -70,7 +72,7 @@ export type BuildConfigBase = {
|
|
|
70
72
|
* eg. `["dist/test-results/TEST-*.xml", "dist/rspec.xml", ...]`
|
|
71
73
|
*/
|
|
72
74
|
junit?: string[];
|
|
73
|
-
}
|
|
75
|
+
};
|
|
74
76
|
};
|
|
75
77
|
|
|
76
78
|
export type BuildConfigNodeBase = BuildConfigBase;
|
|
@@ -113,11 +115,44 @@ export type BuildConfigCustom = BuildConfigBase & {
|
|
|
113
115
|
type: "custom";
|
|
114
116
|
jobImage: string;
|
|
115
117
|
jobServices?: GitlabJobService[];
|
|
118
|
+
|
|
116
119
|
docker: BuildConfigCustomDocker;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* customize cache for the job
|
|
123
|
+
*/
|
|
124
|
+
jobCache?: CatladderJob["cache"];
|
|
117
125
|
};
|
|
118
126
|
|
|
119
127
|
export type BuildConfigRails = BuildConfigBase & {
|
|
120
128
|
type: "rails";
|
|
129
|
+
cnbBuilder?: {
|
|
130
|
+
/**
|
|
131
|
+
* The Cloud Native Buildpacks builder image to use.
|
|
132
|
+
* See e.g. https://github.com/heroku/builder or others.
|
|
133
|
+
* Default: heroku/buildpacks:20
|
|
134
|
+
*/
|
|
135
|
+
image?: string;
|
|
136
|
+
/**
|
|
137
|
+
* The version of the Cloud Native Buildpacks pack command to use.
|
|
138
|
+
* See https://buildpacks.io/docs/tools/pack/
|
|
139
|
+
* Default: 0.28.0
|
|
140
|
+
*/
|
|
141
|
+
packVersion?: string;
|
|
142
|
+
/**
|
|
143
|
+
* Additional command arguments passed to the pack command.
|
|
144
|
+
* See https://buildpacks.io/docs/tools/pack/
|
|
145
|
+
*/
|
|
146
|
+
packExtraArgs?: string[];
|
|
147
|
+
/**
|
|
148
|
+
* Variables needed for Bundler and Rails asset precompilation.
|
|
149
|
+
*
|
|
150
|
+
* Specify a key with the value `undefined` to inherit it from the EnvVars.
|
|
151
|
+
*
|
|
152
|
+
* See https://github.com/rails/rails/issues/32947
|
|
153
|
+
*/
|
|
154
|
+
buildVars?: Record<string, string | undefined>;
|
|
155
|
+
};
|
|
121
156
|
};
|
|
122
157
|
|
|
123
158
|
export type BuildConfigStorybook = BuildConfigNodeBase & {
|
|
@@ -17,12 +17,9 @@ describe("resolveReferences", () => {
|
|
|
17
17
|
FOO: "foo from frontend",
|
|
18
18
|
},
|
|
19
19
|
};
|
|
20
|
-
const result = await resolveReferences(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return otherVariables[componentName]?.[variableName];
|
|
24
|
-
}
|
|
25
|
-
);
|
|
20
|
+
const result = await resolveReferences(variables, async (componentName) => {
|
|
21
|
+
return otherVariables[componentName];
|
|
22
|
+
});
|
|
26
23
|
|
|
27
24
|
expect(result).toEqual({
|
|
28
25
|
a: "hello world",
|
|
@@ -53,12 +50,9 @@ describe("resolveReferences", () => {
|
|
|
53
50
|
FOO: "foo from api",
|
|
54
51
|
},
|
|
55
52
|
};
|
|
56
|
-
const result = await resolveReferences(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return otherVariables[componentName]?.[variableName];
|
|
60
|
-
}
|
|
61
|
-
);
|
|
53
|
+
const result = await resolveReferences(variables, async (componentName) => {
|
|
54
|
+
return otherVariables[componentName];
|
|
55
|
+
});
|
|
62
56
|
|
|
63
57
|
expect(result).toEqual({
|
|
64
58
|
FOO: "hello from foo from api",
|
|
@@ -72,12 +66,9 @@ describe("resolveReferences", () => {
|
|
|
72
66
|
b: "a not found value looks like this: '${api:FOO}'",
|
|
73
67
|
};
|
|
74
68
|
const otherVariables: Record<string, Record<string, string>> = {};
|
|
75
|
-
const result = await resolveReferences(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return otherVariables[componentName]?.[variableName];
|
|
79
|
-
}
|
|
80
|
-
);
|
|
69
|
+
const result = await resolveReferences(variables, async (componentName) => {
|
|
70
|
+
return otherVariables[componentName];
|
|
71
|
+
});
|
|
81
72
|
|
|
82
73
|
expect(result).toEqual({
|
|
83
74
|
a: "hello world",
|
|
@@ -97,12 +88,9 @@ describe("resolveReferences", () => {
|
|
|
97
88
|
FOO: "hi, ${api:FOO}",
|
|
98
89
|
},
|
|
99
90
|
};
|
|
100
|
-
const result = await resolveReferences(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return otherVariables[componentName]?.[variableName] ?? "";
|
|
104
|
-
}
|
|
105
|
-
);
|
|
91
|
+
const result = await resolveReferences(variables, async (componentName) => {
|
|
92
|
+
return otherVariables[componentName];
|
|
93
|
+
});
|
|
106
94
|
|
|
107
95
|
expect(result).toEqual({
|
|
108
96
|
a: "value is hi, foo from api!",
|
|
@@ -121,12 +109,9 @@ describe("resolveReferences", () => {
|
|
|
121
109
|
FOO: "frontend ${api:FOO}",
|
|
122
110
|
},
|
|
123
111
|
};
|
|
124
|
-
const result = await resolveReferences(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return otherVariables[componentName]?.[variableName] ?? "";
|
|
128
|
-
}
|
|
129
|
-
);
|
|
112
|
+
const result = await resolveReferences(variables, async (componentName) => {
|
|
113
|
+
return otherVariables[componentName];
|
|
114
|
+
});
|
|
130
115
|
|
|
131
116
|
expect(result).toEqual({
|
|
132
117
|
a: "value is frontend api ${frontend:FOO}!",
|
|
@@ -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,
|
|
@@ -53,7 +53,7 @@ export const getEnvironmentVariables = async (
|
|
|
53
53
|
} else {
|
|
54
54
|
const additionalEnvVars = deployConfigRaw
|
|
55
55
|
? DEPLOY_TYPES[deployConfigRaw.type].getAdditionalEnvVars(
|
|
56
|
-
environmentContext
|
|
56
|
+
environmentContext as never
|
|
57
57
|
)
|
|
58
58
|
: {};
|
|
59
59
|
|
|
@@ -66,7 +66,9 @@ export const getEnvironmentVariables = async (
|
|
|
66
66
|
predefinedVariables = {
|
|
67
67
|
...basePredefinedVariables,
|
|
68
68
|
// Rails before 6.1 (mis)uses the `HOST` environment variable to specify the IP to bind to
|
|
69
|
-
...(config.components[componentName].build.type === "rails"
|
|
69
|
+
...(config.components[componentName].build.type === "rails"
|
|
70
|
+
? {}
|
|
71
|
+
: { HOST: host }),
|
|
70
72
|
ROOT_URL: url,
|
|
71
73
|
...additionalEnvVars,
|
|
72
74
|
};
|
|
@@ -75,7 +77,7 @@ export const getEnvironmentVariables = async (
|
|
|
75
77
|
|
|
76
78
|
const additionalSecretKeys = deployConfigRaw
|
|
77
79
|
? DEPLOY_TYPES[deployConfigRaw.type].additionalSecretKeys(
|
|
78
|
-
environmentContext
|
|
80
|
+
environmentContext as never
|
|
79
81
|
)
|
|
80
82
|
: [];
|
|
81
83
|
|
|
@@ -115,7 +117,7 @@ export const getEnvironmentVariables = async (
|
|
|
115
117
|
|
|
116
118
|
const envVars = await resolveReferences(
|
|
117
119
|
envVarsRaw,
|
|
118
|
-
async (otherComponentName,
|
|
120
|
+
async (otherComponentName, alreadyVisited) => {
|
|
119
121
|
const { envVars: otherEnvVars } = await getEnvironmentVariables(
|
|
120
122
|
config,
|
|
121
123
|
otherComponentName,
|
|
@@ -123,7 +125,7 @@ export const getEnvironmentVariables = async (
|
|
|
123
125
|
commitInfo,
|
|
124
126
|
alreadyVisited
|
|
125
127
|
);
|
|
126
|
-
return otherEnvVars
|
|
128
|
+
return otherEnvVars;
|
|
127
129
|
},
|
|
128
130
|
alreadyVisited
|
|
129
131
|
);
|
|
@@ -7,9 +7,8 @@ export const resolveReferences = async (
|
|
|
7
7
|
vars: Record<string, string>,
|
|
8
8
|
getOtherVariables?: (
|
|
9
9
|
componentName: string,
|
|
10
|
-
variableName: string,
|
|
11
10
|
alreadyVisited: Record<string, Record<string, boolean>>
|
|
12
|
-
) => Promise<string | null
|
|
11
|
+
) => Promise<Record<string, string | null>>,
|
|
13
12
|
alreadyVisitedBase: Record<string, Record<string, boolean>> = {}
|
|
14
13
|
) => {
|
|
15
14
|
const replaceSingleValue = async (
|
|
@@ -30,10 +29,8 @@ export const resolveReferences = async (
|
|
|
30
29
|
},
|
|
31
30
|
});
|
|
32
31
|
const result = componentName
|
|
33
|
-
? (await getOtherVariables?.(
|
|
34
|
-
|
|
35
|
-
variableName,
|
|
36
|
-
newAlreadyVisited
|
|
32
|
+
? (await getOtherVariables?.(componentName, newAlreadyVisited).then(
|
|
33
|
+
(r) => r?.[variableName]
|
|
37
34
|
)) ?? null
|
|
38
35
|
: vars[variableName]; // is self reference
|
|
39
36
|
|
package/src/deploy/base.ts
CHANGED
|
@@ -44,7 +44,7 @@ export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
|
|
|
44
44
|
name: DEPLOY_JOB_NAME,
|
|
45
45
|
envMode: "stagePerEnv", // makes it easier to run manual tasks er env
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
needs: context.componentConfig.deploy
|
|
48
48
|
? context.componentConfig.deploy.waitFor?.map((c) => ({
|
|
49
49
|
componentName: c,
|
|
50
50
|
job: DEPLOY_JOB_NAME,
|
|
@@ -116,20 +116,18 @@ export const createGoogleCloudRunDeployJobs = (
|
|
|
116
116
|
: undefined;
|
|
117
117
|
|
|
118
118
|
const argsString = createArgsString({
|
|
119
|
-
|
|
119
|
+
// command as empty string resets it to default (uses the image's entrypoint)
|
|
120
|
+
command: command ? '"' + command.split(" ").join(",") + '"' : '""',
|
|
120
121
|
...commonDeployArgs,
|
|
121
122
|
"env-vars-file": "____envvars.yaml",
|
|
122
|
-
"min-instances": customConfig?.minInstances,
|
|
123
|
-
"max-instances": customConfig?.maxInstances,
|
|
124
|
-
"
|
|
123
|
+
"min-instances": customConfig?.minInstances ?? 0,
|
|
124
|
+
"max-instances": customConfig?.maxInstances ?? 100,
|
|
125
|
+
"cpu-throttling": customConfig?.noCpuThrottling !== true,
|
|
126
|
+
memory: customConfig?.memory,
|
|
127
|
+
"allow-unauthenticated": customConfig?.allowUnauthenticated ?? true,
|
|
125
128
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
? "--allow-unauthenticated"
|
|
129
|
-
: "--no-allow-unauthenticated";
|
|
130
|
-
return `gcloud run deploy ${serviceName}${
|
|
131
|
-
nameSuffix ?? ""
|
|
132
|
-
} ${argsString} ${authenticationString}`;
|
|
129
|
+
|
|
130
|
+
return `gcloud run deploy ${serviceName}${nameSuffix ?? ""} ${argsString}`;
|
|
133
131
|
};
|
|
134
132
|
|
|
135
133
|
const getJobCreateScriptsForJob = (
|
|
@@ -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("-");
|
|
@@ -67,9 +68,9 @@ export const GCLOUD_RUN_DEPLOY_TYPE: DeployTypeDefinition<"google-cloudrun"> = {
|
|
|
67
68
|
const HOST_CANONICAL =
|
|
68
69
|
fullName.toLowerCase() +
|
|
69
70
|
"-" +
|
|
70
|
-
process.env[
|
|
71
|
+
(process.env[
|
|
71
72
|
getSecretVarName(env, componentName, GCLOUD_RUN_CANONICAL_HOST_SUFFIX)
|
|
72
|
-
];
|
|
73
|
+
] ?? "unknown-host.example.com");
|
|
73
74
|
|
|
74
75
|
const jobTriggers =
|
|
75
76
|
deployConfigRaw && deployConfigRaw.jobs
|