Skip to content
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

Opencontainers #5172

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 2 additions & 0 deletions cmd/artifactPrepareVersion.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ func runArtifactPrepareVersion(config *artifactPrepareVersionOptions, telemetryD
log.Entry().Infof("New version: '%v'", newVersion)

commonPipelineEnvironment.git.commitID = gitCommitID // this commitID changes and is not necessarily the HEAD commitID
commonPipelineEnvironment.container.labels["org.opencontainers.image.revision"] = gitCommitID
commonPipelineEnvironment.artifactVersion = newVersion
commonPipelineEnvironment.container.labels["org.opencontainers.image.version"] = newVersion
commonPipelineEnvironment.originalArtifactVersion = version

gitCommitMessages := strings.Split(gitCommitMessage, "\n")
Expand Down
7 changes: 6 additions & 1 deletion cmd/artifactPrepareVersion_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions cmd/kanikoExecute.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func runKanikoExecute(config *kanikoExecuteOptions, telemetryData *telemetry.Cus
log.Entry().Debugf("Building image '%v' using file '%v'", image, file)
containerImageNameAndTag := fmt.Sprintf("%v:%v", image, containerImageTag)
buildOpts := append(config.BuildOptions, "--destination", fmt.Sprintf("%v/%v", containerRegistry, containerImageNameAndTag))
if err = runKaniko(file, buildOpts, config.ReadImageDigest, execRunner, fileUtils, commonPipelineEnvironment); err != nil {
if err = runKaniko(config, file, buildOpts, config.ReadImageDigest, execRunner, fileUtils, commonPipelineEnvironment); err != nil {
return fmt.Errorf("failed to build image '%v' using '%v': %w", image, file, err)
}
commonPipelineEnvironment.container.imageNames = append(commonPipelineEnvironment.container.imageNames, image)
Expand Down Expand Up @@ -231,7 +231,7 @@ func runKanikoExecute(config *kanikoExecuteOptions, telemetryData *telemetry.Cus
dockerfilePath = entry.DockerfilePath
}

if err = runKaniko(dockerfilePath, buildOptions, config.ReadImageDigest, execRunner, fileUtils, commonPipelineEnvironment); err != nil {
if err = runKaniko(config, dockerfilePath, buildOptions, config.ReadImageDigest, execRunner, fileUtils, commonPipelineEnvironment); err != nil {
return fmt.Errorf("multipleImages: failed to build image '%v' using '%v': %w", entry.ContainerImageName, config.DockerfilePath, err)
}

Expand Down Expand Up @@ -262,7 +262,7 @@ func runKanikoExecute(config *kanikoExecuteOptions, telemetryData *telemetry.Cus
dockerfilePath = entry.DockerfilePath
}

if err = runKaniko(dockerfilePath, buildOptions, config.ReadImageDigest, execRunner, fileUtils, commonPipelineEnvironment); err != nil {
if err = runKaniko(config, dockerfilePath, buildOptions, config.ReadImageDigest, execRunner, fileUtils, commonPipelineEnvironment); err != nil {
return fmt.Errorf("multipleImages: failed to build image '%v' using '%v': %w", containerImageName, config.DockerfilePath, err)
}

Expand Down Expand Up @@ -356,7 +356,7 @@ func runKanikoExecute(config *kanikoExecuteOptions, telemetryData *telemetry.Cus
config.BuildOptions = append(config.BuildOptions, "--no-push")
}

if err = runKaniko(config.DockerfilePath, config.BuildOptions, config.ReadImageDigest, execRunner, fileUtils, commonPipelineEnvironment); err != nil {
if err = runKaniko(config, config.DockerfilePath, config.BuildOptions, config.ReadImageDigest, execRunner, fileUtils, commonPipelineEnvironment); err != nil {
return err
}

Expand All @@ -368,7 +368,7 @@ func runKanikoExecute(config *kanikoExecuteOptions, telemetryData *telemetry.Cus
return nil
}

func runKaniko(dockerFilepath string, buildOptions []string, readDigest bool, execRunner command.ExecRunner, fileUtils piperutils.FileUtils, commonPipelineEnvironment *kanikoExecuteCommonPipelineEnvironment) error {
func runKaniko(config *kanikoExecuteOptions, dockerFilepath string, buildOptions []string, readDigest bool, execRunner command.ExecRunner, fileUtils piperutils.FileUtils, commonPipelineEnvironment *kanikoExecuteCommonPipelineEnvironment) error {
cwd, err := fileUtils.Getwd()
if err != nil {
return fmt.Errorf("failed to get current working directory: %w", err)
Expand All @@ -379,6 +379,10 @@ func runKaniko(dockerFilepath string, buildOptions []string, readDigest bool, ex
kanikoOpts := []string{"--dockerfile", dockerFilepath, "--context", "dir://" + cwd}
kanikoOpts = append(kanikoOpts, buildOptions...)

for label, value := range config.Labels {
kanikoOpts = append(kanikoOpts, "--label", fmt.Sprintf("%s=%s", label, value))
}

tmpDir, err := fileUtils.TempDir("", "*-kanikoExecute")
if err != nil {
return fmt.Errorf("failed to create tmp dir for kanikoExecute: %w", err)
Expand Down
16 changes: 15 additions & 1 deletion cmd/kanikoExecute_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion resources/metadata/artifactPrepareVersion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ metadata:

The version is then either manually set by the team in the course of the development process or automatically pushed to master after a successful release.

Unlike for the _Continuous Deloyment_ pattern described above, in this case there is no dedicated tagging required for the build process since the version is already available in the repository.
Unlike for the _Continuous Deployment_ pattern described above, in this case there is no dedicated tagging required for the build process since the version is already available in the repository.

Configuration of this pattern is done via `versioningType: library`.

Expand Down Expand Up @@ -385,6 +385,8 @@ spec:
- name: git/commitId
- name: git/headCommitId
- name: git/commitMessage
- name: container/labels
type: map[string]interface{}
containers:
- image: maven:3.6-jdk-8
conditions:
Expand Down
15 changes: 14 additions & 1 deletion resources/metadata/kanikoExecute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
param: custom/buildSettingsInfo
- name: containerBuildOptions
type: string
description: Deprected, please use buildOptions. Defines the build options for the [kaniko](https://github.com/GoogleContainerTools/kaniko) build.
description: Deprecated, please use buildOptions. Defines the build options for the [kaniko](https://github.com/GoogleContainerTools/kaniko) build.
scope:
- PARAMETERS
- STAGES
Expand Down Expand Up @@ -306,6 +306,19 @@
- PARAMETERS
- STEPS
default: "https://github.com/anchore/syft/releases/download/v1.4.1/syft_1.4.1_linux_amd64.tar.gz"
- name: labels
type: map[string]interface{}
description: Map of labels to be added to the image. The key is the label name and the value is the label value.
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
default: []
scope:
- GENERAL

Check failure on line 315 in resources/metadata/kanikoExecute.yaml

View workflow job for this annotation

GitHub Actions / lint

315:9 [indentation] wrong indentation: expected 10 but found 8
- STEPS
- STAGES
- PARAMETERS
resourceRef:
- name: commonPipelineEnvironment

Check failure on line 320 in resources/metadata/kanikoExecute.yaml

View workflow job for this annotation

GitHub Actions / lint

320:9 [indentation] wrong indentation: expected 10 but found 8
param: container/labels
outputs:
resources:
- name: commonPipelineEnvironment
Expand Down
Loading