@catladder/pipeline 0.0.0-mongodb-tolerations-bc2a3387 → 0.0.0-multiple-gitlab-includes-1a40efc0
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/README.md +17 -0
- package/dist/bash/BashExpression.d.ts +36 -0
- package/dist/bash/BashExpression.js +114 -0
- package/dist/bash/bashEscape.d.ts +34 -0
- package/dist/bash/bashEscape.js +114 -0
- package/dist/bash/bashExpressionPerPipelineType.d.ts +6 -0
- package/dist/bash/bashExpressionPerPipelineType.js +11 -0
- package/dist/bash/bashYaml.d.ts +10 -0
- package/dist/bash/bashYaml.js +69 -0
- package/dist/bash/getInjectVarsScript.d.ts +2 -0
- package/dist/bash/getInjectVarsScript.js +47 -0
- package/dist/bash/index.d.ts +2 -0
- package/dist/bash/index.js +26 -0
- package/dist/build/artifacts/createBuildJobArtifact.d.ts +3 -0
- package/dist/build/artifacts/createBuildJobArtifact.js +97 -0
- package/dist/build/base/__tests__/createArtifactsConfig.test.js +42 -0
- package/dist/build/base/constants.d.ts +0 -1
- package/dist/build/base/constants.js +4 -3
- package/dist/build/base/createAppBuildJob.d.ts +10 -0
- package/dist/build/base/{createBuildJob.js → createAppBuildJob.js} +22 -18
- package/dist/build/base/createArtifactsConfig.d.ts +4 -0
- package/dist/build/base/createArtifactsConfig.js +65 -0
- package/dist/build/base/createBuildJobDefinition.d.ts +6 -0
- package/dist/build/base/createBuildJobDefinition.js +58 -0
- package/dist/build/base/index.d.ts +11 -0
- package/dist/build/base/index.js +68 -0
- package/dist/build/base/writeBuildInfo.d.ts +2 -2
- package/dist/build/base/writeBuildInfo.js +4 -3
- package/dist/build/base/writeDotEnv.d.ts +8 -0
- package/dist/build/base/writeDotEnv.js +67 -0
- package/dist/build/cache/createJobCache.d.ts +7 -0
- package/dist/build/cache/createJobCache.js +115 -0
- package/dist/build/cache/getAllCacheConfigsFromConfig.d.ts +3 -0
- package/dist/build/cache/getAllCacheConfigsFromConfig.js +64 -0
- package/dist/build/cache/transformLegacyJobCache.d.ts +3 -0
- package/dist/build/cache/transformLegacyJobCache.js +29 -0
- package/dist/build/custom/__tests__/testJob.test.d.ts +1 -0
- package/dist/build/custom/__tests__/testJob.test.js +36 -0
- package/dist/build/custom/buildJob.d.ts +2 -2
- package/dist/build/custom/buildJob.js +12 -71
- package/dist/build/custom/index.d.ts +2 -2
- package/dist/build/custom/index.js +3 -1
- package/dist/build/custom/testJob.d.ts +6 -2
- package/dist/build/custom/testJob.js +27 -22
- package/dist/build/docker.d.ts +51 -36
- package/dist/build/docker.js +92 -50
- package/dist/build/index.d.ts +14 -7
- package/dist/build/index.js +44 -16
- package/dist/build/node/buildJob.d.ts +6 -2
- package/dist/build/node/buildJob.js +37 -47
- package/dist/build/node/cache.d.ts +4 -5
- package/dist/build/node/cache.js +18 -23
- package/dist/build/node/constants.d.ts +0 -1
- package/dist/build/node/constants.js +5 -4
- package/dist/build/node/index.d.ts +4 -4
- package/dist/build/node/index.js +3 -1
- package/dist/build/node/meteor.d.ts +2 -2
- package/dist/build/node/meteor.js +22 -24
- package/dist/build/node/testJob.d.ts +3 -2
- package/dist/build/node/testJob.js +33 -19
- package/dist/build/node/yarn.d.ts +5 -5
- package/dist/build/node/yarn.js +35 -20
- package/dist/build/rails/build.d.ts +2 -2
- package/dist/build/rails/build.js +49 -10
- package/dist/build/rails/index.d.ts +2 -2
- package/dist/build/rails/index.js +3 -1
- package/dist/build/rails/test.d.ts +2 -2
- package/dist/build/rails/test.js +20 -12
- package/dist/build/sbom.d.ts +5 -0
- package/dist/build/sbom.js +32 -0
- package/dist/build/types.d.ts +214 -67
- package/dist/build/types.js +10 -2
- package/dist/catladder-gitlab.js +129 -49
- package/dist/config/__tests__/configruedEnvs.test.js +3 -1
- package/dist/config/__tests__/getAllEnvs.test.d.ts +1 -0
- package/dist/config/__tests__/getAllEnvs.test.js +79 -0
- package/dist/config/__tests__/getAllEnvsInAllComponents.test.d.ts +1 -0
- package/dist/config/__tests__/getAllEnvsInAllComponents.test.js +73 -0
- package/dist/config/configruedEnvs.js +3 -1
- package/dist/config/index.js +13 -7
- package/dist/config/readConfig.d.ts +2 -2
- package/dist/config/readConfig.js +191 -40
- package/dist/constants.js +5 -3
- package/dist/context/createAllComponentsContext.d.ts +12 -0
- package/dist/{pipeline/commitInfo/getCommitInfo.js → context/createAllComponentsContext.js} +35 -16
- package/dist/context/createComponentContext.d.ts +11 -0
- package/dist/context/createComponentContext.js +255 -0
- package/dist/context/createWorkspaceContext.d.ts +16 -0
- package/dist/context/createWorkspaceContext.js +173 -0
- package/dist/context/getBuildInfoVariables.d.ts +6 -0
- package/dist/context/getBuildInfoVariables.js +55 -0
- package/dist/context/getEnvConfig.js +5 -2
- package/dist/context/getEnvType.js +3 -1
- package/dist/context/getEnvironment.d.ts +3 -3
- package/dist/context/getEnvironment.js +26 -21
- package/dist/context/getEnvironmentContext.d.ts +7 -3
- package/dist/context/getEnvironmentContext.js +21 -11
- package/dist/context/getEnvironmentVariables.d.ts +22 -10
- package/dist/context/getEnvironmentVariables.js +85 -54
- package/dist/context/getLabels.d.ts +3 -2
- package/dist/context/getLabels.js +9 -6
- package/dist/context/getReviewSlug.d.ts +4 -0
- package/dist/context/getReviewSlug.js +21 -0
- package/dist/context/index.d.ts +2 -4
- package/dist/context/index.js +15 -162
- package/dist/context/transformJobOnlyVars.d.ts +13 -0
- package/dist/{pipeline/commitInfo/getBuildId.js → context/transformJobOnlyVars.js} +41 -14
- package/dist/context/utils/envVars.d.ts +8 -0
- package/dist/context/utils/envVars.js +55 -0
- package/dist/defaults/index.js +3 -1
- package/dist/deploy/base/deploy.d.ts +5 -0
- package/dist/deploy/base/deploy.js +122 -0
- package/dist/deploy/base/index.d.ts +8 -0
- package/dist/deploy/base/index.js +44 -0
- package/dist/deploy/base/rollback.d.ts +5 -0
- package/dist/deploy/base/rollback.js +41 -0
- package/dist/deploy/base/stop.d.ts +5 -0
- package/dist/deploy/base/stop.js +46 -0
- package/dist/deploy/base/types.d.ts +2 -0
- package/dist/deploy/base/types.js +5 -0
- package/dist/deploy/base/variables.d.ts +5 -0
- package/dist/deploy/base/variables.js +11 -0
- package/dist/deploy/cloudRun/artifactsRegistry.d.ts +19 -0
- package/dist/deploy/cloudRun/artifactsRegistry.js +125 -0
- package/dist/deploy/cloudRun/cleanup.d.ts +2 -0
- package/dist/deploy/cloudRun/cleanup.js +53 -0
- package/dist/deploy/cloudRun/cloudRunRevisions.d.ts +2 -0
- package/dist/deploy/cloudRun/cloudRunRevisions.js +62 -0
- package/dist/deploy/cloudRun/createJobs/cloudRunJobs.d.ts +7 -0
- package/dist/deploy/cloudRun/createJobs/cloudRunJobs.js +207 -0
- package/dist/deploy/cloudRun/createJobs/cloudRunServices.d.ts +4 -0
- package/dist/deploy/cloudRun/createJobs/cloudRunServices.js +96 -0
- package/dist/deploy/cloudRun/createJobs/common.d.ts +18 -0
- package/dist/deploy/cloudRun/createJobs/common.js +93 -0
- package/dist/deploy/cloudRun/createJobs/constants.d.ts +1 -0
- package/dist/deploy/cloudRun/createJobs/constants.js +7 -0
- package/dist/deploy/cloudRun/createJobs/getCloudRunDeployScripts.d.ts +2 -0
- package/dist/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js +62 -0
- package/dist/deploy/cloudRun/createJobs/getCloudRunStopScripts.d.ts +2 -0
- package/dist/deploy/cloudRun/createJobs/getCloudRunStopScripts.js +54 -0
- package/dist/deploy/cloudRun/createJobs/index.d.ts +3 -0
- package/dist/deploy/cloudRun/createJobs/index.js +57 -0
- package/dist/deploy/cloudRun/createJobs/volumes.d.ts +3 -0
- package/dist/deploy/cloudRun/createJobs/volumes.js +58 -0
- package/dist/deploy/cloudRun/index.d.ts +2 -2
- package/dist/deploy/cloudRun/index.js +17 -10
- package/dist/deploy/cloudRun/utils/createArgsString.d.ts +3 -1
- package/dist/deploy/cloudRun/utils/createArgsString.js +25 -17
- package/dist/deploy/cloudRun/utils/database.d.ts +6 -4
- package/dist/deploy/cloudRun/utils/database.js +28 -15
- package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.d.ts +2 -2
- package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.js +4 -2
- package/dist/deploy/cloudRun/utils/getServiceName.d.ts +2 -0
- package/dist/deploy/cloudRun/utils/getServiceName.js +10 -0
- package/dist/deploy/cloudRun/utils/jobName.d.ts +2 -1
- package/dist/deploy/cloudRun/utils/jobName.js +4 -2
- package/dist/deploy/cloudRun/utils/removeFirstLinesFromCommandOutput.d.ts +9 -0
- package/dist/deploy/cloudRun/utils/removeFirstLinesFromCommandOutput.js +18 -0
- package/dist/deploy/cloudSql/utils.d.ts +2 -1
- package/dist/deploy/cloudSql/utils.js +7 -2
- package/dist/deploy/custom/deployJob.d.ts +2 -2
- package/dist/deploy/custom/deployJob.js +24 -16
- package/dist/deploy/custom/index.d.ts +2 -2
- package/dist/deploy/custom/index.js +3 -1
- package/dist/deploy/dockerTag/deployJob.d.ts +2 -2
- package/dist/deploy/dockerTag/deployJob.js +51 -10
- package/dist/deploy/dockerTag/index.d.ts +2 -2
- package/dist/deploy/dockerTag/index.js +3 -1
- package/dist/deploy/index.d.ts +10 -9
- package/dist/deploy/index.js +13 -7
- package/dist/deploy/kubernetes/additionalSecretKeys.d.ts +3 -1
- package/dist/deploy/kubernetes/additionalSecretKeys.js +3 -1
- package/dist/deploy/kubernetes/cloudSql/index.d.ts +6 -5
- package/dist/deploy/kubernetes/cloudSql/index.js +14 -21
- package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
- package/dist/deploy/kubernetes/deployJob.js +35 -45
- package/dist/deploy/kubernetes/index.d.ts +2 -2
- package/dist/deploy/kubernetes/index.js +52 -15
- package/dist/deploy/kubernetes/kubeEnv.d.ts +5 -4
- package/dist/deploy/kubernetes/kubeEnv.js +9 -5
- package/dist/deploy/kubernetes/kubeValues.d.ts +6 -9
- package/dist/deploy/kubernetes/kubeValues.js +16 -18
- package/dist/deploy/kubernetes/mongodb.d.ts +2 -2
- package/dist/deploy/kubernetes/mongodb.js +19 -16
- package/dist/deploy/sbom.d.ts +4 -0
- package/dist/deploy/sbom.js +20 -0
- package/dist/deploy/types/base.d.ts +18 -2
- package/dist/deploy/types/base.js +3 -1
- package/dist/deploy/types/custom.d.ts +3 -7
- package/dist/deploy/types/custom.js +3 -1
- package/dist/deploy/types/dockerTag.d.ts +3 -1
- package/dist/deploy/types/dockerTag.js +3 -1
- package/dist/deploy/types/googleCloudRun.d.ts +133 -24
- package/dist/deploy/types/googleCloudRun.js +3 -1
- package/dist/deploy/types/index.d.ts +6 -6
- package/dist/deploy/types/index.js +14 -8
- package/dist/deploy/types/kubernetes.d.ts +41 -55
- package/dist/deploy/types/kubernetes.js +3 -1
- package/dist/deploy/utils.d.ts +2 -2
- package/dist/deploy/utils.js +5 -2
- package/dist/globalScriptFunctions/index.d.ts +14 -0
- package/dist/globalScriptFunctions/index.js +37 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +18 -9
- package/dist/packageInfos.d.ts +4 -0
- package/dist/packageInfos.js +20 -0
- package/dist/pipeline/__tests__/getPipelineStages.test.d.ts +1 -0
- package/dist/pipeline/__tests__/getPipelineStages.test.js +73 -0
- package/dist/pipeline/createAllJobs.d.ts +16 -6
- package/dist/pipeline/createAllJobs.js +99 -27
- package/dist/pipeline/createJobsForComponent.d.ts +2 -2
- package/dist/pipeline/createJobsForComponent.js +10 -152
- package/dist/pipeline/createJobsForWorkspace.d.ts +3 -0
- package/dist/pipeline/createJobsForWorkspace.js +12 -0
- package/dist/pipeline/createMainPipeline.d.ts +3 -0
- package/dist/pipeline/createMainPipeline.js +283 -0
- package/dist/pipeline/generatePipelineFiles.d.ts +7 -0
- package/dist/pipeline/generatePipelineFiles.js +304 -0
- package/dist/pipeline/getPipelineStages.d.ts +7 -0
- package/dist/pipeline/getPipelineStages.js +56 -0
- package/dist/pipeline/gitlab/createGitlabJobs.d.ts +11 -12
- package/dist/pipeline/gitlab/createGitlabJobs.js +259 -60
- package/dist/pipeline/gitlab/createGitlabPipeline.d.ts +9 -0
- package/dist/pipeline/gitlab/createGitlabPipeline.js +77 -0
- package/dist/pipeline/gitlab/gitlabReleaseJobs.d.ts +33 -0
- package/dist/pipeline/gitlab/gitlabReleaseJobs.js +25 -0
- package/dist/pipeline/gitlab/sortGitLabJobDefProps.d.ts +7 -0
- package/dist/pipeline/gitlab/sortGitLabJobDefProps.js +27 -0
- package/dist/pipeline/index.d.ts +3 -2
- package/dist/pipeline/index.js +16 -9
- package/dist/pipeline/packageManager.d.ts +3 -2
- package/dist/pipeline/packageManager.js +52 -26
- package/dist/pipeline/yarn/yarnUtils.d.ts +3 -2
- package/dist/pipeline/yarn/yarnUtils.js +65 -17
- package/dist/rules/index.d.ts +7 -2
- package/dist/rules/index.js +34 -16
- package/dist/runner/index.d.ts +1 -1
- package/dist/runner/index.js +3 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +52 -25
- package/dist/types/config.js +5 -2
- package/dist/types/context.d.ts +132 -37
- package/dist/types/context.js +12 -1
- package/dist/types/environmentContext.d.ts +15 -12
- package/dist/types/environmentContext.js +3 -1
- package/dist/types/gitlab-ci-yml.d.ts +769 -0
- package/dist/types/gitlab-ci-yml.js +10 -0
- package/dist/types/gitlab-types.d.ts +15 -96
- package/dist/types/gitlab-types.js +3 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +14 -7
- package/dist/types/jobDefinition.d.ts +11 -0
- package/dist/types/jobDefinition.js +5 -0
- package/dist/types/jobs.d.ts +35 -16
- package/dist/types/jobs.js +3 -1
- package/dist/types/pipeline.d.ts +3 -3
- package/dist/types/pipeline.js +3 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/utils.js +3 -1
- package/dist/utils/gitlab.d.ts +2 -1
- package/dist/utils/gitlab.js +14 -3
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +10 -3
- package/dist/utils/jsonParse.d.ts +1 -0
- package/dist/utils/jsonParse.js +14 -0
- package/dist/utils/removeUndefined.d.ts +1 -0
- package/dist/utils/removeUndefined.js +36 -0
- package/dist/utils/writeFiles.d.ts +11 -0
- package/dist/utils/writeFiles.js +172 -0
- package/dist/variables/VariableValue.d.ts +3 -0
- package/dist/variables/VariableValue.js +5 -0
- package/dist/variables/VariableValueContainingReferences.d.ts +24 -0
- package/dist/variables/VariableValueContainingReferences.js +97 -0
- package/dist/variables/__tests__/resolveAllReferences.test.d.ts +1 -0
- package/dist/variables/__tests__/resolveAllReferences.test.js +218 -0
- package/dist/variables/__tests__/resolveAllReferencesOnce.test.d.ts +1 -0
- package/dist/variables/__tests__/resolveAllReferencesOnce.test.js +171 -0
- package/dist/variables/__tests__/resolveReferencesOnce.test.d.ts +1 -0
- package/dist/variables/__tests__/resolveReferencesOnce.test.js +199 -0
- package/dist/variables/__tests__/variableValue.test.d.ts +1 -0
- package/dist/variables/__tests__/variableValue.test.js +36 -0
- package/dist/variables/resolveAllReferences.d.ts +3 -0
- package/dist/{pipeline/createChildPipeline.js → variables/resolveAllReferences.js} +44 -47
- package/dist/variables/resolveAllReferencesOnce.d.ts +5 -0
- package/dist/variables/resolveAllReferencesOnce.js +191 -0
- package/dist/variables/resolveReferencesOnce.d.ts +8 -0
- package/dist/variables/resolveReferencesOnce.js +22 -0
- package/examples/.test-gen-ignore +1 -0
- package/examples/__snapshots__/cloud-run-http2.test.ts.snap +1418 -0
- package/examples/__snapshots__/cloud-run-memory-limit.test.ts.snap +1418 -0
- package/examples/__snapshots__/cloud-run-meteor-with-worker.test.ts.snap +1418 -0
- package/examples/__snapshots__/cloud-run-nextjs.test.ts.snap +1434 -0
- package/examples/__snapshots__/cloud-run-no-cpu-throttling.test.ts.snap +1418 -0
- package/examples/__snapshots__/cloud-run-no-service.test.ts.snap +1526 -0
- package/examples/__snapshots__/cloud-run-non-public.test.ts.snap +1418 -0
- package/examples/__snapshots__/cloud-run-post-stop-job.test.ts.snap +1436 -0
- package/examples/__snapshots__/cloud-run-service-custom-vpc-connector.test.ts.snap +1418 -0
- package/examples/__snapshots__/cloud-run-service-custom-vpc.test.ts.snap +1418 -0
- package/examples/__snapshots__/cloud-run-service-gen2.test.ts.snap +1418 -0
- package/examples/__snapshots__/cloud-run-service-increase-timout.test.ts.snap +1418 -0
- package/examples/__snapshots__/cloud-run-service-with-volumes.test.ts.snap +1490 -0
- package/examples/__snapshots__/cloud-run-storybook.test.ts.snap +1302 -0
- package/examples/__snapshots__/cloud-run-with-ngnix.test.ts.snap +1418 -0
- package/examples/__snapshots__/cloud-run-with-sql-reuse-db.test.ts.snap +2998 -0
- package/examples/__snapshots__/cloud-run-with-sql.test.ts.snap +1733 -0
- package/examples/__snapshots__/cloud-run-with-worker.test.ts.snap +1426 -0
- package/examples/__snapshots__/custom-build-job-with-tests.test.ts.snap +1285 -0
- package/examples/__snapshots__/custom-build-job.test.ts.snap +1174 -0
- package/examples/__snapshots__/custom-deploy.test.ts.snap +1168 -0
- package/examples/__snapshots__/custom-envs.test.ts.snap +798 -0
- package/examples/__snapshots__/custom-sbom-java.test.ts.snap +1182 -0
- package/examples/__snapshots__/git-submodule.test.ts.snap +1419 -0
- package/examples/__snapshots__/kubernetes-application-customization.test.ts.snap +1759 -0
- package/examples/__snapshots__/kubernetes-with-cloud-sql.test.ts.snap +1779 -0
- package/examples/__snapshots__/kubernetes-with-jobs.test.ts.snap +3357 -0
- package/examples/__snapshots__/kubernetes-with-mongodb.test.ts.snap +1883 -0
- package/examples/__snapshots__/local-dot-env.test.ts.snap +1342 -0
- package/examples/__snapshots__/meteor-kubernetes.test.ts.snap +1836 -0
- package/examples/__snapshots__/multiline-var.test.ts.snap +5679 -0
- package/examples/__snapshots__/native-app.test.ts.snap +2206 -0
- package/examples/__snapshots__/node-build-with-custom-image.test.ts.snap +1418 -0
- package/examples/__snapshots__/node-build-with-docker-additions.test.ts.snap +1426 -0
- package/examples/__snapshots__/rails-k8s-with-worker-dockerfile.test.ts.snap +1487 -0
- package/examples/__snapshots__/rails-k8s-with-worker.test.ts.snap +1471 -0
- package/examples/__snapshots__/referencing-other-vars.test.ts.snap +4739 -0
- package/examples/__snapshots__/wait-for-other-deploy.test.ts.snap +1368 -0
- package/examples/__snapshots__/workspace-api-www-turbo-cache.test.ts.snap +2338 -0
- package/examples/__snapshots__/workspace-api-www.test.ts.snap +2330 -0
- package/examples/__utils__/helpers.ts +9 -12
- package/examples/cloud-run-http2.test.ts +11 -0
- package/examples/cloud-run-http2.ts +29 -0
- package/examples/cloud-run-memory-limit.test.ts +11 -0
- package/examples/cloud-run-memory-limit.ts +10 -5
- package/examples/cloud-run-meteor-with-worker.test.ts +11 -0
- package/examples/cloud-run-meteor-with-worker.ts +37 -0
- package/examples/cloud-run-nextjs.test.ts +11 -0
- package/examples/cloud-run-nextjs.ts +28 -0
- package/examples/cloud-run-no-cpu-throttling.test.ts +11 -0
- package/examples/cloud-run-no-cpu-throttling.ts +6 -4
- package/examples/cloud-run-no-service.test.ts +11 -0
- package/examples/cloud-run-no-service.ts +33 -0
- package/examples/cloud-run-non-public.test.ts +11 -0
- package/examples/cloud-run-non-public.ts +5 -4
- package/examples/cloud-run-post-stop-job.test.ts +11 -0
- package/examples/cloud-run-post-stop-job.ts +42 -0
- package/examples/cloud-run-service-custom-vpc-connector.test.ts +11 -0
- package/examples/cloud-run-service-custom-vpc-connector.ts +30 -0
- package/examples/cloud-run-service-custom-vpc.test.ts +11 -0
- package/examples/cloud-run-service-custom-vpc.ts +31 -0
- package/examples/cloud-run-service-gen2.test.ts +11 -0
- package/examples/cloud-run-service-gen2.ts +29 -0
- package/examples/cloud-run-service-increase-timout.test.ts +11 -0
- package/examples/cloud-run-service-increase-timout.ts +29 -0
- package/examples/cloud-run-service-with-volumes.test.ts +11 -0
- package/examples/cloud-run-service-with-volumes.ts +56 -0
- package/examples/cloud-run-storybook.test.ts +11 -0
- package/examples/cloud-run-storybook.ts +33 -0
- package/examples/cloud-run-with-ngnix.test.ts +11 -0
- package/examples/cloud-run-with-ngnix.ts +29 -0
- package/examples/cloud-run-with-sql-reuse-db.test.ts +11 -0
- package/examples/cloud-run-with-sql-reuse-db.ts +5 -4
- package/examples/cloud-run-with-sql.test.ts +11 -0
- package/examples/cloud-run-with-sql.ts +7 -20
- package/examples/cloud-run-with-worker.test.ts +11 -0
- package/examples/cloud-run-with-worker.ts +37 -0
- package/examples/custom-build-job-with-tests.test.ts +11 -0
- package/examples/custom-build-job-with-tests.ts +14 -4
- package/examples/custom-build-job.test.ts +11 -0
- package/examples/custom-build-job.ts +5 -4
- package/examples/custom-deploy.test.ts +11 -0
- package/examples/custom-deploy.ts +15 -4
- package/examples/custom-envs.test.ts +11 -0
- package/examples/custom-envs.ts +5 -4
- package/examples/custom-sbom-java.test.ts +11 -0
- package/examples/custom-sbom-java.ts +10 -6
- package/examples/git-submodule.test.ts +11 -0
- package/examples/git-submodule.ts +30 -0
- package/examples/kubernetes-application-customization.test.ts +11 -0
- package/examples/kubernetes-application-customization.ts +7 -4
- package/examples/kubernetes-with-cloud-sql.test.ts +11 -0
- package/examples/kubernetes-with-cloud-sql.ts +7 -4
- package/examples/kubernetes-with-jobs.test.ts +11 -0
- package/examples/kubernetes-with-jobs.ts +7 -4
- package/examples/kubernetes-with-mongodb.test.ts +11 -0
- package/examples/kubernetes-with-mongodb.ts +7 -4
- package/examples/local-dot-env.test.ts +11 -0
- package/examples/local-dot-env.ts +27 -0
- package/examples/meteor-kubernetes.test.ts +11 -0
- package/examples/meteor-kubernetes.ts +64 -0
- package/examples/multiline-var.test.ts +11 -0
- package/examples/multiline-var.ts +107 -0
- package/examples/native-app.test.ts +11 -0
- package/examples/native-app.ts +86 -0
- package/examples/node-build-with-custom-image.test.ts +11 -0
- package/examples/node-build-with-custom-image.ts +26 -0
- package/examples/node-build-with-docker-additions.test.ts +11 -0
- package/examples/node-build-with-docker-additions.ts +29 -0
- package/examples/rails-k8s-with-worker-dockerfile.test.ts +33 -0
- package/examples/rails-k8s-with-worker.test.ts +11 -0
- package/examples/rails-k8s-with-worker.ts +23 -17
- package/examples/referencing-other-vars.test.ts +11 -0
- package/examples/referencing-other-vars.ts +83 -0
- package/examples/wait-for-other-deploy.test.ts +11 -0
- package/examples/wait-for-other-deploy.ts +5 -4
- package/examples/workspace-api-www-turbo-cache.test.ts +11 -0
- package/examples/workspace-api-www-turbo-cache.ts +52 -0
- package/examples/workspace-api-www.test.ts +11 -0
- package/examples/workspace-api-www.ts +46 -0
- package/package.json +77 -26
- package/scripts/generate-examples-test.ts +84 -0
- package/scripts/generate-gitlab-ci-types.ts +51 -0
- package/scripts/tsconfig.json +7 -0
- package/src/bash/BashExpression.ts +78 -0
- package/src/bash/bashEscape.ts +158 -0
- package/src/bash/bashExpressionPerPipelineType.ts +16 -0
- package/src/bash/bashYaml.ts +80 -0
- package/src/bash/getInjectVarsScript.ts +21 -0
- package/src/bash/index.ts +2 -0
- package/src/build/artifacts/createBuildJobArtifact.ts +61 -0
- package/src/build/base/__tests__/__snapshots__/createArtifactsConfig.test.ts.snap +49 -0
- package/src/build/base/__tests__/createArtifactsConfig.test.ts +41 -0
- package/src/build/base/constants.ts +2 -2
- package/src/build/base/createAppBuildJob.ts +70 -0
- package/src/build/base/createArtifactsConfig.ts +34 -0
- package/src/build/base/createBuildJobDefinition.ts +37 -0
- package/src/build/base/index.ts +64 -0
- package/src/build/base/writeBuildInfo.ts +3 -3
- package/src/build/base/writeDotEnv.ts +40 -0
- package/src/build/cache/createJobCache.ts +83 -0
- package/src/build/cache/getAllCacheConfigsFromConfig.ts +28 -0
- package/src/build/cache/transformLegacyJobCache.ts +14 -0
- package/src/build/custom/__tests__/testJob.test.ts +29 -0
- package/src/build/custom/buildJob.ts +18 -53
- package/src/build/custom/index.ts +2 -2
- package/src/build/custom/testJob.ts +40 -14
- package/src/build/docker.ts +149 -63
- package/src/build/index.ts +42 -10
- package/src/build/node/buildJob.ts +68 -69
- package/src/build/node/cache.ts +30 -35
- package/src/build/node/constants.ts +2 -3
- package/src/build/node/index.ts +8 -4
- package/src/build/node/meteor.ts +37 -47
- package/src/build/node/testJob.ts +61 -22
- package/src/build/node/yarn.ts +72 -27
- package/src/build/rails/build.ts +42 -12
- package/src/build/rails/index.ts +2 -2
- package/src/build/rails/test.ts +31 -15
- package/src/build/sbom.ts +48 -0
- package/src/build/types.ts +262 -79
- package/src/catladder-gitlab.ts +7 -56
- package/src/config/__tests__/__snapshots__/getAllEnvs.test.ts.snap +31 -0
- package/src/config/__tests__/__snapshots__/getAllEnvsInAllComponents.test.ts.snap +15 -0
- package/src/config/__tests__/getAllEnvs.test.ts +71 -0
- package/src/config/__tests__/getAllEnvsInAllComponents.test.ts +63 -0
- package/src/config/configruedEnvs.ts +6 -6
- package/src/config/readConfig.ts +15 -22
- package/src/constants.ts +5 -2
- package/src/context/createAllComponentsContext.ts +31 -0
- package/src/context/createComponentContext.ts +134 -0
- package/src/context/createWorkspaceContext.ts +56 -0
- package/src/context/getBuildInfoVariables.ts +36 -0
- package/src/context/getEnvConfig.ts +3 -3
- package/src/context/getEnvType.ts +1 -1
- package/src/context/getEnvironment.ts +9 -23
- package/src/context/getEnvironmentContext.ts +25 -29
- package/src/context/getEnvironmentVariables.ts +127 -84
- package/src/context/getLabels.ts +5 -4
- package/src/context/getReviewSlug.ts +27 -0
- package/src/context/index.ts +1 -65
- package/src/context/transformJobOnlyVars.ts +45 -0
- package/src/context/utils/envVars.ts +27 -0
- package/src/deploy/base/deploy.ts +130 -0
- package/src/deploy/base/index.ts +27 -0
- package/src/deploy/base/rollback.ts +35 -0
- package/src/deploy/base/stop.ts +40 -0
- package/src/deploy/base/types.ts +3 -0
- package/src/deploy/base/variables.ts +5 -0
- package/src/deploy/cloudRun/artifactsRegistry.ts +126 -0
- package/src/deploy/cloudRun/cleanup.ts +30 -0
- package/src/deploy/cloudRun/cloudRunRevisions.ts +65 -0
- package/src/deploy/cloudRun/createJobs/cloudRunJobs.ts +227 -0
- package/src/deploy/cloudRun/createJobs/cloudRunServices.ts +86 -0
- package/src/deploy/cloudRun/createJobs/common.ts +59 -0
- package/src/deploy/cloudRun/createJobs/constants.ts +1 -0
- package/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.ts +71 -0
- package/src/deploy/cloudRun/createJobs/getCloudRunStopScripts.ts +34 -0
- package/src/deploy/cloudRun/createJobs/index.ts +51 -0
- package/src/deploy/cloudRun/createJobs/volumes.ts +23 -0
- package/src/deploy/cloudRun/index.ts +85 -59
- package/src/deploy/cloudRun/utils/createArgsString.ts +21 -13
- package/src/deploy/cloudRun/utils/database.ts +31 -9
- package/src/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.ts +9 -11
- package/src/deploy/cloudRun/utils/getServiceName.ts +3 -0
- package/src/deploy/cloudRun/utils/jobName.ts +7 -2
- package/src/deploy/cloudRun/utils/removeFirstLinesFromCommandOutput.ts +12 -0
- package/src/deploy/cloudSql/utils.ts +13 -10
- package/src/deploy/custom/deployJob.ts +35 -25
- package/src/deploy/custom/index.ts +2 -2
- package/src/deploy/dockerTag/deployJob.ts +12 -14
- package/src/deploy/dockerTag/index.ts +8 -7
- package/src/deploy/index.ts +15 -12
- package/src/deploy/kubernetes/additionalSecretKeys.ts +3 -1
- package/src/deploy/kubernetes/cloudSql/index.ts +16 -25
- package/src/deploy/kubernetes/deployJob.ts +52 -51
- package/src/deploy/kubernetes/index.ts +43 -35
- package/src/deploy/kubernetes/kubeEnv.ts +12 -10
- package/src/deploy/kubernetes/kubeValues.ts +15 -19
- package/src/deploy/kubernetes/mongodb.ts +17 -16
- package/src/deploy/sbom.ts +32 -0
- package/src/deploy/types/base.ts +20 -0
- package/src/deploy/types/custom.ts +3 -7
- package/src/deploy/types/dockerTag.ts +2 -0
- package/src/deploy/types/googleCloudRun.ts +140 -10
- package/src/deploy/types/index.ts +2 -2
- package/src/deploy/types/kubernetes.ts +24 -37
- package/src/deploy/utils.ts +5 -5
- package/src/globalScriptFunctions/index.ts +30 -0
- package/src/index.ts +4 -1
- package/src/packageInfos.ts +14 -0
- package/src/pipeline/__tests__/__snapshots__/getPipelineStages.test.ts.snap +69 -0
- package/src/pipeline/__tests__/getPipelineStages.test.ts +63 -0
- package/src/pipeline/createAllJobs.ts +67 -33
- package/src/pipeline/createJobsForComponent.ts +11 -41
- package/src/pipeline/createJobsForWorkspace.ts +12 -0
- package/src/pipeline/createMainPipeline.ts +119 -0
- package/src/pipeline/generatePipelineFiles.ts +100 -0
- package/src/pipeline/getPipelineStages.ts +23 -0
- package/src/pipeline/gitlab/createGitlabJobs.ts +391 -98
- package/src/pipeline/gitlab/createGitlabPipeline.ts +35 -0
- package/src/pipeline/gitlab/gitlabReleaseJobs.ts +23 -0
- package/src/pipeline/gitlab/sortGitLabJobDefProps.ts +59 -0
- package/src/pipeline/index.ts +2 -1
- package/src/pipeline/packageManager.ts +50 -31
- package/src/pipeline/yarn/yarnUtils.ts +39 -10
- package/src/rules/index.ts +36 -9
- package/src/runner/index.ts +0 -1
- package/src/types/config.ts +52 -12
- package/src/types/context.ts +176 -35
- package/src/types/environmentContext.ts +18 -13
- package/src/types/gitlab-ci-yml.ts +891 -0
- package/src/types/gitlab-types.ts +54 -87
- package/src/types/index.ts +1 -0
- package/src/types/jobDefinition.ts +34 -0
- package/src/types/jobs.ts +37 -17
- package/src/types/utils.ts +4 -4
- package/src/utils/gitlab.ts +28 -1
- package/src/utils/index.ts +6 -3
- package/src/utils/jsonParse.ts +7 -0
- package/src/utils/removeUndefined.ts +4 -0
- package/src/utils/writeFiles.ts +52 -0
- package/src/variables/VariableValue.ts +6 -0
- package/src/variables/VariableValueContainingReferences.ts +89 -0
- package/src/variables/__tests__/resolveAllReferences.test.ts +110 -0
- package/src/variables/__tests__/resolveAllReferencesOnce.test.ts +64 -0
- package/src/variables/__tests__/resolveReferencesOnce.test.ts +117 -0
- package/src/variables/__tests__/variableValue.test.ts +73 -0
- package/src/variables/resolveAllReferences.ts +46 -0
- package/src/variables/resolveAllReferencesOnce.ts +44 -0
- package/src/variables/resolveReferencesOnce.ts +29 -0
- package/tsconfig.json +1 -1
- package/bin/catladder-gitlab-dev.js +0 -3
- package/bin/catladder-gitlab.js +0 -3
- package/dist/build/base/createBuildJob.d.ts +0 -7
- package/dist/bundles/catladder-gitlab/index.js +0 -33200
- package/dist/context/__tests__/resolveReferences.test.js +0 -336
- package/dist/context/resolveReferences.d.ts +0 -4
- package/dist/context/resolveReferences.js +0 -254
- package/dist/deploy/base.d.ts +0 -10
- package/dist/deploy/base.js +0 -112
- package/dist/deploy/cloudRun/deployJob.d.ts +0 -3
- package/dist/deploy/cloudRun/deployJob.js +0 -242
- package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +0 -86
- package/dist/deploy/kubernetes/processSecretsAsFiles.js +0 -31
- package/dist/pipeline/commitInfo/getBuildId.d.ts +0 -1
- package/dist/pipeline/commitInfo/getCommitInfo.d.ts +0 -2
- package/dist/pipeline/createChildPipeline.d.ts +0 -3
- package/dist/verify/reporting.d.ts +0 -3
- package/dist/verify/reporting.js +0 -48
- package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +0 -1776
- package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +0 -1776
- package/examples/__snapshots__/cloud-run-non-public.ts.snap +0 -1776
- package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +0 -3524
- package/examples/__snapshots__/cloud-run-with-sql.ts.snap +0 -3535
- package/examples/__snapshots__/custom-build-job-with-tests.ts.snap +0 -1630
- package/examples/__snapshots__/custom-build-job.ts.snap +0 -1378
- package/examples/__snapshots__/custom-deploy.ts.snap +0 -1580
- package/examples/__snapshots__/custom-envs.ts.snap +0 -1164
- package/examples/__snapshots__/custom-sbom-java.ts.snap +0 -1386
- package/examples/__snapshots__/kubernetes-application-customization.ts.snap +0 -2476
- package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.ts.snap +0 -2436
- package/examples/__snapshots__/kubernetes-with-cloud-sql.ts.snap +0 -2448
- package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +0 -4469
- package/examples/__snapshots__/kubernetes-with-mongodb.ts.snap +0 -2640
- package/examples/__snapshots__/rails-k8s-with-worker.ts.snap +0 -2143
- package/examples/__snapshots__/wait-for-other-deploy.ts.snap +0 -2018
- package/examples/kubernetes-with-cloud-sql-legacy.ts +0 -33
- package/scripts/bundle +0 -2
- package/src/build/base/createBuildJob.ts +0 -50
- package/src/context/__tests__/resolveReferences.test.ts +0 -143
- package/src/context/resolveReferences.ts +0 -70
- package/src/deploy/base.ts +0 -144
- package/src/deploy/cloudRun/deployJob.ts +0 -275
- package/src/deploy/kubernetes/processSecretsAsFiles.ts +0 -34
- package/src/pipeline/commitInfo/getBuildId.ts +0 -6
- package/src/pipeline/commitInfo/getCommitInfo.ts +0 -12
- package/src/pipeline/createChildPipeline.ts +0 -45
- package/src/verify/reporting.ts +0 -69
- /package/dist/{context/__tests__/resolveReferences.test.d.ts → build/base/__tests__/createArtifactsConfig.test.d.ts} +0 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { createJobCacheFromCacheConfigs } from "../../build/cache/createJobCache";
|
|
2
|
+
import {
|
|
3
|
+
getDockerImageVariables,
|
|
4
|
+
requiresDockerBuild,
|
|
5
|
+
} from "../../build/docker";
|
|
6
|
+
import { SBOM_BUILD_JOB_NAME } from "../../build/sbom";
|
|
7
|
+
import type { DeployJobDefinition } from "../../types";
|
|
8
|
+
import {
|
|
9
|
+
componentContextHasWorkspaceBuild,
|
|
10
|
+
type ComponentContext,
|
|
11
|
+
} from "../../types/context";
|
|
12
|
+
import type { BaseStage, CatladderJob } from "../../types/jobs";
|
|
13
|
+
import { sbomDeactivated } from "../sbom";
|
|
14
|
+
import { contextIsStoppable } from "../utils";
|
|
15
|
+
import { STOP_JOB_NAME } from "./stop";
|
|
16
|
+
|
|
17
|
+
import { DEPLOY_RUNNER_VARIABLES } from "./variables";
|
|
18
|
+
|
|
19
|
+
export const DEPLOY_JOB_NAME = "🚀 Deploy";
|
|
20
|
+
|
|
21
|
+
export const createDeployJob = (
|
|
22
|
+
context: ComponentContext,
|
|
23
|
+
jobDefinition: DeployJobDefinition,
|
|
24
|
+
): CatladderJob => {
|
|
25
|
+
const hasDocker = requiresDockerBuild(context);
|
|
26
|
+
const isStoppable = contextIsStoppable(context);
|
|
27
|
+
|
|
28
|
+
const autoStop =
|
|
29
|
+
context.environment.envType === "review"
|
|
30
|
+
? "1 week"
|
|
31
|
+
: context.environment.envType === "dev"
|
|
32
|
+
? "4 weeks"
|
|
33
|
+
: undefined;
|
|
34
|
+
|
|
35
|
+
const deployConfig = context.deploy?.config;
|
|
36
|
+
|
|
37
|
+
// if auto or manual is configured explicitly, use that
|
|
38
|
+
const whenDeployDefined =
|
|
39
|
+
deployConfig && deployConfig.when ? deployConfig.when : undefined;
|
|
40
|
+
// otherwise auto deploy if env is not prod. If its prod, deploy automatically if stage is disabled
|
|
41
|
+
const whenDeployDefault =
|
|
42
|
+
context.environment.envType !== "prod"
|
|
43
|
+
? "auto" // is not stage, auto deploy
|
|
44
|
+
: context.componentConfig.env?.stage === false
|
|
45
|
+
? "auto" // is prod, but no staging, auto deploy
|
|
46
|
+
: "manual"; // manually deploy
|
|
47
|
+
const whenDeploy = whenDeployDefined ? whenDeployDefined : whenDeployDefault;
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
name: DEPLOY_JOB_NAME,
|
|
51
|
+
script: jobDefinition.script,
|
|
52
|
+
image: jobDefinition.image,
|
|
53
|
+
cache: jobDefinition.cache
|
|
54
|
+
? createJobCacheFromCacheConfigs(context, jobDefinition.cache)
|
|
55
|
+
: undefined,
|
|
56
|
+
artifacts: jobDefinition.artifacts,
|
|
57
|
+
services: jobDefinition.services,
|
|
58
|
+
envMode: "stagePerEnv", // makes it easier to run manual tasks er env
|
|
59
|
+
|
|
60
|
+
needs: [
|
|
61
|
+
...(sbomDeactivated(context)
|
|
62
|
+
? []
|
|
63
|
+
: [{ job: SBOM_BUILD_JOB_NAME, artifacts: true }]),
|
|
64
|
+
...(deployConfig
|
|
65
|
+
? (deployConfig.waitFor?.map((c) => ({
|
|
66
|
+
componentName: c,
|
|
67
|
+
job: DEPLOY_JOB_NAME,
|
|
68
|
+
artifacts: false,
|
|
69
|
+
})) ?? [])
|
|
70
|
+
: []),
|
|
71
|
+
],
|
|
72
|
+
// we don't want to deploy when there is a broken test
|
|
73
|
+
needsStages: [
|
|
74
|
+
...(componentContextHasWorkspaceBuild(context)
|
|
75
|
+
? hasDocker // docker build is per component,
|
|
76
|
+
? [
|
|
77
|
+
// we don't need artifacts, but have to wait for the component build
|
|
78
|
+
{
|
|
79
|
+
stage: "build" as BaseStage,
|
|
80
|
+
artifacts: false,
|
|
81
|
+
},
|
|
82
|
+
]
|
|
83
|
+
: [
|
|
84
|
+
{
|
|
85
|
+
// pick build artifacts from workspace build
|
|
86
|
+
stage: "build" as BaseStage,
|
|
87
|
+
artifacts: true,
|
|
88
|
+
workspaceName: context.build.workspaceName,
|
|
89
|
+
},
|
|
90
|
+
]
|
|
91
|
+
: [
|
|
92
|
+
{
|
|
93
|
+
stage: "build" as BaseStage,
|
|
94
|
+
artifacts: hasDocker ? false : true, // we asume that no-docker deployments need build artifacts,
|
|
95
|
+
},
|
|
96
|
+
]),
|
|
97
|
+
{
|
|
98
|
+
stage: "test",
|
|
99
|
+
artifacts: false,
|
|
100
|
+
// use test from workspace build
|
|
101
|
+
workspaceName: componentContextHasWorkspaceBuild(context)
|
|
102
|
+
? context.build.workspaceName
|
|
103
|
+
: undefined,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
when: whenDeploy === "auto" ? "on_success" : "manual",
|
|
107
|
+
|
|
108
|
+
allow_failure: whenDeploy === "manual" ? true : false,
|
|
109
|
+
stage: "deploy",
|
|
110
|
+
variables: {
|
|
111
|
+
...context.environment.envVars,
|
|
112
|
+
...(hasDocker ? getDockerImageVariables(context) : {}),
|
|
113
|
+
...context.environment.jobOnlyVars.deploy.envVars,
|
|
114
|
+
|
|
115
|
+
...jobDefinition.variables,
|
|
116
|
+
},
|
|
117
|
+
runnerVariables: {
|
|
118
|
+
...DEPLOY_RUNNER_VARIABLES,
|
|
119
|
+
...(jobDefinition.runnerVariables ?? {}),
|
|
120
|
+
...(deployConfig ? (deployConfig.runnerVariables ?? {}) : {}),
|
|
121
|
+
},
|
|
122
|
+
environment: isStoppable
|
|
123
|
+
? {
|
|
124
|
+
on_stop: STOP_JOB_NAME,
|
|
125
|
+
auto_stop_in: autoStop,
|
|
126
|
+
}
|
|
127
|
+
: undefined,
|
|
128
|
+
jobTags: deployConfig ? deployConfig.jobTags : undefined,
|
|
129
|
+
};
|
|
130
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ComponentContext } from "../../types/context";
|
|
2
|
+
import type {
|
|
3
|
+
DeployJobDefinition,
|
|
4
|
+
RollbackJobDefinition,
|
|
5
|
+
StopJobDefinition,
|
|
6
|
+
} from "../../types/jobDefinition";
|
|
7
|
+
import type { CatladderJob } from "../../types/jobs";
|
|
8
|
+
import { createDeployJob } from "./deploy";
|
|
9
|
+
import { createRollbackJob } from "./rollback";
|
|
10
|
+
import { createStopJob } from "./stop";
|
|
11
|
+
|
|
12
|
+
export const createDeployementJobs = (
|
|
13
|
+
context: ComponentContext,
|
|
14
|
+
definitions: {
|
|
15
|
+
deploy: DeployJobDefinition;
|
|
16
|
+
stop?: StopJobDefinition;
|
|
17
|
+
rollback?: RollbackJobDefinition;
|
|
18
|
+
},
|
|
19
|
+
): CatladderJob[] => {
|
|
20
|
+
return [
|
|
21
|
+
createDeployJob(context, definitions.deploy),
|
|
22
|
+
...(definitions.stop ? [createStopJob(context, definitions.stop)] : []),
|
|
23
|
+
...(definitions.rollback
|
|
24
|
+
? [createRollbackJob(context, definitions.rollback)]
|
|
25
|
+
: []),
|
|
26
|
+
];
|
|
27
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ComponentContext } from "../../types/context";
|
|
2
|
+
import type { RollbackJobDefinition } from "../../types/jobDefinition";
|
|
3
|
+
import type { CatladderJob } from "../../types/jobs";
|
|
4
|
+
import { DEPLOY_RUNNER_VARIABLES } from "./variables";
|
|
5
|
+
|
|
6
|
+
export const ROLLBACK_JOB_NAME = "↩️ Rollback ⚠️";
|
|
7
|
+
|
|
8
|
+
export const createRollbackJob = (
|
|
9
|
+
context: ComponentContext,
|
|
10
|
+
jobDefinition: RollbackJobDefinition,
|
|
11
|
+
): CatladderJob => {
|
|
12
|
+
return {
|
|
13
|
+
name: ROLLBACK_JOB_NAME,
|
|
14
|
+
image: jobDefinition.image,
|
|
15
|
+
envMode: "stagePerEnv", // makes it easier to run manual tasks er env
|
|
16
|
+
needs: [], // can be executed even if the deploy job failed
|
|
17
|
+
allow_failure: true,
|
|
18
|
+
when: "manual",
|
|
19
|
+
variables: {
|
|
20
|
+
...context.environment.jobOnlyVars.deploy.envVars,
|
|
21
|
+
...jobDefinition.variables,
|
|
22
|
+
},
|
|
23
|
+
runnerVariables: {
|
|
24
|
+
...DEPLOY_RUNNER_VARIABLES,
|
|
25
|
+
GIT_STRATEGY: "none",
|
|
26
|
+
...(jobDefinition.runnerVariables ?? {}),
|
|
27
|
+
},
|
|
28
|
+
stage: "rollback",
|
|
29
|
+
environment: {
|
|
30
|
+
action: "access",
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
script: jobDefinition.script,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ComponentContext } from "../../types/context";
|
|
2
|
+
import type { StopJobDefinition } from "../../types/jobDefinition";
|
|
3
|
+
import type { CatladderJob } from "../../types/jobs";
|
|
4
|
+
|
|
5
|
+
import { DEPLOY_RUNNER_VARIABLES } from "./variables";
|
|
6
|
+
export const STOP_JOB_NAME = "🛑 Stop ⚠️";
|
|
7
|
+
|
|
8
|
+
export const createStopJob = (
|
|
9
|
+
context: ComponentContext,
|
|
10
|
+
jobDefinition: StopJobDefinition,
|
|
11
|
+
): CatladderJob => {
|
|
12
|
+
return {
|
|
13
|
+
name: STOP_JOB_NAME,
|
|
14
|
+
image: jobDefinition.image,
|
|
15
|
+
envMode: "stagePerEnv", // makes it easier to run manual tasks er env
|
|
16
|
+
needs: [], // can be executed even if the deploy job failed
|
|
17
|
+
allow_failure: true,
|
|
18
|
+
when: "manual", // stop is always manual
|
|
19
|
+
rules: [
|
|
20
|
+
{
|
|
21
|
+
if: "$CI_COMMIT_BRANCH =~ /^[0-9]+\\.([0-9]+|x)\\.x$/", // automatic on hotfix branches
|
|
22
|
+
when: "on_success",
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
variables: {
|
|
26
|
+
...context.environment.jobOnlyVars.deploy.envVars,
|
|
27
|
+
...jobDefinition.variables,
|
|
28
|
+
},
|
|
29
|
+
runnerVariables: {
|
|
30
|
+
...DEPLOY_RUNNER_VARIABLES,
|
|
31
|
+
GIT_STRATEGY: "none",
|
|
32
|
+
...jobDefinition.runnerVariables,
|
|
33
|
+
},
|
|
34
|
+
stage: "stop",
|
|
35
|
+
environment: {
|
|
36
|
+
action: "stop",
|
|
37
|
+
},
|
|
38
|
+
script: jobDefinition.script,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { StringOrBashExpression } from "../../bash/BashExpression";
|
|
2
|
+
import { joinBashExpressions } from "../../bash/BashExpression";
|
|
3
|
+
import type { ComponentContext } from "../../types/context";
|
|
4
|
+
import { allowFailureInScripts } from "../../utils/gitlab";
|
|
5
|
+
import { isOfDeployType } from "../types";
|
|
6
|
+
import { removeFirstLinesFromCommandOutput } from "./utils/removeFirstLinesFromCommandOutput";
|
|
7
|
+
|
|
8
|
+
export const getArtifactsRegistryHost = (context: ComponentContext) => {
|
|
9
|
+
if (!isOfDeployType(context.deploy?.config, "google-cloudrun")) {
|
|
10
|
+
// should not happen
|
|
11
|
+
throw new Error("deploy config is wrong");
|
|
12
|
+
}
|
|
13
|
+
return `${context.deploy.config.region}-docker.pkg.dev`;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const getArtifactsRegistryDockerUrl = (context: ComponentContext) => {
|
|
17
|
+
const deployConfig = context.deploy?.config;
|
|
18
|
+
|
|
19
|
+
if (!isOfDeployType(deployConfig, "google-cloudrun")) {
|
|
20
|
+
// should not happen
|
|
21
|
+
throw new Error("deploy config is wrong");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const fullAppName = `${context.fullConfig.customerName}-${context.fullConfig.appName}`;
|
|
25
|
+
|
|
26
|
+
return `${getArtifactsRegistryHost(context)}/${
|
|
27
|
+
deployConfig.projectId
|
|
28
|
+
}/catladder-deploy/${fullAppName}`;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* lecacyReviewImageName is only temporary. In old versions the images had no reviewslug in review apps, which makes cleanup harder. We delete all those images now, but need the path
|
|
34
|
+
*/
|
|
35
|
+
export const getArtifactsRegistryImageName = (
|
|
36
|
+
context: ComponentContext,
|
|
37
|
+
lecacyReviewImageName = false,
|
|
38
|
+
) => {
|
|
39
|
+
if (lecacyReviewImageName && context.environment.envType !== "review") {
|
|
40
|
+
throw new Error("lecacyReviewImageName is only allowed for review app");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const dockerUrl = getArtifactsRegistryDockerUrl(context);
|
|
44
|
+
const gcloudImagePath = [
|
|
45
|
+
dockerUrl,
|
|
46
|
+
context.env,
|
|
47
|
+
context.name,
|
|
48
|
+
...(context.environment.reviewSlug && !lecacyReviewImageName
|
|
49
|
+
? [context.environment.reviewSlug]
|
|
50
|
+
: []),
|
|
51
|
+
];
|
|
52
|
+
return joinBashExpressions(gcloudImagePath, "/");
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const getArtifactsRegistryBuildCacheImage = (
|
|
56
|
+
context: ComponentContext,
|
|
57
|
+
) => {
|
|
58
|
+
const dockerUrl = getArtifactsRegistryDockerUrl(context);
|
|
59
|
+
// does not include env, so that after merge, you might get more cache hits (review-->dev)
|
|
60
|
+
const gcloudImagePath = [dockerUrl, "caches", context.name];
|
|
61
|
+
return gcloudImagePath.join("/");
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const getArtifactsRegistryImage = (context: ComponentContext) =>
|
|
65
|
+
`${getArtifactsRegistryImageName(context)}:$DOCKER_IMAGE_TAG`;
|
|
66
|
+
|
|
67
|
+
const getDeleteImageCommands = (
|
|
68
|
+
fullImageName: StringOrBashExpression,
|
|
69
|
+
keepNewest = 0,
|
|
70
|
+
) => {
|
|
71
|
+
if (keepNewest === 0) {
|
|
72
|
+
// no need to list tags, we delete the whole thing
|
|
73
|
+
return [
|
|
74
|
+
`gcloud artifacts docker images delete ${fullImageName} --quiet --delete-tags`,
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
// delete unused tags
|
|
78
|
+
const listAllImagesCommand = `gcloud artifacts docker images list ${fullImageName} --sort-by=~CREATE_TIME --format="value(version)"`;
|
|
79
|
+
|
|
80
|
+
const listImagesToDeletecommand = removeFirstLinesFromCommandOutput(
|
|
81
|
+
listAllImagesCommand,
|
|
82
|
+
keepNewest,
|
|
83
|
+
);
|
|
84
|
+
const deleteImageCommand = `gcloud artifacts docker images delete ${fullImageName}@$version --quiet --delete-tags`;
|
|
85
|
+
|
|
86
|
+
const deleteImagesCommand = `${listImagesToDeletecommand} | while read -r version; do ${deleteImageCommand}; done`;
|
|
87
|
+
|
|
88
|
+
return [deleteImagesCommand];
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* commands to delete unused images.
|
|
93
|
+
*
|
|
94
|
+
* @param context
|
|
95
|
+
* @param keep how many of the newest images to keep
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
export const getDeleteUnusedImagesCommands = (
|
|
99
|
+
context: ComponentContext,
|
|
100
|
+
keep = 0,
|
|
101
|
+
) => {
|
|
102
|
+
const deployConfig = context.deploy?.config;
|
|
103
|
+
if (!isOfDeployType(deployConfig, "google-cloudrun")) {
|
|
104
|
+
// should not happen
|
|
105
|
+
throw new Error("deploy config is wrong");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const fullImageName = getArtifactsRegistryImageName(context);
|
|
109
|
+
const buildCacheImageName = getArtifactsRegistryBuildCacheImage(context);
|
|
110
|
+
|
|
111
|
+
return [
|
|
112
|
+
...getDeleteImageCommands(fullImageName, keep),
|
|
113
|
+
...getDeleteImageCommands(buildCacheImageName, 1),
|
|
114
|
+
// because a recent version of catladder had no review-slug in the image name, we have to delete those as well
|
|
115
|
+
// we can later remove this line in some months
|
|
116
|
+
|
|
117
|
+
...(context.environment.envType === "review"
|
|
118
|
+
? allowFailureInScripts(
|
|
119
|
+
getDeleteImageCommands(
|
|
120
|
+
getArtifactsRegistryImageName(context, true),
|
|
121
|
+
0,
|
|
122
|
+
),
|
|
123
|
+
)
|
|
124
|
+
: []),
|
|
125
|
+
];
|
|
126
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ComponentContext } from "../../types/context";
|
|
2
|
+
import { getDeleteUnusedImagesCommands } from "./artifactsRegistry";
|
|
3
|
+
import { getDeleteUnusedRevisionsCommands } from "./cloudRunRevisions";
|
|
4
|
+
|
|
5
|
+
export const getRemoveOldRevisionsAndImagesCommand = (
|
|
6
|
+
context: ComponentContext,
|
|
7
|
+
when: "postDeploy" | "onStop",
|
|
8
|
+
) => {
|
|
9
|
+
if (when === "onStop") {
|
|
10
|
+
// service is already deleted, so we don't need to delete old revisions, just delete all images
|
|
11
|
+
return getDeleteUnusedImagesCommands(context);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// this number only targets inactive revisions
|
|
15
|
+
const revisionsToKeep = context.environment.envType === "prod" ? 5 : 0;
|
|
16
|
+
|
|
17
|
+
// this number needs to be higher than inactive after deploy, so we add one
|
|
18
|
+
const imagesToKeep = revisionsToKeep + 1;
|
|
19
|
+
|
|
20
|
+
const deleteOldRevisionsCommands = getDeleteUnusedRevisionsCommands(
|
|
21
|
+
context,
|
|
22
|
+
revisionsToKeep,
|
|
23
|
+
);
|
|
24
|
+
const deleteOldImagesCommands = getDeleteUnusedImagesCommands(
|
|
25
|
+
context,
|
|
26
|
+
imagesToKeep,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return [...deleteOldRevisionsCommands, ...deleteOldImagesCommands];
|
|
30
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { ComponentContext } from "../../types/context";
|
|
2
|
+
import { isOfDeployType } from "../types";
|
|
3
|
+
import { createArgsString } from "./utils/createArgsString";
|
|
4
|
+
import { getServiceName } from "./utils/getServiceName";
|
|
5
|
+
import { removeFirstLinesFromCommandOutput } from "./utils/removeFirstLinesFromCommandOutput";
|
|
6
|
+
|
|
7
|
+
const getListRevisionsCommand = (
|
|
8
|
+
context: ComponentContext,
|
|
9
|
+
args: {
|
|
10
|
+
filter?: string;
|
|
11
|
+
format: string;
|
|
12
|
+
},
|
|
13
|
+
) => {
|
|
14
|
+
const serviceName = getServiceName(context);
|
|
15
|
+
|
|
16
|
+
const deployConfig = context.deploy?.config;
|
|
17
|
+
|
|
18
|
+
if (!deployConfig || !isOfDeployType(deployConfig, "google-cloudrun")) {
|
|
19
|
+
// should not happen
|
|
20
|
+
throw new Error("deploy config is wrong");
|
|
21
|
+
}
|
|
22
|
+
const filterRevisionArgs = {
|
|
23
|
+
project: deployConfig.projectId,
|
|
24
|
+
region: deployConfig.region,
|
|
25
|
+
// only show inactive revisions
|
|
26
|
+
service: serviceName,
|
|
27
|
+
|
|
28
|
+
limit: "unlimited", // is actualy the default
|
|
29
|
+
"sort-by": "metadata.creationTimestamp",
|
|
30
|
+
...args,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// this prints out all inactive images of the given app
|
|
34
|
+
return `gcloud run revisions list ${createArgsString(filterRevisionArgs)}`;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const getDeleteUnusedRevisionsCommands = (
|
|
38
|
+
context: ComponentContext,
|
|
39
|
+
keep: number,
|
|
40
|
+
) => {
|
|
41
|
+
const deployConfig = context.deploy?.config;
|
|
42
|
+
if (!isOfDeployType(deployConfig, "google-cloudrun")) {
|
|
43
|
+
// should not happen
|
|
44
|
+
throw new Error("deploy config is wrong");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// this prints out all inactive images of the given app
|
|
48
|
+
const listAllInactiveRevisionsCmd = getListRevisionsCommand(context, {
|
|
49
|
+
format: `"value(name)"`,
|
|
50
|
+
filter: `'(status.conditions.status=False OR status.conditions.status=Unknown)'`,
|
|
51
|
+
});
|
|
52
|
+
// this removes the newest `revisionsToKeep` images
|
|
53
|
+
const listRevisionsToDeleteCmd = removeFirstLinesFromCommandOutput(
|
|
54
|
+
listAllInactiveRevisionsCmd,
|
|
55
|
+
keep,
|
|
56
|
+
);
|
|
57
|
+
const deleteRevisionCmd = `gcloud run revisions delete ${createArgsString({
|
|
58
|
+
project: deployConfig.projectId,
|
|
59
|
+
region: deployConfig.region,
|
|
60
|
+
quiet: true,
|
|
61
|
+
})} $revisionname `;
|
|
62
|
+
|
|
63
|
+
const deleteRevisionsCmd = `${listRevisionsToDeleteCmd} | while read -r revisionname; do ${deleteRevisionCmd}; done`;
|
|
64
|
+
return [deleteRevisionsCmd];
|
|
65
|
+
};
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import type { ComponentContext } from "../../../types/context";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
DeployConfigCloudRunJob,
|
|
5
|
+
DeployConfigCloudRunJobWithSchedule,
|
|
6
|
+
} from "../../types/googleCloudRun";
|
|
7
|
+
import { createArgsString } from "../utils/createArgsString";
|
|
8
|
+
import { getCloudRunJobName } from "../utils/jobName";
|
|
9
|
+
import {
|
|
10
|
+
gcloudRunCmd,
|
|
11
|
+
gcloudSchedulerCmd,
|
|
12
|
+
getCloudRunDeployConfig,
|
|
13
|
+
getCommonCloudRunArgs,
|
|
14
|
+
getCommonDeployArgs,
|
|
15
|
+
makeLabelString,
|
|
16
|
+
} from "./common";
|
|
17
|
+
import { getLabels } from "../../../context/getLabels";
|
|
18
|
+
import { createVolumeConfig } from "./volumes";
|
|
19
|
+
import type {
|
|
20
|
+
BashExpression,
|
|
21
|
+
StringOrBashExpression,
|
|
22
|
+
} from "../../../bash/BashExpression";
|
|
23
|
+
import { ENV_VARS_FILENAME } from "./constants";
|
|
24
|
+
import { notNil } from "../../../utils";
|
|
25
|
+
|
|
26
|
+
const getJobRunScriptForJob = (
|
|
27
|
+
context: ComponentContext,
|
|
28
|
+
jobName: StringOrBashExpression,
|
|
29
|
+
wait: boolean,
|
|
30
|
+
) => {
|
|
31
|
+
const commonArgs = getCommonCloudRunArgs(context);
|
|
32
|
+
|
|
33
|
+
const commonArgsString = createArgsString(commonArgs);
|
|
34
|
+
return `${gcloudRunCmd()} jobs execute ${jobName.toString()} ${commonArgsString}${
|
|
35
|
+
wait ? " --wait" : ""
|
|
36
|
+
}`;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const getDeleteSchedulesScripts = (context: ComponentContext) => {
|
|
40
|
+
const deployConfig = getCloudRunDeployConfig(context);
|
|
41
|
+
const jobsWithSchedule = getCloudRunJobsWithSchedule(context);
|
|
42
|
+
const argsString = createArgsString({
|
|
43
|
+
project: deployConfig.projectId,
|
|
44
|
+
location: deployConfig.region,
|
|
45
|
+
});
|
|
46
|
+
return jobsWithSchedule
|
|
47
|
+
.map(({ schedulerName }) => {
|
|
48
|
+
return [
|
|
49
|
+
`${gcloudSchedulerCmd()} jobs delete ${schedulerName} ${argsString}`,
|
|
50
|
+
];
|
|
51
|
+
})
|
|
52
|
+
.flat();
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const getDeleteJobsScripts = (context: ComponentContext) => {
|
|
56
|
+
const commonArgs = getCommonCloudRunArgs(context);
|
|
57
|
+
const commonArgsString = createArgsString(commonArgs);
|
|
58
|
+
const jobsWithNames = getCloudRunJobsWithNames(context);
|
|
59
|
+
|
|
60
|
+
return jobsWithNames.flatMap(({ jobName }) => [
|
|
61
|
+
// first delete all job executions. Otherwise delete might fail if one of those is still running
|
|
62
|
+
`${gcloudRunCmd()} jobs executions list ${commonArgsString} --job ${jobName} --format="value(name)" | xargs -I {} ${gcloudRunCmd()} jobs executions delete {} --quiet ${commonArgsString}`,
|
|
63
|
+
`${gcloudRunCmd()} jobs delete ${jobName} ${commonArgsString}`,
|
|
64
|
+
]);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const getJobRunScripts = (
|
|
68
|
+
context: ComponentContext,
|
|
69
|
+
when: DeployConfigCloudRunJob["when"],
|
|
70
|
+
) => {
|
|
71
|
+
const jobsWithNames = getCloudRunJobsWithNames(context);
|
|
72
|
+
return jobsWithNames
|
|
73
|
+
.filter(({ job }) => job.when === when)
|
|
74
|
+
.map(({ jobName }) =>
|
|
75
|
+
getJobRunScriptForJob(
|
|
76
|
+
context,
|
|
77
|
+
jobName,
|
|
78
|
+
// wait for completin on stop jobs, since stop will delete the jobs afterwards, so they will fail
|
|
79
|
+
["preStop", "postStop"].includes(when),
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const getJobCreateScripts = (context: ComponentContext): string[] =>
|
|
85
|
+
getCloudRunJobsWithNames(context).map(
|
|
86
|
+
(
|
|
87
|
+
{
|
|
88
|
+
job: {
|
|
89
|
+
command,
|
|
90
|
+
image,
|
|
91
|
+
cpu,
|
|
92
|
+
memory = "512Mi",
|
|
93
|
+
timeout = "10m",
|
|
94
|
+
parallelism = 1,
|
|
95
|
+
volumes,
|
|
96
|
+
},
|
|
97
|
+
jobName,
|
|
98
|
+
},
|
|
99
|
+
jobIndex,
|
|
100
|
+
): string => {
|
|
101
|
+
const commandArray = Array.isArray(command)
|
|
102
|
+
? command
|
|
103
|
+
: command.split(" ");
|
|
104
|
+
|
|
105
|
+
const {
|
|
106
|
+
image: commonImage,
|
|
107
|
+
project,
|
|
108
|
+
region,
|
|
109
|
+
...deployArgs
|
|
110
|
+
} = getCommonDeployArgs(context);
|
|
111
|
+
const commonDeployArgsString = createArgsString(
|
|
112
|
+
{
|
|
113
|
+
command: `"${commandArray.join(",")}"`,
|
|
114
|
+
labels: `"${makeLabelString(getLabels(context))},cloud-run-job-name=$current_job_name"`,
|
|
115
|
+
image: `"${image ?? commonImage}"`,
|
|
116
|
+
project,
|
|
117
|
+
region,
|
|
118
|
+
cpu,
|
|
119
|
+
memory,
|
|
120
|
+
parallelism,
|
|
121
|
+
"task-timeout": timeout,
|
|
122
|
+
"env-vars-file": ENV_VARS_FILENAME,
|
|
123
|
+
"max-retries": 0,
|
|
124
|
+
...deployArgs,
|
|
125
|
+
},
|
|
126
|
+
...createVolumeConfig(volumes, "job"),
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
return [
|
|
130
|
+
jobIndex === 0
|
|
131
|
+
? `exist_job_names="$(\n ${gcloudRunCmd()} jobs list --filter='metadata.name ~ ${context.env}.*${context.name}' --format='value(name)' --limit=999 --project='${project}' --region='${region}'\n)"`
|
|
132
|
+
: null,
|
|
133
|
+
`current_job_name="${jobName}"`,
|
|
134
|
+
'if grep "$current_job_name" <<<"$exist_job_names" >/dev/null; then',
|
|
135
|
+
` ${gcloudRunCmd()} jobs update "$current_job_name" ${commonDeployArgsString}`,
|
|
136
|
+
"else",
|
|
137
|
+
` ${gcloudRunCmd()} jobs create "$current_job_name" ${commonDeployArgsString}`,
|
|
138
|
+
"fi",
|
|
139
|
+
]
|
|
140
|
+
.filter(notNil)
|
|
141
|
+
.join("\n");
|
|
142
|
+
},
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
export const getCreateScheduleScripts = (
|
|
146
|
+
context: ComponentContext,
|
|
147
|
+
): string[] => {
|
|
148
|
+
const jobsWithSchedule = getCloudRunJobsWithSchedule(context);
|
|
149
|
+
const { region: location, projectId: project } =
|
|
150
|
+
getCloudRunDeployConfig(context);
|
|
151
|
+
|
|
152
|
+
const uriBase = `https://${location}-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${project}/jobs`;
|
|
153
|
+
const gcloudArgs = {
|
|
154
|
+
project,
|
|
155
|
+
location,
|
|
156
|
+
uri: `"$current_job_uri"`,
|
|
157
|
+
"http-method": "POST",
|
|
158
|
+
"oauth-service-account-email": `"$GCLOUD_PROJECT_NUMBER-compute@developer.gserviceaccount.com"`,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
return jobsWithSchedule.map(
|
|
162
|
+
(
|
|
163
|
+
{ job: { maxRetryAttempts, schedule }, jobName, schedulerName },
|
|
164
|
+
jobIndex,
|
|
165
|
+
): string => {
|
|
166
|
+
const argsString = createArgsString({
|
|
167
|
+
...gcloudArgs,
|
|
168
|
+
schedule: `"${schedule}"`,
|
|
169
|
+
"max-retry-attempts": maxRetryAttempts ?? 0,
|
|
170
|
+
});
|
|
171
|
+
return [
|
|
172
|
+
jobIndex === 0
|
|
173
|
+
? `exist_scheduler_names="$(\n ${gcloudSchedulerCmd()} jobs list --filter='httpTarget.uri ~ ${context.env}.*${context.name}' --format='value(name)' --limit=999 --location='${location}' --project='${project}'\n)"`
|
|
174
|
+
: null,
|
|
175
|
+
`current_job_uri="${uriBase}/${jobName}:run"`,
|
|
176
|
+
`current_scheduler_name="${schedulerName}"`,
|
|
177
|
+
`if grep "$current_scheduler_name" <<<"$exist_scheduler_names" >/dev/null; then`,
|
|
178
|
+
` ${gcloudSchedulerCmd()} jobs update http "$current_scheduler_name" ${argsString}`,
|
|
179
|
+
`else`,
|
|
180
|
+
` ${gcloudSchedulerCmd()} jobs create http "$current_scheduler_name" ${argsString}`,
|
|
181
|
+
`fi`,
|
|
182
|
+
]
|
|
183
|
+
.filter(notNil)
|
|
184
|
+
.join("\n");
|
|
185
|
+
},
|
|
186
|
+
);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const getCloudRunJobsWithSchedule = (context: ComponentContext) => {
|
|
190
|
+
const jobsWithNames = getCloudRunJobsWithNames(context);
|
|
191
|
+
|
|
192
|
+
return jobsWithNames
|
|
193
|
+
.filter(
|
|
194
|
+
(
|
|
195
|
+
entry,
|
|
196
|
+
): entry is {
|
|
197
|
+
jobName: BashExpression;
|
|
198
|
+
job: DeployConfigCloudRunJobWithSchedule;
|
|
199
|
+
jobKey: string;
|
|
200
|
+
} => entry.job.when === "schedule",
|
|
201
|
+
)
|
|
202
|
+
.map(({ job, jobName, jobKey }) => ({
|
|
203
|
+
job,
|
|
204
|
+
jobName,
|
|
205
|
+
jobKey,
|
|
206
|
+
schedulerName: jobName.concat("-scheduler"),
|
|
207
|
+
}));
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const getCloudRunJobsWithNames = (context: ComponentContext) => {
|
|
211
|
+
const deployConfig = getCloudRunDeployConfig(context);
|
|
212
|
+
|
|
213
|
+
const getFullJobName = (name: string) =>
|
|
214
|
+
getCloudRunJobName(context.environment.fullName, name);
|
|
215
|
+
|
|
216
|
+
const jobsWithNames = Object.entries(deployConfig.jobs ?? {})
|
|
217
|
+
// filter out disabled jobs
|
|
218
|
+
.filter((entry): entry is [string, DeployConfigCloudRunJob] =>
|
|
219
|
+
Boolean(entry[1]),
|
|
220
|
+
)
|
|
221
|
+
.map(([jobKey, job]) => ({
|
|
222
|
+
jobName: getFullJobName(jobKey),
|
|
223
|
+
job,
|
|
224
|
+
jobKey,
|
|
225
|
+
}));
|
|
226
|
+
return jobsWithNames;
|
|
227
|
+
};
|