@catladder/pipeline 0.0.0-refactor-cloud-run-825d7e86 → 0.0.0-refactor-docker-9fda97e9
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/bash/BashExpression.d.ts +40 -0
- package/dist/bash/BashExpression.js +124 -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 +46 -0
- package/dist/bash/getInjectVarsScript.d.ts +2 -0
- package/dist/bash/getInjectVarsScript.js +45 -0
- package/dist/bash/replaceAsync.d.ts +2 -0
- package/dist/{pipeline/commitInfo/getCommitInfo.js → bash/replaceAsync.js} +49 -21
- package/dist/build/base/__tests__/createArtifactsConfig.test.js +3 -1
- package/dist/build/base/constants.js +3 -1
- package/dist/build/base/createAppBuildJob.d.ts +2 -1
- package/dist/build/base/createAppBuildJob.js +11 -6
- package/dist/build/base/createArtifactsConfig.d.ts +1 -1
- package/dist/build/base/createArtifactsConfig.js +3 -1
- package/dist/build/base/index.js +3 -1
- package/dist/build/base/writeBuildInfo.js +4 -3
- package/dist/build/base/writeDotEnv.js +12 -3
- package/dist/build/custom/__tests__/testJob.test.js +3 -1
- package/dist/build/custom/buildJob.js +6 -14
- package/dist/build/custom/index.js +3 -1
- package/dist/build/custom/testJob.d.ts +1 -1
- package/dist/build/custom/testJob.js +18 -14
- package/dist/build/docker.d.ts +28 -33
- package/dist/build/docker.js +39 -14
- package/dist/build/index.d.ts +1 -1
- package/dist/build/index.js +13 -7
- package/dist/build/node/buildJob.js +5 -13
- package/dist/build/node/cache.js +6 -3
- package/dist/build/node/constants.js +3 -1
- package/dist/build/node/index.js +3 -1
- package/dist/build/node/meteor.js +6 -3
- package/dist/build/node/testJob.js +18 -14
- package/dist/build/node/yarn.d.ts +3 -2
- package/dist/build/node/yarn.js +6 -3
- package/dist/build/rails/build.js +4 -2
- package/dist/build/rails/index.js +3 -1
- package/dist/build/rails/test.js +15 -11
- package/dist/build/sbom.js +3 -1
- package/dist/build/types.d.ts +57 -43
- package/dist/build/types.js +3 -1
- package/dist/bundles/catladder-gitlab/index.js +31112 -25265
- package/dist/catladder-gitlab.js +10 -54
- package/dist/config/__tests__/configruedEnvs.test.js +3 -1
- package/dist/config/configruedEnvs.js +3 -1
- package/dist/config/index.js +13 -7
- package/dist/config/readConfig.js +6 -5
- package/dist/constants.js +5 -3
- package/dist/context/__tests__/resolveReferences.test.js +40 -8
- package/dist/context/getBuildInfoVariables.d.ts +7 -0
- package/dist/context/getBuildInfoVariables.js +29 -0
- package/dist/context/getEnvConfig.js +3 -1
- package/dist/context/getEnvType.js +3 -1
- package/dist/context/getEnvironment.d.ts +3 -3
- package/dist/context/getEnvironment.js +10 -10
- package/dist/context/getEnvironmentContext.d.ts +7 -3
- package/dist/context/getEnvironmentContext.js +21 -11
- package/dist/context/getEnvironmentVariables.d.ts +26 -5
- package/dist/context/getEnvironmentVariables.js +41 -25
- package/dist/context/getLabels.js +4 -2
- package/dist/context/getReviewSlug.d.ts +4 -0
- package/dist/context/getReviewSlug.js +22 -0
- package/dist/context/index.d.ts +12 -3
- package/dist/context/index.js +21 -15
- package/dist/context/resolveReferences.d.ts +3 -1
- package/dist/context/resolveReferences.js +54 -22
- package/dist/context/transformJobOnlyVars.d.ts +5 -2
- package/dist/context/transformJobOnlyVars.js +4 -2
- package/dist/context/utils/envVars.d.ts +1 -1
- package/dist/context/utils/envVars.js +5 -2
- package/dist/defaults/index.js +3 -1
- package/dist/deploy/base/deploy.d.ts +1 -1
- package/dist/deploy/base/deploy.js +12 -11
- package/dist/deploy/base/index.js +3 -1
- package/dist/deploy/base/rollback.d.ts +1 -1
- package/dist/deploy/base/rollback.js +13 -9
- package/dist/deploy/base/stop.d.ts +1 -1
- package/dist/deploy/base/stop.js +16 -11
- package/dist/deploy/base/types.d.ts +1 -1
- package/dist/deploy/base/types.js +3 -1
- package/dist/deploy/base/variables.js +3 -1
- package/dist/deploy/cloudRun/artifactsRegistry.d.ts +2 -1
- package/dist/deploy/cloudRun/artifactsRegistry.js +6 -4
- package/dist/deploy/cloudRun/cleanup.js +3 -1
- package/dist/deploy/cloudRun/cloudRunRevisions.js +3 -1
- package/dist/deploy/cloudRun/createJobs/cloudRunJobs.js +20 -11
- package/dist/deploy/cloudRun/createJobs/cloudRunServices.d.ts +2 -2
- package/dist/deploy/cloudRun/createJobs/cloudRunServices.js +47 -8
- package/dist/deploy/cloudRun/createJobs/common.d.ts +3 -0
- package/dist/deploy/cloudRun/createJobs/common.js +17 -3
- 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.js +9 -2
- package/dist/deploy/cloudRun/createJobs/getCloudRunStopScripts.js +3 -1
- package/dist/deploy/cloudRun/createJobs/index.js +25 -8
- package/dist/deploy/cloudRun/createJobs/volumes.d.ts +3 -0
- package/dist/deploy/cloudRun/createJobs/volumes.js +58 -0
- package/dist/deploy/cloudRun/index.js +13 -7
- 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 +4 -2
- package/dist/deploy/cloudRun/utils/database.js +28 -15
- package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.js +3 -1
- package/dist/deploy/cloudRun/utils/getServiceName.d.ts +1 -1
- package/dist/deploy/cloudRun/utils/getServiceName.js +3 -1
- 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.js +3 -1
- package/dist/deploy/cloudSql/utils.d.ts +2 -1
- package/dist/deploy/cloudSql/utils.js +7 -2
- package/dist/deploy/custom/deployJob.js +3 -1
- package/dist/deploy/custom/index.js +3 -1
- package/dist/deploy/dockerTag/deployJob.js +3 -1
- package/dist/deploy/dockerTag/index.js +3 -1
- package/dist/deploy/index.d.ts +4 -3
- package/dist/deploy/index.js +13 -7
- package/dist/deploy/kubernetes/additionalSecretKeys.js +3 -1
- package/dist/deploy/kubernetes/cloudSql/index.d.ts +3 -2
- package/dist/deploy/kubernetes/cloudSql/index.js +6 -4
- package/dist/deploy/kubernetes/deployJob.js +22 -15
- package/dist/deploy/kubernetes/index.js +51 -14
- package/dist/deploy/kubernetes/kubeEnv.d.ts +3 -2
- package/dist/deploy/kubernetes/kubeEnv.js +7 -4
- package/dist/deploy/kubernetes/kubeValues.d.ts +2 -2
- package/dist/deploy/kubernetes/kubeValues.js +3 -2
- package/dist/deploy/kubernetes/mongodb.js +3 -1
- package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +2 -1
- package/dist/deploy/kubernetes/processSecretsAsFiles.js +3 -1
- package/dist/deploy/sbom.js +3 -1
- package/dist/deploy/types/base.d.ts +8 -2
- package/dist/deploy/types/base.js +3 -1
- package/dist/deploy/types/custom.d.ts +1 -1
- package/dist/deploy/types/custom.js +3 -1
- package/dist/deploy/types/dockerTag.d.ts +1 -1
- package/dist/deploy/types/dockerTag.js +3 -1
- package/dist/deploy/types/googleCloudRun.d.ts +74 -17
- package/dist/deploy/types/googleCloudRun.js +3 -1
- package/dist/deploy/types/index.d.ts +6 -6
- package/dist/deploy/types/index.js +13 -7
- package/dist/deploy/types/kubernetes.d.ts +22 -22
- package/dist/deploy/types/kubernetes.js +3 -1
- package/dist/deploy/utils.js +3 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +16 -9
- package/dist/packageInfos.d.ts +2 -0
- package/dist/packageInfos.js +14 -0
- package/dist/pipeline/createAllJobs.d.ts +13 -5
- package/dist/pipeline/createAllJobs.js +21 -10
- package/dist/pipeline/createChildPipeline.d.ts +1 -1
- package/dist/pipeline/createChildPipeline.js +30 -63
- package/dist/pipeline/createJobsForComponent.d.ts +3 -3
- package/dist/pipeline/createJobsForComponent.js +19 -18
- package/dist/pipeline/createMainPipeline.d.ts +3 -0
- package/dist/pipeline/createMainPipeline.js +248 -0
- package/dist/pipeline/generatePipelineFiles.d.ts +2 -0
- package/dist/pipeline/generatePipelineFiles.js +178 -0
- package/dist/pipeline/getPipelineStages.d.ts +8 -0
- package/dist/pipeline/getPipelineStages.js +55 -0
- package/dist/pipeline/gitlab/createGitlabJobs.d.ts +15 -6
- package/dist/pipeline/gitlab/createGitlabJobs.js +98 -25
- package/dist/pipeline/gitlab/createGitlabPipeline.d.ts +8 -0
- package/dist/pipeline/gitlab/createGitlabPipeline.js +38 -0
- package/dist/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.d.ts +1 -0
- package/dist/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.js +29 -0
- package/dist/pipeline/gitlab/gitlabReleaseJobs.d.ts +33 -0
- package/dist/pipeline/gitlab/gitlabReleaseJobs.js +24 -0
- package/dist/pipeline/index.d.ts +3 -1
- package/dist/pipeline/index.js +16 -8
- package/dist/pipeline/packageManager.js +4 -2
- package/dist/pipeline/yarn/yarnUtils.js +6 -4
- 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 +31 -18
- package/dist/types/config.js +5 -2
- package/dist/types/context.d.ts +37 -32
- package/dist/types/context.js +3 -1
- package/dist/types/environmentContext.d.ts +11 -7
- package/dist/types/environmentContext.js +3 -1
- package/dist/types/gitlab-ci-yml.d.ts +30 -30
- package/dist/types/gitlab-ci-yml.js +3 -2
- package/dist/types/gitlab-types.d.ts +4 -6
- package/dist/types/gitlab-types.js +3 -1
- package/dist/types/index.js +13 -7
- package/dist/types/jobs.d.ts +23 -6
- package/dist/types/jobs.js +3 -1
- package/dist/types/pipeline.d.ts +4 -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.js +3 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/writeFiles.d.ts +7 -0
- package/dist/{pipeline/commitInfo/getBuildId.js → utils/writeFiles.js} +39 -22
- package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +495 -363
- package/examples/__snapshots__/cloud-run-meteor-with-worker.ts.snap +474 -342
- package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +492 -360
- package/examples/__snapshots__/cloud-run-no-service.ts.snap +2023 -0
- package/examples/__snapshots__/cloud-run-non-public.ts.snap +492 -360
- package/examples/__snapshots__/cloud-run-post-stop-job.ts.snap +501 -368
- package/examples/__snapshots__/cloud-run-service-gen2.ts.snap +1971 -0
- package/examples/__snapshots__/cloud-run-service-with-volumes.ts.snap +2015 -0
- package/examples/__snapshots__/cloud-run-with-ngnix.ts.snap +1971 -0
- package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +1167 -867
- package/examples/__snapshots__/cloud-run-with-sql.ts.snap +1155 -867
- package/examples/__snapshots__/cloud-run-with-worker.ts.snap +494 -362
- package/examples/__snapshots__/custom-build-job-with-tests.ts.snap +464 -332
- package/examples/__snapshots__/custom-build-job.ts.snap +446 -326
- package/examples/__snapshots__/custom-deploy.ts.snap +331 -223
- package/examples/__snapshots__/custom-envs.ts.snap +135 -81
- package/examples/__snapshots__/custom-sbom-java.ts.snap +446 -326
- package/examples/__snapshots__/kubernetes-application-customization.ts.snap +858 -969
- package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.ts.snap +898 -957
- package/examples/__snapshots__/kubernetes-with-cloud-sql.ts.snap +906 -969
- package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +1638 -1728
- package/examples/__snapshots__/kubernetes-with-mongodb.ts.snap +986 -1137
- package/examples/__snapshots__/local-dot-env.ts.snap +1971 -0
- package/examples/__snapshots__/meteor-kubernetes.ts.snap +918 -1069
- package/examples/__snapshots__/multiline-var.ts.snap +4500 -0
- package/examples/__snapshots__/native-app.ts.snap +718 -554
- package/examples/__snapshots__/node-build-with-custom-image.ts.snap +492 -360
- package/examples/__snapshots__/node-build-with-docker-additions.ts.snap +500 -360
- package/examples/__snapshots__/rails-k8s-with-worker.ts.snap +1689 -1947
- package/examples/__snapshots__/wait-for-other-deploy.ts.snap +299 -231
- package/examples/cloud-run-memory-limit.ts +4 -1
- package/examples/cloud-run-no-service.ts +32 -0
- package/examples/cloud-run-service-gen2.ts +27 -0
- package/examples/cloud-run-service-with-volumes.ts +54 -0
- package/examples/cloud-run-with-ngnix.ts +24 -0
- package/examples/custom-deploy.ts +7 -7
- package/examples/local-dot-env.ts +25 -0
- package/examples/multiline-var.ts +64 -0
- package/package.json +5 -7
- package/src/bash/BashExpression.ts +81 -0
- package/src/bash/bashExpressionPerPipelineType.ts +16 -0
- package/src/bash/bashYaml.ts +46 -0
- package/src/bash/getInjectVarsScript.ts +12 -0
- package/src/bash/replaceAsync.ts +50 -0
- package/src/build/base/createAppBuildJob.ts +11 -5
- package/src/build/base/index.ts +1 -1
- package/src/build/base/writeBuildInfo.ts +1 -1
- package/src/build/base/writeDotEnv.ts +6 -1
- package/src/build/custom/buildJob.ts +4 -9
- package/src/build/custom/testJob.ts +3 -2
- package/src/build/docker.ts +62 -17
- package/src/build/node/buildJob.ts +5 -9
- package/src/build/node/meteor.ts +3 -3
- package/src/build/node/testJob.ts +3 -2
- package/src/build/node/yarn.ts +9 -4
- package/src/build/rails/build.ts +1 -0
- package/src/build/rails/test.ts +2 -1
- package/src/build/types.ts +61 -39
- package/src/catladder-gitlab.ts +8 -55
- package/src/config/readConfig.ts +2 -3
- package/src/constants.ts +5 -2
- package/src/context/__tests__/resolveReferences.test.ts +11 -6
- package/src/context/getBuildInfoVariables.ts +40 -0
- package/src/context/getEnvironment.ts +7 -23
- package/src/context/getEnvironmentContext.ts +25 -29
- package/src/context/getEnvironmentVariables.ts +61 -36
- package/src/context/getReviewSlug.ts +27 -0
- package/src/context/index.ts +24 -23
- package/src/context/resolveReferences.ts +29 -9
- package/src/context/transformJobOnlyVars.ts +5 -2
- package/src/context/utils/envVars.ts +2 -1
- package/src/deploy/base/deploy.ts +20 -18
- package/src/deploy/base/rollback.ts +8 -10
- package/src/deploy/base/stop.ts +8 -9
- package/src/deploy/cloudRun/artifactsRegistry.ts +9 -4
- package/src/deploy/cloudRun/createJobs/cloudRunJobs.ts +35 -15
- package/src/deploy/cloudRun/createJobs/cloudRunServices.ts +35 -20
- package/src/deploy/cloudRun/createJobs/common.ts +14 -1
- package/src/deploy/cloudRun/createJobs/constants.ts +1 -0
- package/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.ts +20 -2
- package/src/deploy/cloudRun/createJobs/index.ts +17 -8
- package/src/deploy/cloudRun/createJobs/volumes.ts +23 -0
- package/src/deploy/cloudRun/index.ts +28 -8
- package/src/deploy/cloudRun/utils/createArgsString.ts +21 -13
- package/src/deploy/cloudRun/utils/database.ts +25 -3
- package/src/deploy/cloudRun/utils/jobName.ts +7 -2
- package/src/deploy/cloudSql/utils.ts +12 -9
- package/src/deploy/index.ts +2 -1
- package/src/deploy/kubernetes/cloudSql/index.ts +3 -2
- package/src/deploy/kubernetes/deployJob.ts +24 -10
- package/src/deploy/kubernetes/index.ts +15 -8
- package/src/deploy/kubernetes/kubeEnv.ts +8 -6
- package/src/deploy/kubernetes/kubeValues.ts +0 -1
- package/src/deploy/kubernetes/processSecretsAsFiles.ts +2 -1
- package/src/deploy/types/base.ts +6 -0
- package/src/deploy/types/googleCloudRun.ts +73 -4
- package/src/index.ts +2 -1
- package/src/packageInfos.ts +10 -0
- package/src/pipeline/createAllJobs.ts +24 -10
- package/src/pipeline/createChildPipeline.ts +19 -30
- package/src/pipeline/createJobsForComponent.ts +14 -22
- package/src/pipeline/createMainPipeline.ts +88 -0
- package/src/pipeline/generatePipelineFiles.ts +29 -0
- package/src/pipeline/getPipelineStages.ts +22 -0
- package/src/pipeline/gitlab/createGitlabJobs.ts +174 -51
- package/src/pipeline/gitlab/createGitlabPipeline.ts +24 -0
- package/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.ts +46 -0
- package/src/pipeline/gitlab/gitlabReleaseJobs.ts +20 -0
- package/src/pipeline/index.ts +2 -0
- package/src/rules/index.ts +36 -9
- package/src/types/config.ts +24 -4
- package/src/types/context.ts +39 -26
- package/src/types/environmentContext.ts +12 -6
- package/src/types/gitlab-ci-yml.ts +0 -1
- package/src/types/gitlab-types.ts +5 -4
- package/src/types/jobs.ts +28 -3
- package/src/types/pipeline.ts +4 -0
- package/src/utils/writeFiles.ts +40 -0
- package/dist/deploy/cloudRun/createJobs/variables.d.ts +0 -5
- package/dist/deploy/cloudRun/createJobs/variables.js +0 -19
- package/dist/pipeline/commitInfo/getBuildId.d.ts +0 -6
- package/dist/pipeline/commitInfo/getCommitInfo.d.ts +0 -2
- package/src/deploy/cloudRun/createJobs/variables.ts +0 -21
- package/src/pipeline/commitInfo/getBuildId.ts +0 -17
- package/src/pipeline/commitInfo/getCommitInfo.ts +0 -15
package/src/build/docker.ts
CHANGED
|
@@ -12,8 +12,9 @@ import {
|
|
|
12
12
|
getArtifactsRegistryImageName,
|
|
13
13
|
} from "../deploy/cloudRun/artifactsRegistry";
|
|
14
14
|
import { gcloudServiceAccountLoginCommands } from "../deploy/cloudRun/utils/gcloudServiceAccountLoginCommands";
|
|
15
|
+
import type { BuildConfig, BuildConfigDocker } from ".";
|
|
15
16
|
|
|
16
|
-
const
|
|
17
|
+
const DOCKER_BUILD_RUNNER_REQUESTS = {
|
|
17
18
|
KUBERNETES_CPU_REQUEST: "0.5",
|
|
18
19
|
KUBERNETES_MEMORY_REQUEST: "1Gi",
|
|
19
20
|
KUBERNETES_MEMORY_LIMIT: "2Gi",
|
|
@@ -52,24 +53,34 @@ export const requiresDockerBuild = ({
|
|
|
52
53
|
isOfDeployType(deploy, "kubernetes", "google-cloudrun", "dockerTag") ||
|
|
53
54
|
(isOfDeployType(deploy, "custom") && deploy.requiresDocker);
|
|
54
55
|
|
|
55
|
-
|
|
56
|
+
// those need to be runner variables
|
|
57
|
+
const getDockerBuildRunnerVariables = () => ({
|
|
56
58
|
DOCKER_HOST: "tcp://0.0.0.0:2375",
|
|
57
59
|
DOCKER_TLS_CERTDIR: "",
|
|
58
60
|
DOCKER_DRIVER: "overlay2",
|
|
59
61
|
DOCKER_BUILDKIT: "1", // see https://docs.docker.com/develop/develop-images/build_enhancements/
|
|
60
62
|
});
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
const getDockerAdditions = (build: BuildConfig) => {
|
|
65
|
+
if (!("docker" in build)) return {};
|
|
66
|
+
if (!build.docker) return {};
|
|
67
|
+
|
|
63
68
|
return {
|
|
64
|
-
...DOCKER_RUNNER_BUILD_VARIABLES,
|
|
65
69
|
DOCKERFILE_ADDITIONS:
|
|
66
|
-
|
|
70
|
+
"additionsBegin" in build.docker
|
|
71
|
+
? build.docker.additionsBegin?.join("\n")
|
|
72
|
+
: undefined,
|
|
67
73
|
DOCKERFILE_ADDITIONS_END:
|
|
68
|
-
|
|
74
|
+
"additionsEnd" in build.docker
|
|
75
|
+
? build.docker.additionsEnd?.join("\n")
|
|
76
|
+
: undefined,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
export const getDockerBuildVariables = (context: Context) => {
|
|
80
|
+
return {
|
|
81
|
+
...getDockerAdditions(context.componentConfig.build),
|
|
69
82
|
APP_DIR: context.componentConfig.dir,
|
|
70
|
-
|
|
71
83
|
DOCKER_DIR: ".", // relative to componentdir
|
|
72
|
-
...getDockerBaseVariables(),
|
|
73
84
|
|
|
74
85
|
...getDockerImageVariables(context),
|
|
75
86
|
};
|
|
@@ -77,7 +88,12 @@ export const getDockerBuildVariables = (context: Context) => {
|
|
|
77
88
|
|
|
78
89
|
export const DOCKER_BUILD_JOB_NAME = "🔨 docker";
|
|
79
90
|
|
|
80
|
-
export const getDockerJobBaseProps = (
|
|
91
|
+
export const getDockerJobBaseProps = (
|
|
92
|
+
context: Context,
|
|
93
|
+
): Pick<
|
|
94
|
+
CatladderJob,
|
|
95
|
+
"image" | "services" | "variables" | "runnerVariables"
|
|
96
|
+
> => {
|
|
81
97
|
return {
|
|
82
98
|
image: getRunnerImage("docker-build"),
|
|
83
99
|
services: [
|
|
@@ -86,14 +102,15 @@ export const getDockerJobBaseProps = (context: Context) => {
|
|
|
86
102
|
command: ["--tls=false"],
|
|
87
103
|
},
|
|
88
104
|
],
|
|
89
|
-
variables:
|
|
105
|
+
variables: {},
|
|
106
|
+
runnerVariables: getDockerBuildRunnerVariables(),
|
|
90
107
|
};
|
|
91
108
|
};
|
|
92
109
|
|
|
93
110
|
export type DockerBuildJobDefinition = Partial<CatladderJob>;
|
|
94
111
|
export const createDockerBuildJobBase = (
|
|
95
112
|
context: Context,
|
|
96
|
-
{ script, ...def }: Partial<CatladderJob
|
|
113
|
+
{ script, ...def }: Partial<CatladderJob>,
|
|
97
114
|
): CatladderJob => {
|
|
98
115
|
return merge(
|
|
99
116
|
{
|
|
@@ -105,8 +122,12 @@ export const createDockerBuildJobBase = (
|
|
|
105
122
|
},
|
|
106
123
|
{
|
|
107
124
|
variables: getDockerBuildVariables(context),
|
|
125
|
+
runnerVariables: {
|
|
126
|
+
...DOCKER_BUILD_RUNNER_REQUESTS,
|
|
127
|
+
...getDockerBuildRunnerVariables(),
|
|
128
|
+
},
|
|
108
129
|
},
|
|
109
|
-
def
|
|
130
|
+
def,
|
|
110
131
|
);
|
|
111
132
|
};
|
|
112
133
|
|
|
@@ -120,25 +141,49 @@ export const gitlabDockerLogin = (context: Context) =>
|
|
|
120
141
|
"docker login --username gitlab-ci-token --password $CI_JOB_TOKEN $CI_REGISTRY",
|
|
121
142
|
];
|
|
122
143
|
|
|
144
|
+
const BUILT_IN_ENSURE_DOCKERFILE_SCRIPTS = {
|
|
145
|
+
meteor: "ensureMeteorDockerfile",
|
|
146
|
+
node: "ensureNodeDockerfile",
|
|
147
|
+
nginx: "ensureNginxDockerfile",
|
|
148
|
+
custom: null,
|
|
149
|
+
} satisfies {
|
|
150
|
+
[type in BuildConfigDocker["type"]]: string | null;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export const getDockerBuildScriptWithBuiltInDockerFile = (
|
|
154
|
+
context: Context,
|
|
155
|
+
defaultType?: BuildConfigDocker["type"],
|
|
156
|
+
) => {
|
|
157
|
+
const type =
|
|
158
|
+
"docker" in context.componentConfig.build &&
|
|
159
|
+
context.componentConfig.build.docker &&
|
|
160
|
+
"type" in context.componentConfig.build.docker
|
|
161
|
+
? context.componentConfig.build.docker?.type
|
|
162
|
+
: defaultType;
|
|
163
|
+
return getDockerBuildDefaultScript(
|
|
164
|
+
context,
|
|
165
|
+
type ? BUILT_IN_ENSURE_DOCKERFILE_SCRIPTS[type] : null,
|
|
166
|
+
);
|
|
167
|
+
};
|
|
123
168
|
export const getDockerBuildDefaultScript = (
|
|
124
169
|
context: Context,
|
|
125
|
-
ensureDockerFileScript?: string
|
|
170
|
+
ensureDockerFileScript?: string | null,
|
|
126
171
|
) =>
|
|
127
172
|
[
|
|
128
|
-
ensureDockerFileScript,
|
|
173
|
+
ensureDockerFileScript ?? undefined,
|
|
129
174
|
...collapseableSection(
|
|
130
175
|
"docker-login",
|
|
131
|
-
"Docker Login"
|
|
176
|
+
"Docker Login",
|
|
132
177
|
)(gitlabDockerLogin(context)),
|
|
133
178
|
...collapseableSection(
|
|
134
179
|
"docker-build",
|
|
135
|
-
"Docker build"
|
|
180
|
+
"Docker build",
|
|
136
181
|
)([
|
|
137
182
|
"docker build --network host --cache-from $DOCKER_CACHE_IMAGE --tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG -f $APP_DIR/Dockerfile . --build-arg BUILDKIT_INLINE_CACHE=1", //BUILDKIT_INLINE_CACHE, see https://testdriven.io/blog/faster-ci-builds-with-docker-cache/
|
|
138
183
|
]),
|
|
139
184
|
...collapseableSection(
|
|
140
185
|
"docker-push",
|
|
141
|
-
"Docker push and tag"
|
|
186
|
+
"Docker push and tag",
|
|
142
187
|
)([
|
|
143
188
|
"docker push $DOCKER_IMAGE:$DOCKER_IMAGE_TAG",
|
|
144
189
|
"docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG $DOCKER_CACHE_IMAGE",
|
|
@@ -4,7 +4,7 @@ import type { Context } from "../../types/context";
|
|
|
4
4
|
import type { CatladderJob } from "../../types/jobs";
|
|
5
5
|
import { ensureArray } from "../../utils";
|
|
6
6
|
import { createBuildJobs } from "../base";
|
|
7
|
-
import {
|
|
7
|
+
import { getDockerBuildScriptWithBuiltInDockerFile } from "../docker";
|
|
8
8
|
import { isOfBuildType } from "../types";
|
|
9
9
|
import { getNextCache, getNodeCache, getYarnCache } from "./cache";
|
|
10
10
|
import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
|
|
@@ -25,9 +25,7 @@ export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
|
|
|
25
25
|
buildConfig.buildCommand !== null
|
|
26
26
|
? {
|
|
27
27
|
image: buildConfig.jobImage ?? defaultImage,
|
|
28
|
-
|
|
29
|
-
...NODE_RUNNER_BUILD_VARIABLES,
|
|
30
|
-
},
|
|
28
|
+
runnerVariables: NODE_RUNNER_BUILD_VARIABLES,
|
|
31
29
|
cache: [
|
|
32
30
|
...(ensureArray(buildConfig.jobCache) ?? []),
|
|
33
31
|
...getNodeCache(context),
|
|
@@ -48,7 +46,7 @@ export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
|
|
|
48
46
|
join(dir, "dist"),
|
|
49
47
|
join(dir, ".next"),
|
|
50
48
|
...(buildConfig.artifactsPaths?.map((path) =>
|
|
51
|
-
join(dir, path)
|
|
49
|
+
join(dir, path),
|
|
52
50
|
) ?? []),
|
|
53
51
|
]),
|
|
54
52
|
expire_in: "1 day",
|
|
@@ -59,11 +57,9 @@ export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
|
|
|
59
57
|
: undefined,
|
|
60
58
|
|
|
61
59
|
dockerBuild: {
|
|
62
|
-
script:
|
|
60
|
+
script: getDockerBuildScriptWithBuiltInDockerFile(
|
|
63
61
|
context,
|
|
64
|
-
buildConfig.type === "node-static"
|
|
65
|
-
? "ensureNginxDockerfile"
|
|
66
|
-
: "ensureNodeDockerfile"
|
|
62
|
+
buildConfig.type === "node-static" ? "nginx" : "node",
|
|
67
63
|
),
|
|
68
64
|
cache: [...getYarnCache(context, "pull")],
|
|
69
65
|
variables: {
|
package/src/build/node/meteor.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { Context } from "../../types/context";
|
|
|
6
6
|
import type { CatladderJob } from "../../types/jobs";
|
|
7
7
|
|
|
8
8
|
import { createBuildJobs } from "../base";
|
|
9
|
-
import {
|
|
9
|
+
import { getDockerBuildScriptWithBuiltInDockerFile } from "../docker";
|
|
10
10
|
import { isOfBuildType } from "../types";
|
|
11
11
|
import { getNodeCache } from "./cache";
|
|
12
12
|
import { getYarnInstall } from "./yarn";
|
|
@@ -18,7 +18,7 @@ const getMeteorCache = (context: Context): GitlabJobCache[] => [
|
|
|
18
18
|
paths: [
|
|
19
19
|
join(
|
|
20
20
|
context.componentConfig.dir,
|
|
21
|
-
".meteor/local/resolver-result-cache.json"
|
|
21
|
+
".meteor/local/resolver-result-cache.json",
|
|
22
22
|
),
|
|
23
23
|
join(context.componentConfig.dir, ".meteor/local/plugin-cache"),
|
|
24
24
|
join(context.componentConfig.dir, ".meteor/local/isopacks"),
|
|
@@ -64,7 +64,7 @@ export const createMeteorBuildJobs = (context: Context): CatladderJob[] => {
|
|
|
64
64
|
}
|
|
65
65
|
: undefined,
|
|
66
66
|
dockerBuild: {
|
|
67
|
-
script:
|
|
67
|
+
script: getDockerBuildScriptWithBuiltInDockerFile(context, "meteor"),
|
|
68
68
|
variables: {
|
|
69
69
|
METEOR_INSTALL_SCRIPTS: buildConfig.installScripts ? "true" : "",
|
|
70
70
|
},
|
|
@@ -9,7 +9,8 @@ import { createArtifactsConfig } from "../base/createArtifactsConfig";
|
|
|
9
9
|
|
|
10
10
|
export const createNodeTestJobs = (context: Context): CatladderJob[] => {
|
|
11
11
|
// don't run tests after release
|
|
12
|
-
|
|
12
|
+
// TODO: this will be replaced by using rules
|
|
13
|
+
if (context.trigger === "taggedRelease") {
|
|
13
14
|
return [];
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -18,10 +19,10 @@ export const createNodeTestJobs = (context: Context): CatladderJob[] => {
|
|
|
18
19
|
const base: Omit<CatladderJob, "script" | "name"> = {
|
|
19
20
|
variables: {
|
|
20
21
|
APP_PATH: context.componentConfig.dir,
|
|
21
|
-
...NODE_RUNNER_BUILD_VARIABLES,
|
|
22
22
|
...context.environment.jobOnlyVars.build.envVars,
|
|
23
23
|
...(buildConfig.extraVars ?? {}),
|
|
24
24
|
},
|
|
25
|
+
runnerVariables: NODE_RUNNER_BUILD_VARIABLES,
|
|
25
26
|
stage: "test",
|
|
26
27
|
needs: [],
|
|
27
28
|
envMode: "none",
|
package/src/build/node/yarn.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BashExpression } from "../../bash/BashExpression";
|
|
1
2
|
import type { Context } from "../../types";
|
|
2
3
|
import { ensureArray } from "../../utils";
|
|
3
4
|
import { collapseableSection } from "../../utils/gitlab";
|
|
@@ -53,11 +54,13 @@ const DOCKER_COPY_FILES = `COPY --chown=node:node $APP_DIR .`;
|
|
|
53
54
|
|
|
54
55
|
export const getDockerAppCopyAndBuildScript = (context: Context) => {
|
|
55
56
|
if (context.packageManagerInfo?.isClassic) {
|
|
56
|
-
return
|
|
57
|
+
return new BashExpression(
|
|
58
|
+
`
|
|
57
59
|
RUN ${YARN_INSTALL_CLASSIC} --production --ignore-scripts
|
|
58
60
|
${DOCKER_COPY_FILES}
|
|
59
61
|
RUN ${YARN_INSTALL_CLASSIC} --production
|
|
60
|
-
`.trim()
|
|
62
|
+
`.trim()
|
|
63
|
+
);
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
// yarn >= 4 ships with build in plugins, see https://github.com/yarnpkg/berry/pull/4253
|
|
@@ -71,10 +74,12 @@ RUN ${YARN_INSTALL_CLASSIC} --production
|
|
|
71
74
|
|
|
72
75
|
// copy first everything and then install
|
|
73
76
|
// rebuild first does not work as it will run postinstall and that might require files in the app
|
|
74
|
-
return
|
|
77
|
+
return new BashExpression(
|
|
78
|
+
`
|
|
75
79
|
${DOCKER_COPY_FILES}
|
|
76
80
|
${maybeAddWorkspaceToolsCommand}
|
|
77
81
|
RUN ${YARN_BERRY_PROD_REBUILD}
|
|
78
82
|
|
|
79
|
-
`.trim()
|
|
83
|
+
`.trim()
|
|
84
|
+
);
|
|
80
85
|
};
|
package/src/build/rails/build.ts
CHANGED
|
@@ -40,6 +40,7 @@ export const createRailsBuildJobs = (context: Context): CatladderJob[] => {
|
|
|
40
40
|
// custom script
|
|
41
41
|
script: [
|
|
42
42
|
...gitlabDockerLogin(context),
|
|
43
|
+
`cd ${context.componentConfig.dir}`,
|
|
43
44
|
`docker pull $DOCKER_CACHE_IMAGE || true`,
|
|
44
45
|
`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`,
|
|
45
46
|
`chmod +x /usr/local/bin/pack`,
|
package/src/build/rails/test.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { ensureArray, notNil } from "../../utils";
|
|
|
4
4
|
|
|
5
5
|
export const createRailsTestJobs = (context: Context): CatladderJob[] => {
|
|
6
6
|
// don't run tests after release
|
|
7
|
-
|
|
7
|
+
// TODO: this will be replaced by using rules
|
|
8
|
+
if (context.trigger === "taggedRelease") {
|
|
8
9
|
return [];
|
|
9
10
|
}
|
|
10
11
|
|
package/src/build/types.ts
CHANGED
|
@@ -43,35 +43,20 @@ export type BuildConfigBase = {
|
|
|
43
43
|
/**
|
|
44
44
|
* additional env vars for the buid jobs
|
|
45
45
|
*
|
|
46
|
-
* @deprecated use jobVars
|
|
46
|
+
* @deprecated use jobVars or runnerVariables
|
|
47
47
|
*/
|
|
48
48
|
extraVars?: Record<string, string>;
|
|
49
|
+
|
|
49
50
|
/**
|
|
50
|
-
*
|
|
51
|
+
* additional vars only for the runner.
|
|
52
|
+
* Also if you use services: that require env vars, you need to set them here.
|
|
53
|
+
*
|
|
51
54
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
runnerVariables?: Record<string, string>;
|
|
54
56
|
/**
|
|
55
|
-
*
|
|
57
|
+
* define the build command
|
|
56
58
|
*/
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Custom Dockerfile lines integrated in the generated Dockerfile before the standard build steps.
|
|
60
|
-
*
|
|
61
|
-
* - [runner-images/docker-build/scripts/ensureNodeDockerfile](https://git.panter.ch/catladder/catladder/-/tree/main/runner-images/docker-build/scripts/ensureNodeDockerfile)
|
|
62
|
-
* - [runner-images/docker-build/scripts/ensureNginxDockerfile](https://git.panter.ch/catladder/catladder/-/tree/main/runner-images/docker-build/scripts/ensureNginxDockerfile)
|
|
63
|
-
* - [runner-images/docker-build/scripts/ensureMeteorDockerfile](https://git.panter.ch/catladder/catladder/-/tree/main/runner-images/docker-build/scripts/ensureMeteorDockerfile)
|
|
64
|
-
*/
|
|
65
|
-
additionsBegin?: string[];
|
|
66
|
-
/**
|
|
67
|
-
* Custom Dockerfile lines integrated in the generated Dockerfile after the standard build steps.
|
|
68
|
-
*
|
|
69
|
-
* - [runner-images/docker-build/scripts/ensureNodeDockerfile](https://git.panter.ch/catladder/catladder/-/tree/main/runner-images/docker-build/scripts/ensureNodeDockerfile)
|
|
70
|
-
* - [runner-images/docker-build/scripts/ensureNginxDockerfile](https://git.panter.ch/catladder/catladder/-/tree/main/runner-images/docker-build/scripts/ensureNginxDockerfile)
|
|
71
|
-
* - [runner-images/docker-build/scripts/ensureMeteorDockerfile](https://git.panter.ch/catladder/catladder/-/tree/main/runner-images/docker-build/scripts/ensureMeteorDockerfile)
|
|
72
|
-
*/
|
|
73
|
-
additionsEnd?: string[];
|
|
74
|
-
};
|
|
59
|
+
buildCommand?: string | string[] | null;
|
|
75
60
|
|
|
76
61
|
/**
|
|
77
62
|
* customize lint, set false to disable
|
|
@@ -125,11 +110,13 @@ export type BuildConfigNodeBase = BuildConfigBase & {
|
|
|
125
110
|
|
|
126
111
|
export type BuildConfigNode = {
|
|
127
112
|
type: "node";
|
|
113
|
+
docker?: Omit<BuildConfigDockerBuiltInNode, "type"> | BuildConfigDocker;
|
|
128
114
|
} & BuildConfigNodeBase;
|
|
129
115
|
|
|
130
116
|
export type BuildConfigNodeStatic = BuildConfigNodeBase & {
|
|
131
117
|
type: "node-static";
|
|
132
118
|
startCommand?: never;
|
|
119
|
+
docker?: Omit<BuildConfigDockerBuiltInNgninx, "type"> | BuildConfigDocker;
|
|
133
120
|
};
|
|
134
121
|
|
|
135
122
|
export type BuildConfigMeteor = BuildConfigNodeBase & {
|
|
@@ -139,23 +126,58 @@ export type BuildConfigMeteor = BuildConfigNodeBase & {
|
|
|
139
126
|
* This is only required if you have custom scripts in your image
|
|
140
127
|
*/
|
|
141
128
|
installScripts?: boolean;
|
|
129
|
+
docker?: Omit<BuildConfigDockerBuiltInMeteor, "type"> | BuildConfigDocker;
|
|
142
130
|
};
|
|
143
131
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
132
|
+
type BuildConfigDockerWithAdditions = {
|
|
133
|
+
/**
|
|
134
|
+
* Custom Dockerfile lines integrated in the generated Dockerfile before the standard build steps.
|
|
135
|
+
*
|
|
136
|
+
*/
|
|
137
|
+
additionsBegin?: string[];
|
|
138
|
+
/**
|
|
139
|
+
* Custom Dockerfile lines integrated in the generated Dockerfile after the standard build steps.
|
|
140
|
+
*
|
|
141
|
+
*/
|
|
142
|
+
additionsEnd?: string[];
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
type BuildConfigDockerBuiltInNode = {
|
|
146
|
+
type: "node";
|
|
147
|
+
} & BuildConfigDockerWithAdditions;
|
|
148
|
+
|
|
149
|
+
type BuildConfigDockerBuiltInMeteor = {
|
|
150
|
+
type: "meteor";
|
|
151
|
+
} & BuildConfigDockerWithAdditions;
|
|
152
|
+
|
|
153
|
+
type BuildConfigDockerBuiltInNgninx = {
|
|
154
|
+
/**
|
|
155
|
+
* use the built-in nginx image for simple static apps
|
|
156
|
+
*/
|
|
157
|
+
type: "nginx";
|
|
158
|
+
} & BuildConfigDockerWithAdditions;
|
|
159
|
+
type BuildConfigDockerBuiltIn =
|
|
160
|
+
| BuildConfigDockerBuiltInNgninx
|
|
161
|
+
| BuildConfigDockerBuiltInNode
|
|
162
|
+
| BuildConfigDockerBuiltInMeteor;
|
|
163
|
+
|
|
164
|
+
type BuildConfigDockerCustom = {
|
|
165
|
+
/**
|
|
166
|
+
* custom docker build, expect that a Dockerfile in your directory
|
|
167
|
+
*/
|
|
168
|
+
type: "custom";
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export type BuildConfigDocker =
|
|
172
|
+
| BuildConfigDockerBuiltIn
|
|
173
|
+
| BuildConfigDockerCustom;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @deprecated this type is no longer used. Use {@link BuildConfigDocker} instead.
|
|
177
|
+
*/
|
|
178
|
+
export type BuildConfigCustomDocker =
|
|
179
|
+
| BuildConfigDockerCustom
|
|
180
|
+
| BuildConfigDockerBuiltInNgninx;
|
|
159
181
|
|
|
160
182
|
export type BuildConfigCustom = Omit<
|
|
161
183
|
BuildConfigBase,
|
|
@@ -168,7 +190,7 @@ export type BuildConfigCustom = Omit<
|
|
|
168
190
|
*/
|
|
169
191
|
jobServices?: Services;
|
|
170
192
|
|
|
171
|
-
docker:
|
|
193
|
+
docker: BuildConfigDocker;
|
|
172
194
|
|
|
173
195
|
/**
|
|
174
196
|
* custom lint, disabled when not set
|
package/src/catladder-gitlab.ts
CHANGED
|
@@ -1,59 +1,12 @@
|
|
|
1
|
-
import { writeFileSync } from "fs";
|
|
2
|
-
import { dump } from "js-yaml";
|
|
3
1
|
import { readConfigSync } from "./config";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import type { PipelineTrigger } from "./types";
|
|
2
|
+
import { generatePipelineFiles } from "./pipeline/generatePipelineFiles";
|
|
3
|
+
import type { PipelineMode } from "./types";
|
|
7
4
|
|
|
8
|
-
const
|
|
9
|
-
CI_MERGE_REQUEST_ID,
|
|
10
|
-
CI_COMMIT_TAG,
|
|
11
|
-
CI_COMMIT_BRANCH,
|
|
12
|
-
CI_DEFAULT_BRANCH,
|
|
13
|
-
} = process.env;
|
|
5
|
+
const mode = process.argv[2] || "local";
|
|
14
6
|
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
? /^[0-9]+\.([0-9]+|x)\.x$/.test(CI_COMMIT_BRANCH)
|
|
19
|
-
: false;
|
|
20
|
-
const isMergeRequest = Boolean(CI_MERGE_REQUEST_ID);
|
|
21
|
-
const isTaggedRelease = Boolean(CI_COMMIT_TAG);
|
|
22
|
-
|
|
23
|
-
console.info(`catladder version ${PIPELINE_IMAGE_TAG}`);
|
|
24
|
-
|
|
25
|
-
const trigger: PipelineTrigger | null =
|
|
26
|
-
isMergeRequest || isHotfixBranch
|
|
27
|
-
? "mr"
|
|
28
|
-
: isDefaultBranch
|
|
29
|
-
? "mainBranch"
|
|
30
|
-
: isTaggedRelease
|
|
31
|
-
? "taggedRelease"
|
|
32
|
-
: null;
|
|
33
|
-
if (trigger) {
|
|
34
|
-
const config = readConfigSync()?.config;
|
|
35
|
-
if (!config) {
|
|
36
|
-
throw new Error("no catladder config found");
|
|
37
|
-
}
|
|
38
|
-
createChildPipeline("gitlab", trigger, config).then(
|
|
39
|
-
({ jobs, ...mainPipeline }) => {
|
|
40
|
-
// need to spread out the jobs
|
|
41
|
-
writeFileSync(`__pipeline.yml`, dump({ ...jobs, ...mainPipeline }), {
|
|
42
|
-
encoding: "utf-8",
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
);
|
|
46
|
-
} else {
|
|
47
|
-
throw new Error(
|
|
48
|
-
"no matching trigger: " +
|
|
49
|
-
JSON.stringify(
|
|
50
|
-
{
|
|
51
|
-
isMergeRequest,
|
|
52
|
-
isDefaultBranch,
|
|
53
|
-
isTaggedRelease,
|
|
54
|
-
},
|
|
55
|
-
null,
|
|
56
|
-
2
|
|
57
|
-
)
|
|
58
|
-
);
|
|
7
|
+
const config = readConfigSync()?.config;
|
|
8
|
+
if (!config) {
|
|
9
|
+
throw new Error("no catladder config found");
|
|
59
10
|
}
|
|
11
|
+
|
|
12
|
+
generatePipelineFiles(config, "gitlab", mode as PipelineMode<"gitlab">);
|
package/src/config/readConfig.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "fs";
|
|
2
2
|
import { register } from "ts-node";
|
|
3
|
-
import {
|
|
3
|
+
import { parse } from "yaml";
|
|
4
4
|
import type { Config } from "../types";
|
|
5
5
|
|
|
6
6
|
// allows us to load ts files
|
|
@@ -33,14 +33,13 @@ export const readConfigSync = (
|
|
|
33
33
|
return {
|
|
34
34
|
path: filePath,
|
|
35
35
|
ext: found,
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
37
36
|
config: requireUncached(filePath).default,
|
|
38
37
|
};
|
|
39
38
|
} else {
|
|
40
39
|
return {
|
|
41
40
|
path: filePath,
|
|
42
41
|
ext: found,
|
|
43
|
-
config:
|
|
42
|
+
config: parse(readFileSync(filePath, { encoding: "utf-8" })) as Config,
|
|
44
43
|
};
|
|
45
44
|
}
|
|
46
45
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export const PIPELINE_IMAGE_TAG =
|
|
2
|
-
|
|
1
|
+
export const PIPELINE_IMAGE_TAG =
|
|
2
|
+
process.env.INLINE_PIPELINE_IMAGE_TAG || "latest";
|
|
3
|
+
export const DOCKER_REGISTRY =
|
|
4
|
+
process.env.INLINE_DOCKER_REGISTRY ||
|
|
5
|
+
"git.panter.ch:5001/catladder/catladder";
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import type { BashExpression } from "../../bash/BashExpression";
|
|
1
2
|
import {
|
|
2
3
|
resolveReferences,
|
|
3
4
|
translateLegacyFromComponents,
|
|
4
5
|
} from "../resolveReferences";
|
|
5
6
|
|
|
7
|
+
const unpackBashExpressions = (obj: Record<string, string | BashExpression>) =>
|
|
8
|
+
Object.fromEntries(
|
|
9
|
+
Object.entries(obj).map(([key, value]) => [key, value.toString()])
|
|
10
|
+
);
|
|
6
11
|
describe("resolveReferences", () => {
|
|
7
12
|
it("replaces occurences of ${componentName:VARIABLE_NAME}", async () => {
|
|
8
13
|
const variables = {
|
|
@@ -21,7 +26,7 @@ describe("resolveReferences", () => {
|
|
|
21
26
|
return otherVariables[componentName];
|
|
22
27
|
});
|
|
23
28
|
|
|
24
|
-
expect(result).toEqual({
|
|
29
|
+
expect(unpackBashExpressions(result)).toEqual({
|
|
25
30
|
a: "hello world",
|
|
26
31
|
b: "a replaced value looks like this: 'foo from api', nice!",
|
|
27
32
|
});
|
|
@@ -34,7 +39,7 @@ describe("resolveReferences", () => {
|
|
|
34
39
|
};
|
|
35
40
|
const result = await resolveReferences(variables);
|
|
36
41
|
|
|
37
|
-
expect(result).toEqual({
|
|
42
|
+
expect(unpackBashExpressions(result)).toEqual({
|
|
38
43
|
FOO: "hello world",
|
|
39
44
|
BAR: "this: hello world!",
|
|
40
45
|
});
|
|
@@ -54,7 +59,7 @@ describe("resolveReferences", () => {
|
|
|
54
59
|
return otherVariables[componentName];
|
|
55
60
|
});
|
|
56
61
|
|
|
57
|
-
expect(result).toEqual({
|
|
62
|
+
expect(unpackBashExpressions(result)).toEqual({
|
|
58
63
|
FOO: "hello from foo from api",
|
|
59
64
|
BAR: "this: hello from foo from api!",
|
|
60
65
|
});
|
|
@@ -70,7 +75,7 @@ describe("resolveReferences", () => {
|
|
|
70
75
|
return otherVariables[componentName];
|
|
71
76
|
});
|
|
72
77
|
|
|
73
|
-
expect(result).toEqual({
|
|
78
|
+
expect(unpackBashExpressions(result)).toEqual({
|
|
74
79
|
a: "hello world",
|
|
75
80
|
b: "a not found value looks like this: '${api:FOO}'",
|
|
76
81
|
});
|
|
@@ -92,7 +97,7 @@ describe("resolveReferences", () => {
|
|
|
92
97
|
return otherVariables[componentName];
|
|
93
98
|
});
|
|
94
99
|
|
|
95
|
-
expect(result).toEqual({
|
|
100
|
+
expect(unpackBashExpressions(result)).toEqual({
|
|
96
101
|
a: "value is hi, foo from api!",
|
|
97
102
|
});
|
|
98
103
|
});
|
|
@@ -113,7 +118,7 @@ describe("resolveReferences", () => {
|
|
|
113
118
|
return otherVariables[componentName];
|
|
114
119
|
});
|
|
115
120
|
|
|
116
|
-
expect(result).toEqual({
|
|
121
|
+
expect(unpackBashExpressions(result)).toEqual({
|
|
117
122
|
a: "value is frontend api ${frontend:FOO}!",
|
|
118
123
|
});
|
|
119
124
|
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BashExpression } from "../bash/BashExpression";
|
|
2
|
+
import type { BashExpressionPerPipelineType } from "../bash/bashExpressionPerPipelineType";
|
|
3
|
+
import { getBashExpressionPerPipelineType } from "../bash/bashExpressionPerPipelineType";
|
|
4
|
+
import type { EnvironmentContext } from "../types/environmentContext";
|
|
5
|
+
|
|
6
|
+
const BUILD_TIME: BashExpressionPerPipelineType = {
|
|
7
|
+
default: "unknown-build-time",
|
|
8
|
+
gitlab: new BashExpression(`$CI_JOB_STARTED_AT`),
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const BUILD_ID: BashExpressionPerPipelineType = {
|
|
12
|
+
default: new BashExpression(
|
|
13
|
+
`$(git describe --tags 2>/dev/null || git rev-parse HEAD)`
|
|
14
|
+
),
|
|
15
|
+
};
|
|
16
|
+
const CURRENT_VERSION: BashExpressionPerPipelineType = {
|
|
17
|
+
default: new BashExpression(
|
|
18
|
+
// because we do shallow fetch, we need to ask the origin
|
|
19
|
+
`$(tag=$(git ls-remote origin "refs/tags/v*[0-9]" 2>/dev/null | cut -f 2- | sort -V | tail -1 | sed 's/refs\\/tags\\///'); [ -z "$tag" ] && echo "v0.0.0" || echo "$tag")`
|
|
20
|
+
),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const getBuildInfoVariables = (ctx: EnvironmentContext<any, any>) => {
|
|
24
|
+
const { pipelineType } = ctx;
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
BUILD_INFO_BUILD_ID: getBashExpressionPerPipelineType(
|
|
28
|
+
BUILD_ID,
|
|
29
|
+
pipelineType
|
|
30
|
+
),
|
|
31
|
+
BUILD_INFO_BUILD_TIME: getBashExpressionPerPipelineType(
|
|
32
|
+
BUILD_TIME,
|
|
33
|
+
pipelineType
|
|
34
|
+
),
|
|
35
|
+
BUILD_INFO_CURRENT_VERSION: getBashExpressionPerPipelineType(
|
|
36
|
+
CURRENT_VERSION,
|
|
37
|
+
pipelineType
|
|
38
|
+
),
|
|
39
|
+
};
|
|
40
|
+
};
|