Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions documentation/docs/steps/dockerBuild.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# ${docGenStepName}

## ${docGenDescription}

Comment thread
fskhiri marked this conversation as resolved.
## Prerequisites

This step is intended for use in **GitHub Actions**, where Docker + BuildKit are natively available on the runner.
It is not supported on Jenkins or Azure DevOps runners.

When pushing to a container registry, you need to provide credentials via one of these approaches:

* Pass `containerRegistryUser` and `containerRegistryPassword` parameters — the step will write a `config.json` automatically.
* Provide a pre-existing `config.json` via the `dockerConfigJSON` parameter.

## ${docJenkinsPluginDependencies}

## Example

### Building a single image

```yaml
steps:
dockerBuild:
containerImageName: myImage
containerRegistryUrl: my.registry.example.com
containerRegistryUser: myUser
containerRegistryPassword: myPassword
```

### Building multiple images from sub-directories

```yaml
steps:
dockerBuild:
containerImageName: myImage
containerMultiImageBuild: true
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multi-image example is incomplete for push. This example builds sub-images but omits containerRegistryUrl and credentials, so the images can be built locally but cannot be pushed. Either add the missing registry/auth fields to show a realistic push scenario, or add a note clarifying that this example covers the build-only case and that credentials from the single-image example are required for push.

```

With the following Dockerfiles present in the repository:

* `sub1/Dockerfile`
* `sub2/Dockerfile`

The following images will be built and pushed:

* `myImage-sub1`
* `myImage-sub2`

### Using registry mirrors

```yaml
steps:
dockerBuild:
containerImageName: myImage
registryMirrors:
- mirror.gcr.io
- mycompany-docker-virtual.jfrog.io
```

### Enabling BOM creation

```yaml
steps:
dockerBuild:
containerImageName: myImage
createBOM: true
```

### Opting in (replacing kanikoExecute)

By default `kanikoExecute` is active and `dockerBuild` is off. To switch:

```yaml
stages:
Build:
dockerBuild: true
kanikoExecute: false
```

## ${docGenParameters}

## ${docGenConfiguration}
3 changes: 3 additions & 0 deletions documentation/docs/steps/kanikoExecute.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## ${docGenDescription}

> **Note:** For pipelines running on **GitHub Actions**, consider using the [`dockerBuild`](dockerBuild.md) step instead.
> It uses Docker BuildKit natively and does not require a Kaniko sidecar container.

## Prerequisites

When pushing to a container registry, you need to maintain the respective credentials in your Jenkins credentials store:
Expand Down
5 changes: 5 additions & 0 deletions pkg/buildsettings/buildSettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

type BuildSettings struct {
DockerBuild []BuildOptions `json:"dockerBuild,omitempty"`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Struct field ordering inconsistency. CnbBuild (C) already sits at the bottom of the struct out of alphabetical order, and placing DockerBuild (D) here at the top makes it worse — the struct now starts with D and ends with C. Either keep the existing append-at-bottom convention (move DockerBuild after CnbBuild) or fix the ordering for both fields while touching this file.

GolangBuild []BuildOptions `json:"golangBuild,omitempty"`
GradleExecuteBuild []BuildOptions `json:"gradleExecuteBuild,omitempty"`
HelmExecute []BuildOptions `json:"helmExecute,omitempty"`
Expand Down Expand Up @@ -78,6 +79,10 @@ func CreateBuildSettingsInfo(config *BuildOptions, buildTool string) (string, er
settings = append(settings, currentBuildSettingsInfo)
var err error
switch buildTool {
case "dockerBuild":
jsonResult, err = json.Marshal(BuildSettings{
DockerBuild: settings,
})
case "golangBuild":
jsonResult, err = json.Marshal(BuildSettings{
GolangBuild: settings,
Expand Down
5 changes: 5 additions & 0 deletions pkg/buildsettings/buildSettings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func TestCreateBuildSettingsInfo(t *testing.T) {
buildTool: "cnbBuild",
expected: "{\"cnbBuild\":[{\"dockerImage\":\"builder:latest\"}]}",
},
{
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test for the accumulation / merge path. CreateBuildSettingsInfo has two branches: the else branch (no prior BuildSettingsInfo, uses the typed BuildSettings struct — covered by this test) and the if branch (existing BuildSettingsInfo JSON is merged via map[string][]interface{}). The if path is only tested for mavenBuild in this file. Consider adding a case like:

{
    config:    BuildOptions{DockerImage: "docker:latest", BuildSettingsInfo: `{"dockerBuild":[{"dockerImage":"docker:prev"}]}`},
    buildTool: "dockerBuild",
    expected:  `{"dockerBuild":[{"dockerImage":"docker:prev"},{"dockerImage":"docker:latest"}]}`,
},

config: BuildOptions{DockerImage: "docker:latest"},
buildTool: "dockerBuild",
expected: "{\"dockerBuild\":[{\"dockerImage\":\"docker:latest\"}]}",
},
}

for _, testCase := range testTableConfig {
Expand Down
Loading