mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-02-21 19:48:53 +02:00
Modification to documentation of cnbBuild. (#3222)
Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com> Co-authored-by: Philipp Stehle <philipp.stehle@sap.com> Co-authored-by: Pavel Busko <pavel.busko@sap.com> Co-authored-by: Jan von Löwenstein <jan.von.loewenstein@sap.com>
This commit is contained in:
parent
adcc0447ba
commit
9a60143153
@ -354,27 +354,25 @@ func runCnbBuild(config *cnbBuildOptions, telemetryData *telemetry.CustomData, u
|
||||
var containerImage string
|
||||
var containerImageTag string
|
||||
|
||||
if len(config.ContainerRegistryURL) > 0 && len(config.ContainerImageName) > 0 && len(config.ContainerImageTag) > 0 {
|
||||
var containerRegistry string
|
||||
if matched, _ := regexp.MatchString("^(http|https)://.*", config.ContainerRegistryURL); matched {
|
||||
containerRegistry, err = docker.ContainerRegistryFromURL(config.ContainerRegistryURL)
|
||||
if err != nil {
|
||||
log.SetErrorCategory(log.ErrorConfiguration)
|
||||
return errors.Wrapf(err, "failed to read containerRegistryUrl %s", config.ContainerRegistryURL)
|
||||
}
|
||||
} else {
|
||||
containerRegistry = config.ContainerRegistryURL
|
||||
}
|
||||
|
||||
containerImage = fmt.Sprintf("%s/%s", containerRegistry, config.ContainerImageName)
|
||||
containerImageTag = strings.ReplaceAll(config.ContainerImageTag, "+", "-")
|
||||
commonPipelineEnvironment.container.registryURL = config.ContainerRegistryURL
|
||||
commonPipelineEnvironment.container.imageNameTag = containerImage
|
||||
} else {
|
||||
if len(config.ContainerRegistryURL) == 0 || len(config.ContainerImageName) == 0 || len(config.ContainerImageTag) == 0 {
|
||||
log.SetErrorCategory(log.ErrorConfiguration)
|
||||
return errors.New("containerRegistryUrl, containerImageName and containerImageTag must be present")
|
||||
}
|
||||
|
||||
var containerRegistry string
|
||||
if matched, _ := regexp.MatchString("^(http|https)://.*", config.ContainerRegistryURL); matched {
|
||||
containerRegistry, err = docker.ContainerRegistryFromURL(config.ContainerRegistryURL)
|
||||
if err != nil {
|
||||
log.SetErrorCategory(log.ErrorConfiguration)
|
||||
return errors.Wrapf(err, "failed to read containerRegistryUrl %s", config.ContainerRegistryURL)
|
||||
}
|
||||
} else {
|
||||
containerRegistry = config.ContainerRegistryURL
|
||||
}
|
||||
|
||||
containerImage = fmt.Sprintf("%s/%s", containerRegistry, config.ContainerImageName)
|
||||
containerImageTag = strings.ReplaceAll(config.ContainerImageTag, "+", "-")
|
||||
|
||||
if len(config.CustomTLSCertificateLinks) > 0 {
|
||||
caCertificates := "/tmp/ca-certificates.crt"
|
||||
_, err := utils.Copy("/etc/ssl/certs/ca-certificates.crt", caCertificates)
|
||||
@ -402,10 +400,14 @@ func runCnbBuild(config *cnbBuildOptions, telemetryData *telemetry.CustomData, u
|
||||
return errors.Wrapf(err, "execution of '%s' failed", builderPath)
|
||||
}
|
||||
|
||||
containerImageNameTag := fmt.Sprintf("%s:%s", containerImage, containerImageTag)
|
||||
targets := []string{
|
||||
fmt.Sprintf("%s:%s", containerImage, containerImageTag),
|
||||
containerImageNameTag,
|
||||
}
|
||||
|
||||
commonPipelineEnvironment.container.registryURL = config.ContainerRegistryURL
|
||||
commonPipelineEnvironment.container.imageNameTag = containerImageNameTag
|
||||
|
||||
for _, tag := range config.AdditionalTags {
|
||||
target := fmt.Sprintf("%s:%s", containerImage, tag)
|
||||
if !piperutils.ContainsString(targets, target) {
|
||||
|
@ -150,18 +150,17 @@ func addCnbBuildFlags(cmd *cobra.Command, stepConfig *cnbBuildOptions) {
|
||||
cmd.Flags().StringVar(&stepConfig.ContainerImageName, "containerImageName", os.Getenv("PIPER_containerImageName"), "Name of the container which will be built")
|
||||
cmd.Flags().StringVar(&stepConfig.ContainerImageTag, "containerImageTag", os.Getenv("PIPER_containerImageTag"), "Tag of the container which will be built")
|
||||
cmd.Flags().StringVar(&stepConfig.ContainerRegistryURL, "containerRegistryUrl", os.Getenv("PIPER_containerRegistryUrl"), "Container registry where the image should be pushed to")
|
||||
cmd.Flags().StringSliceVar(&stepConfig.Buildpacks, "buildpacks", []string{}, "List of custom buildpacks to use in the form of '<hostname>/<repo>[:<tag>]'.")
|
||||
cmd.Flags().StringSliceVar(&stepConfig.Buildpacks, "buildpacks", []string{}, "List of custom buildpacks to use in the form of '$HOSTNAME/$REPO[:$TAG]'.")
|
||||
cmd.Flags().StringSliceVar(&stepConfig.BuildEnvVars, "buildEnvVars", []string{}, "List of custom environment variables used during a build in the form of 'KEY=VALUE'.")
|
||||
cmd.Flags().StringVar(&stepConfig.Path, "path", os.Getenv("PIPER_path"), "The path should either point to a directory with your sources or an artifact in zip format.")
|
||||
cmd.Flags().StringVar(&stepConfig.ProjectDescriptor, "projectDescriptor", `project.toml`, "Path to the project.toml file (see https://buildpacks.io/docs/reference/config/project-descriptor/ for the reference). Parameters passed to the cnbBuild step will take precedence over the parameters set in the project.toml file.")
|
||||
cmd.Flags().StringVar(&stepConfig.Path, "path", os.Getenv("PIPER_path"), "The path should either point to a directory with your sources or an artifact in zip format.\nThis property determines the input to the buildpack.\n")
|
||||
cmd.Flags().StringVar(&stepConfig.ProjectDescriptor, "projectDescriptor", `project.toml`, "Path to the project.toml file.\nSee [buildpacks.io](https://buildpacks.io/docs/reference/config/project-descriptor/) for the reference.\nParameters passed to the cnbBuild step will take precedence over the parameters set in the project.toml file.\n\nNote: Inline buildpacks (see [specification](https://buildpacks.io/docs/reference/config/project-descriptor/#build-_table-optional_)) are not supported yet.\n")
|
||||
cmd.Flags().StringVar(&stepConfig.DockerConfigJSON, "dockerConfigJSON", os.Getenv("PIPER_dockerConfigJSON"), "Path to the file `.docker/config.json` - this is typically provided by your CI/CD system. You can find more details about the Docker credentials in the [Docker documentation](https://docs.docker.com/engine/reference/commandline/login/).")
|
||||
cmd.Flags().StringSliceVar(&stepConfig.CustomTLSCertificateLinks, "customTlsCertificateLinks", []string{}, "List containing download links of custom TLS certificates. This is required to ensure trusted connections to registries with custom certificates.")
|
||||
cmd.Flags().StringSliceVar(&stepConfig.AdditionalTags, "additionalTags", []string{}, "List of tags which will be additionally pushed to the registry, e.g. \"latest\".")
|
||||
cmd.Flags().StringSliceVar(&stepConfig.AdditionalTags, "additionalTags", []string{}, "List of tags which will be pushed to the registry (additionally to the provided `containerImageTag`), e.g. \"latest\".")
|
||||
|
||||
cmd.MarkFlagRequired("containerImageName")
|
||||
cmd.MarkFlagRequired("containerImageTag")
|
||||
cmd.MarkFlagRequired("containerRegistryUrl")
|
||||
cmd.MarkFlagRequired("dockerConfigJSON")
|
||||
}
|
||||
|
||||
// retrieve step metadata
|
||||
@ -272,7 +271,7 @@ func cnbBuildMetadata() config.StepData {
|
||||
},
|
||||
Scope: []string{"PARAMETERS"},
|
||||
Type: "string",
|
||||
Mandatory: true,
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
Default: os.Getenv("PIPER_dockerConfigJSON"),
|
||||
},
|
||||
|
@ -2,18 +2,36 @@
|
||||
|
||||
## ${docGenDescription}
|
||||
|
||||
see [Examples](#examples)
|
||||
|
||||
## Prerequisites
|
||||
|
||||
When pushing to a container registry, you need to maintain the respective credentials in your Jenkins credentials store:
|
||||
|
||||
`cnbBuild` expects a Docker `config.json` file containing the credential information for registries.
|
||||
You can create it like explained in the [protocodeExecuteScan Prerequisites section](https://www.project-piper.io/steps/protecodeExecuteScan/#prerequisites).
|
||||
|
||||
Please copy this file and upload it to your Jenkins for example<br />
|
||||
via _Jenkins_ -> _Credentials_ -> _System_ -> _Global credentials (unrestricted)_ -> _Add Credentials_ ->
|
||||
|
||||
* Kind: _Secret file_
|
||||
* File: upload your `config.json` file
|
||||
* ID: specify id which you then use for the configuration of `dockerConfigJsonCredentialsId` (see below)
|
||||
|
||||
## ${docGenParameters}
|
||||
|
||||
### Additional hints
|
||||
|
||||
To run the `cnbBuild` with a different builder, you can specify the `dockerImage` parameter.
|
||||
Without specifying it, the step will run with the `paketobuildpacks/builder:full` builder.
|
||||
|
||||
## ${docGenParameters}
|
||||
|
||||
## ${docGenConfiguration}
|
||||
|
||||
## ${docJenkinsPluginDependencies}
|
||||
|
||||
## Example 1
|
||||
## Examples
|
||||
|
||||
### Example 1: simple usage
|
||||
|
||||
```groovy
|
||||
cnbBuild(
|
||||
@ -25,7 +43,7 @@ cnbBuild(
|
||||
)
|
||||
```
|
||||
|
||||
## Example 2: User provided builder
|
||||
### Example 2: User provided builder
|
||||
|
||||
```groovy
|
||||
cnbBuild(
|
||||
@ -38,7 +56,7 @@ cnbBuild(
|
||||
)
|
||||
```
|
||||
|
||||
## Example 3: User provided buildpacks
|
||||
### Example 3: User provided buildpacks
|
||||
|
||||
```groovy
|
||||
cnbBuild(
|
||||
|
@ -73,7 +73,7 @@ spec:
|
||||
param: container/registryUrl
|
||||
- name: buildpacks
|
||||
type: "[]string"
|
||||
description: List of custom buildpacks to use in the form of '<hostname>/<repo>[:<tag>]'.
|
||||
description: List of custom buildpacks to use in the form of '$HOSTNAME/$REPO[:$TAG]'.
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
@ -87,14 +87,21 @@ spec:
|
||||
- STEPS
|
||||
- name: path
|
||||
type: string
|
||||
description: The path should either point to a directory with your sources or an artifact in zip format.
|
||||
description: |
|
||||
The path should either point to a directory with your sources or an artifact in zip format.
|
||||
This property determines the input to the buildpack.
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- name: projectDescriptor
|
||||
type: string
|
||||
description: Path to the project.toml file (see https://buildpacks.io/docs/reference/config/project-descriptor/ for the reference). Parameters passed to the cnbBuild step will take precedence over the parameters set in the project.toml file.
|
||||
description: |
|
||||
Path to the project.toml file.
|
||||
See [buildpacks.io](https://buildpacks.io/docs/reference/config/project-descriptor/) for the reference.
|
||||
Parameters passed to the cnbBuild step will take precedence over the parameters set in the project.toml file.
|
||||
|
||||
Note: Inline buildpacks (see [specification](https://buildpacks.io/docs/reference/config/project-descriptor/#build-_table-optional_)) are not supported yet.
|
||||
default: project.toml
|
||||
scope:
|
||||
- PARAMETERS
|
||||
@ -106,7 +113,6 @@ spec:
|
||||
scope:
|
||||
- PARAMETERS
|
||||
secret: true
|
||||
mandatory: true
|
||||
resourceRef:
|
||||
- name: commonPipelineEnvironment
|
||||
param: custom/dockerConfigJSON
|
||||
@ -124,7 +130,7 @@ spec:
|
||||
- STEPS
|
||||
- name: additionalTags
|
||||
type: "[]string"
|
||||
description: List of tags which will be additionally pushed to the registry, e.g. "latest".
|
||||
description: List of tags which will be pushed to the registry (additionally to the provided `containerImageTag`), e.g. "latest".
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
|
Loading…
x
Reference in New Issue
Block a user