-
Notifications
You must be signed in to change notification settings - Fork 621
feat(buildsettings): add dockerBuild support in CreateBuildSettingsInfo #5780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # ${docGenStepName} | ||
|
|
||
| ## ${docGenDescription} | ||
|
|
||
| ## 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| ``` | ||
|
|
||
| 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} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |
| ) | ||
|
|
||
| type BuildSettings struct { | ||
| DockerBuild []BuildOptions `json:"dockerBuild,omitempty"` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Struct field ordering inconsistency. |
||
| GolangBuild []BuildOptions `json:"golangBuild,omitempty"` | ||
| GradleExecuteBuild []BuildOptions `json:"gradleExecuteBuild,omitempty"` | ||
| HelmExecute []BuildOptions `json:"helmExecute,omitempty"` | ||
|
|
@@ -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, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,11 @@ func TestCreateBuildSettingsInfo(t *testing.T) { | |
| buildTool: "cnbBuild", | ||
| expected: "{\"cnbBuild\":[{\"dockerImage\":\"builder:latest\"}]}", | ||
| }, | ||
| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing test for the accumulation / merge path. {
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 { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.