@catladder/pipeline 2.7.0 → 2.7.2
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/constants.js +1 -1
- package/dist/deploy/cloudRun/createJobs/cloudRunJobs.js +39 -32
- package/dist/pipeline/gitlab/createGitlabJobs.js +13 -9
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/examples/__snapshots__/cloud-run-http2.test.ts.snap +0 -16
- package/examples/__snapshots__/cloud-run-memory-limit.test.ts.snap +0 -16
- package/examples/__snapshots__/cloud-run-meteor-with-worker.test.ts.snap +0 -16
- package/examples/__snapshots__/cloud-run-nextjs.test.ts.snap +0 -16
- package/examples/__snapshots__/cloud-run-no-cpu-throttling.test.ts.snap +0 -16
- package/examples/__snapshots__/cloud-run-no-service.test.ts.snap +0 -16
- package/examples/__snapshots__/cloud-run-non-public.test.ts.snap +0 -16
- package/examples/__snapshots__/cloud-run-post-stop-job.test.ts.snap +0 -16
- package/examples/__snapshots__/cloud-run-service-custom-vpc-connector.test.ts.snap +0 -16
- package/examples/__snapshots__/cloud-run-service-custom-vpc.test.ts.snap +0 -16
- package/examples/__snapshots__/cloud-run-service-gen2.test.ts.snap +0 -16
- package/examples/__snapshots__/cloud-run-service-increase-timout.test.ts.snap +0 -16
- package/examples/__snapshots__/cloud-run-service-with-volumes.test.ts.snap +0 -16
- package/examples/__snapshots__/cloud-run-storybook.test.ts.snap +0 -16
- package/examples/__snapshots__/cloud-run-with-ngnix.test.ts.snap +0 -16
- package/examples/__snapshots__/cloud-run-with-sql-reuse-db.test.ts.snap +0 -32
- package/examples/__snapshots__/cloud-run-with-sql.test.ts.snap +0 -16
- package/examples/__snapshots__/cloud-run-with-worker.test.ts.snap +0 -16
- package/examples/__snapshots__/custom-build-job-with-tests.test.ts.snap +0 -16
- package/examples/__snapshots__/custom-build-job.test.ts.snap +0 -16
- package/examples/__snapshots__/custom-deploy.test.ts.snap +0 -4
- package/examples/__snapshots__/custom-sbom-java.test.ts.snap +0 -16
- package/examples/__snapshots__/custom-verify-job.test.ts.snap +0 -24
- package/examples/__snapshots__/git-submodule.test.ts.snap +0 -16
- package/examples/__snapshots__/kubernetes-application-customization.test.ts.snap +0 -32
- package/examples/__snapshots__/kubernetes-with-cloud-sql.test.ts.snap +0 -32
- package/examples/__snapshots__/kubernetes-with-jobs.test.ts.snap +0 -64
- package/examples/__snapshots__/kubernetes-with-mongodb.test.ts.snap +0 -32
- package/examples/__snapshots__/local-dot-env.test.ts.snap +0 -16
- package/examples/__snapshots__/meteor-kubernetes.test.ts.snap +0 -32
- package/examples/__snapshots__/multiline-var.test.ts.snap +0 -64
- package/examples/__snapshots__/native-app.test.ts.snap +0 -16
- package/examples/__snapshots__/node-build-with-custom-image.test.ts.snap +0 -16
- package/examples/__snapshots__/node-build-with-docker-additions.test.ts.snap +0 -16
- package/examples/__snapshots__/rails-k8s-with-worker-dockerfile.test.ts.snap +0 -32
- package/examples/__snapshots__/rails-k8s-with-worker.test.ts.snap +0 -32
- package/examples/__snapshots__/referencing-other-vars.test.ts.snap +0 -64
- package/examples/__snapshots__/workspace-api-www-turbo-cache.test.ts.snap +0 -32
- package/examples/__snapshots__/workspace-api-www.test.ts.snap +0 -32
- package/package.json +1 -1
- package/src/deploy/cloudRun/createJobs/cloudRunJobs.ts +65 -49
- package/src/pipeline/gitlab/createGitlabJobs.ts +18 -12
|
@@ -38,16 +38,14 @@ const getJobRunScriptForJob = (
|
|
|
38
38
|
|
|
39
39
|
export const getDeleteSchedulesScripts = (context: ComponentContext) => {
|
|
40
40
|
const deployConfig = getCloudRunDeployConfig(context);
|
|
41
|
-
const
|
|
41
|
+
const schedules = getSchedules(context);
|
|
42
42
|
const argsString = createArgsString({
|
|
43
43
|
project: deployConfig.projectId,
|
|
44
44
|
location: deployConfig.region,
|
|
45
45
|
});
|
|
46
|
-
return
|
|
47
|
-
.map(({
|
|
48
|
-
return [
|
|
49
|
-
`${gcloudSchedulerCmd()} jobs delete ${schedulerName} ${argsString}`,
|
|
50
|
-
];
|
|
46
|
+
return schedules
|
|
47
|
+
.map(({ name }) => {
|
|
48
|
+
return [`${gcloudSchedulerCmd()} jobs delete ${name} ${argsString}`];
|
|
51
49
|
})
|
|
52
50
|
.flat();
|
|
53
51
|
};
|
|
@@ -142,48 +140,62 @@ export const getJobCreateScripts = (context: ComponentContext): string[] =>
|
|
|
142
140
|
export const getCreateScheduleScripts = (
|
|
143
141
|
context: ComponentContext,
|
|
144
142
|
): string[] => {
|
|
145
|
-
const
|
|
143
|
+
const schedules = getSchedules(context);
|
|
146
144
|
const { region: location, projectId: project } =
|
|
147
145
|
getCloudRunDeployConfig(context);
|
|
148
146
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
`else`,
|
|
177
|
-
` ${gcloudSchedulerCmd()} jobs create http "$current_scheduler_name" ${argsString}`,
|
|
178
|
-
`fi`,
|
|
179
|
-
]
|
|
180
|
-
.filter(notNil)
|
|
181
|
-
.join("\n");
|
|
182
|
-
},
|
|
183
|
-
);
|
|
147
|
+
return schedules.map((scheduler, jobIndex): string => {
|
|
148
|
+
const uri = getSchedulerUrl(scheduler, context);
|
|
149
|
+
|
|
150
|
+
const argsString = createArgsString({
|
|
151
|
+
project,
|
|
152
|
+
location,
|
|
153
|
+
uri: `"$current_job_uri"`,
|
|
154
|
+
"http-method": "POST",
|
|
155
|
+
"oauth-service-account-email": `"$GCLOUD_PROJECT_NUMBER-compute@developer.gserviceaccount.com"`,
|
|
156
|
+
schedule: `"${scheduler.schedule}"`,
|
|
157
|
+
"max-retry-attempts": scheduler.maxRetryAttempts ?? 0,
|
|
158
|
+
});
|
|
159
|
+
return [
|
|
160
|
+
jobIndex === 0
|
|
161
|
+
? `exist_scheduler_names="$(\n ${gcloudSchedulerCmd()} jobs list --filter='httpTarget.uri ~ ${context.env}.*${context.name}' --format='value(name)' --limit=999 --location='${location}' --project='${project}'\n)"`
|
|
162
|
+
: null,
|
|
163
|
+
`current_job_uri="${uri}"`,
|
|
164
|
+
`current_scheduler_name="${scheduler.name}"`,
|
|
165
|
+
`if grep "$current_scheduler_name" <<<"$exist_scheduler_names" >/dev/null; then`,
|
|
166
|
+
` ${gcloudSchedulerCmd()} jobs update http "$current_scheduler_name" ${argsString}`,
|
|
167
|
+
`else`,
|
|
168
|
+
` ${gcloudSchedulerCmd()} jobs create http "$current_scheduler_name" ${argsString}`,
|
|
169
|
+
`fi`,
|
|
170
|
+
]
|
|
171
|
+
.filter(notNil)
|
|
172
|
+
.join("\n");
|
|
173
|
+
});
|
|
184
174
|
};
|
|
185
175
|
|
|
186
|
-
|
|
176
|
+
type Scheduler = {
|
|
177
|
+
name: StringOrBashExpression;
|
|
178
|
+
maxRetryAttempts?: number;
|
|
179
|
+
schedule: string;
|
|
180
|
+
} & {
|
|
181
|
+
type: "cloudRunJob";
|
|
182
|
+
jobName: StringOrBashExpression;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const getSchedulerUrl = (scheduler: Scheduler, context: ComponentContext) => {
|
|
186
|
+
if (scheduler.type === "cloudRunJob") {
|
|
187
|
+
const { region: location, projectId: project } =
|
|
188
|
+
getCloudRunDeployConfig(context);
|
|
189
|
+
|
|
190
|
+
const uriBase = `https://${location}-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${project}/jobs`;
|
|
191
|
+
|
|
192
|
+
return `${uriBase}/${scheduler.jobName}:run`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
throw new Error(`Unknown scheduler type: ${scheduler.type}`);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const getSchedules = (context: ComponentContext): Scheduler[] => {
|
|
187
199
|
const jobsWithNames = getCloudRunJobsWithNames(context);
|
|
188
200
|
|
|
189
201
|
return jobsWithNames
|
|
@@ -196,12 +208,16 @@ const getCloudRunJobsWithSchedule = (context: ComponentContext) => {
|
|
|
196
208
|
jobKey: string;
|
|
197
209
|
} => entry.job.when === "schedule",
|
|
198
210
|
)
|
|
199
|
-
.map(({ job,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
211
|
+
.map(({ job: { maxRetryAttempts, schedule }, jobName }) => {
|
|
212
|
+
const schedulerName = jobName.concat("-scheduler");
|
|
213
|
+
return {
|
|
214
|
+
name: schedulerName,
|
|
215
|
+
maxRetryAttempts,
|
|
216
|
+
schedule,
|
|
217
|
+
type: "cloudRunJob",
|
|
218
|
+
jobName,
|
|
219
|
+
};
|
|
220
|
+
});
|
|
205
221
|
};
|
|
206
222
|
|
|
207
223
|
const getCloudRunJobsWithNames = (context: ComponentContext) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isObject, merge } from "lodash";
|
|
1
|
+
import { isEmpty, isObject, merge } from "lodash";
|
|
2
2
|
import { getInjectVarsScript } from "../../bash/getInjectVarsScript";
|
|
3
3
|
import { BASE_RETRY } from "../../defaults";
|
|
4
4
|
import type {
|
|
@@ -228,6 +228,20 @@ const addGitlabEnvironment = (
|
|
|
228
228
|
// those can be dynamic, so we therefore have to do this: https://docs.gitlab.com/ee/ci/environments/#set-a-dynamic-environment-url
|
|
229
229
|
|
|
230
230
|
const dotEnvFile = "gitlab_environment.env";
|
|
231
|
+
const createsJobEnv =
|
|
232
|
+
!catladderJobEnvironment.action ||
|
|
233
|
+
catladderJobEnvironment.action === "start";
|
|
234
|
+
|
|
235
|
+
const artifacts = merge(
|
|
236
|
+
job.artifacts ?? {},
|
|
237
|
+
createsJobEnv
|
|
238
|
+
? {
|
|
239
|
+
reports: {
|
|
240
|
+
dotenv: dotEnvFile,
|
|
241
|
+
},
|
|
242
|
+
}
|
|
243
|
+
: {},
|
|
244
|
+
);
|
|
231
245
|
|
|
232
246
|
const scriptToAdd = [
|
|
233
247
|
`echo "${GITLAB_ENVIRONMENT_URL_VARIABLE}=${getBashVariable("ROOT_URL")}" >> ${dotEnvFile}`,
|
|
@@ -243,10 +257,7 @@ const addGitlabEnvironment = (
|
|
|
243
257
|
...job,
|
|
244
258
|
environment: {
|
|
245
259
|
name: gitlabEnvironmentName,
|
|
246
|
-
...(
|
|
247
|
-
catladderJobEnvironment.action === "start"
|
|
248
|
-
? { url: `$${GITLAB_ENVIRONMENT_URL_VARIABLE}` }
|
|
249
|
-
: {}),
|
|
260
|
+
...(createsJobEnv ? { url: `$${GITLAB_ENVIRONMENT_URL_VARIABLE}` } : {}),
|
|
250
261
|
...(on_stop
|
|
251
262
|
? {
|
|
252
263
|
on_stop: getFullReferencedJobNameFromComponent(
|
|
@@ -259,13 +270,8 @@ const addGitlabEnvironment = (
|
|
|
259
270
|
: {}),
|
|
260
271
|
...restEnvironment,
|
|
261
272
|
},
|
|
262
|
-
artifacts
|
|
263
|
-
|
|
264
|
-
dotenv: `${dotEnvFile}`,
|
|
265
|
-
},
|
|
266
|
-
}),
|
|
267
|
-
|
|
268
|
-
script: [...(job.script ?? []), ...scriptToAdd],
|
|
273
|
+
...(!isEmpty(artifacts) ? { artifacts } : {}),
|
|
274
|
+
script: [...(job.script ?? []), ...(createsJobEnv ? scriptToAdd : [])],
|
|
269
275
|
};
|
|
270
276
|
};
|
|
271
277
|
|