1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-02-21 19:48:53 +02:00

Allow run-image to be specified (#4088)

Co-authored-by: Philipp Stehle <philipp.stehle@sap.com>
This commit is contained in:
Johannes Dillmann 2022-10-27 15:18:32 +02:00 committed by GitHub
parent 95c8166796
commit cfacde97be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 0 deletions

View File

@ -598,6 +598,10 @@ func runCnbBuild(config *cnbBuildOptions, cnbTelemetry *cnbBuildTelemetry, utils
creatorArgs = append(creatorArgs, "-log-level", "debug")
}
if config.RunImage != "" {
creatorArgs = append(creatorArgs, "-run-image", config.RunImage)
}
containerImage := path.Join(targetImage.ContainerRegistry.Host, targetImage.ContainerImageName)
for _, tag := range config.AdditionalTags {
target := fmt.Sprintf("%s:%s", containerImage, tag)

View File

@ -38,6 +38,7 @@ type cnbBuildOptions struct {
PreserveFiles []string `json:"preserveFiles,omitempty"`
BuildSettingsInfo string `json:"buildSettingsInfo,omitempty"`
CreateBOM bool `json:"createBOM,omitempty"`
RunImage string `json:"runImage,omitempty"`
}
type cnbBuildCommonPipelineEnvironment struct {
@ -232,6 +233,7 @@ func addCnbBuildFlags(cmd *cobra.Command, stepConfig *cnbBuildOptions) {
cmd.Flags().StringSliceVar(&stepConfig.PreserveFiles, "preserveFiles", []string{}, "List of globs, for keeping build results in the Jenkins workspace.\n\n*Note*: globs will be calculated relative to the [path](#path) property.\n")
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.MarkFlagRequired("containerImageTag")
cmd.MarkFlagRequired("containerRegistryUrl")
@ -433,6 +435,15 @@ func cnbBuildMetadata() config.StepData {
Aliases: []config.Alias{},
Default: false,
},
{
Name: "runImage",
ResourceRef: []config.ResourceReference{},
Scope: []string{"GENERAL", "STEPS", "STAGES", "PARAMETERS"},
Type: "string",
Mandatory: false,
Aliases: []config.Alias{},
Default: os.Getenv("PIPER_runImage"),
},
},
},
Containers: []config.Container{

View File

@ -78,6 +78,7 @@ func TestRunCnbBuild(t *testing.T) {
ContainerImageTag: "0.0.1",
ContainerRegistryURL: fmt.Sprintf("https://%s", imageRegistry),
DockerConfigJSON: "/path/to/config.json",
RunImage: "my-run-image",
}
projectToml := `[project]
@ -96,6 +97,8 @@ func TestRunCnbBuild(t *testing.T) {
assert.Contains(t, runner.Env, "CNB_REGISTRY_AUTH={\"my-registry\":\"Basic dXNlcjpwYXNz\"}")
assertLifecycleCalls(t, runner, 1)
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.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)

View File

@ -264,6 +264,14 @@ spec:
- STEPS
- STAGES
- PARAMETERS
- name: runImage
type: string
description: "Base image from which application images are built. Will be defaulted to the image provided by the builder."
scope:
- GENERAL
- STEPS
- STAGES
- PARAMETERS
outputs:
resources:
- name: commonPipelineEnvironment