You've already forked sap-jenkins-library
							
							
				mirror of
				https://github.com/SAP/jenkins-library.git
				synced 2025-10-30 23:57:50 +02:00 
			
		
		
		
	feat(cnbBuild): allow setting the default process type (#4140)
This commit is contained in:
		| @@ -601,6 +601,10 @@ func runCnbBuild(config *cnbBuildOptions, cnbTelemetry *cnbBuildTelemetry, utils | ||||
| 		creatorArgs = append(creatorArgs, "-run-image", config.RunImage) | ||||
| 	} | ||||
|  | ||||
| 	if config.DefaultProcess != "" { | ||||
| 		creatorArgs = append(creatorArgs, "-process-type", config.DefaultProcess) | ||||
| 	} | ||||
|  | ||||
| 	containerImage := path.Join(targetImage.ContainerRegistry.Host, targetImage.ContainerImageName) | ||||
| 	for _, tag := range config.AdditionalTags { | ||||
| 		target := fmt.Sprintf("%s:%s", containerImage, tag) | ||||
|   | ||||
| @@ -39,6 +39,7 @@ type cnbBuildOptions struct { | ||||
| 	BuildSettingsInfo         string                   `json:"buildSettingsInfo,omitempty"` | ||||
| 	CreateBOM                 bool                     `json:"createBOM,omitempty"` | ||||
| 	RunImage                  string                   `json:"runImage,omitempty"` | ||||
| 	DefaultProcess            string                   `json:"defaultProcess,omitempty"` | ||||
| } | ||||
|  | ||||
| type cnbBuildCommonPipelineEnvironment struct { | ||||
| @@ -234,6 +235,7 @@ func addCnbBuildFlags(cmd *cobra.Command, stepConfig *cnbBuildOptions) { | ||||
| 	cmd.Flags().StringVar(&stepConfig.BuildSettingsInfo, "buildSettingsInfo", os.Getenv("PIPER_buildSettingsInfo"), "Build settings info is typically filled by the step automatically to create information about the build settings that were used during the mta build. This information is typically used for compliance related processes.") | ||||
| 	cmd.Flags().BoolVar(&stepConfig.CreateBOM, "createBOM", false, "**EXPERIMENTAL:** Creates the bill of materials (BOM) using CycloneDX plugin.") | ||||
| 	cmd.Flags().StringVar(&stepConfig.RunImage, "runImage", os.Getenv("PIPER_runImage"), "Base image from which application images are built. Will be defaulted to the image provided by the builder.") | ||||
| 	cmd.Flags().StringVar(&stepConfig.DefaultProcess, "defaultProcess", os.Getenv("PIPER_defaultProcess"), "Process that should be started by default. See https://buildpacks.io/docs/app-developer-guide/run-an-app/") | ||||
|  | ||||
| 	cmd.MarkFlagRequired("containerImageTag") | ||||
| 	cmd.MarkFlagRequired("containerRegistryUrl") | ||||
| @@ -444,6 +446,15 @@ func cnbBuildMetadata() config.StepData { | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 						Default:     os.Getenv("PIPER_runImage"), | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "defaultProcess", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"GENERAL", "STEPS", "STAGES", "PARAMETERS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 						Default:     os.Getenv("PIPER_defaultProcess"), | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Containers: []config.Container{ | ||||
|   | ||||
| @@ -79,6 +79,7 @@ func TestRunCnbBuild(t *testing.T) { | ||||
| 			ContainerRegistryURL: fmt.Sprintf("https://%s", imageRegistry), | ||||
| 			DockerConfigJSON:     "/path/to/config.json", | ||||
| 			RunImage:             "my-run-image", | ||||
| 			DefaultProcess:       "my-process", | ||||
| 		} | ||||
|  | ||||
| 		projectToml := `[project] | ||||
| @@ -99,6 +100,8 @@ func TestRunCnbBuild(t *testing.T) { | ||||
| 		assert.Contains(t, runner.Calls[0].Params, fmt.Sprintf("%s/%s:%s", imageRegistry, config.ContainerImageName, config.ContainerImageTag)) | ||||
| 		assert.Contains(t, runner.Calls[0].Params, "-run-image") | ||||
| 		assert.Contains(t, runner.Calls[0].Params, "my-run-image") | ||||
| 		assert.Contains(t, runner.Calls[0].Params, "-process-type") | ||||
| 		assert.Contains(t, runner.Calls[0].Params, "my-process") | ||||
| 		assert.Equal(t, config.ContainerRegistryURL, commonPipelineEnvironment.container.registryURL) | ||||
| 		assert.Equal(t, "my-image:0.0.1", commonPipelineEnvironment.container.imageNameTag) | ||||
| 		assert.Equal(t, `{"cnbBuild":[{"dockerImage":"paketobuildpacks/builder:base"}]}`, commonPipelineEnvironment.custom.buildSettingsInfo) | ||||
|   | ||||
| @@ -57,12 +57,13 @@ func TestCNBIntegrationNPMProject(t *testing.T) { | ||||
| 	}) | ||||
| 	defer container2.terminate(t) | ||||
|  | ||||
| 	err := container.whenRunningPiperCommand("cnbBuild", "--noTelemetry", "--verbose", "--path", "TestCnbIntegration/project", "--customConfig", "TestCnbIntegration/config.yml", "--containerImageName", "node", "--containerImageTag", "0.0.1", "--containerRegistryUrl", registryURL) | ||||
| 	err := container.whenRunningPiperCommand("cnbBuild", "--noTelemetry", "--verbose", "--path", "TestCnbIntegration/project", "--customConfig", "TestCnbIntegration/config.yml", "--containerImageName", "node", "--containerImageTag", "0.0.1", "--containerRegistryUrl", registryURL, "--defaultProcess", "greeter") | ||||
| 	assert.NoError(t, err) | ||||
| 	container.assertHasOutput(t, "running command: /cnb/lifecycle/creator") | ||||
| 	container.assertHasOutput(t, "Selected Node Engine version (using BP_NODE_VERSION): 16") | ||||
| 	container.assertHasOutput(t, "Paketo NPM Start Buildpack") | ||||
| 	container.assertHasOutput(t, fmt.Sprintf("Saving %s/node:0.0.1", registryURL)) | ||||
| 	container.assertHasOutput(t, "Setting default process type 'greeter'") | ||||
| 	container.assertHasOutput(t, "*** Images (sha256:") | ||||
| 	container.assertHasOutput(t, "SUCCESS") | ||||
| 	container.terminate(t) | ||||
|   | ||||
							
								
								
									
										2
									
								
								integration/testdata/TestCnbIntegration/project/Procfile
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								integration/testdata/TestCnbIntegration/project/Procfile
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| greeter: echo 'Hello World' | ||||
|  | ||||
| @@ -5,7 +5,8 @@ version = "0.1" | ||||
| [build] | ||||
| include = [ | ||||
|     "*.js", | ||||
|     "/package.json" | ||||
|     "/package.json", | ||||
|     "Procfile" | ||||
| ] | ||||
|  | ||||
| [[build.env]] | ||||
| @@ -26,3 +27,6 @@ uri = "gcr.io/paketo-buildpacks/node-module-bom:0.4.0" | ||||
|  | ||||
| [[build.buildpacks]] | ||||
| uri = "gcr.io/paketo-buildpacks/npm-start:0.9.2" | ||||
|  | ||||
| [[build.buildpacks]] | ||||
| uri = "gcr.io/paketo-buildpacks/procfile:5.4.0" | ||||
|   | ||||
| @@ -272,6 +272,14 @@ spec: | ||||
|           - STEPS | ||||
|           - STAGES | ||||
|           - PARAMETERS | ||||
|       - name: defaultProcess | ||||
|         type: string | ||||
|         description: "Process that should be started by default. See https://buildpacks.io/docs/app-developer-guide/run-an-app/" | ||||
|         scope: | ||||
|           - GENERAL | ||||
|           - STEPS | ||||
|           - STAGES | ||||
|           - PARAMETERS | ||||
|   outputs: | ||||
|     resources: | ||||
|       - name: commonPipelineEnvironment | ||||
|   | ||||
		Reference in New Issue
	
	Block a user