Skip to content

Commit

Permalink
Merge pull request containers#3963 from nalind/label-compat
Browse files Browse the repository at this point in the history
Make `buildah build --label foo` create an empty "foo" label again
  • Loading branch information
rhatdan committed May 4, 2022
2 parents f621d47 + fccc789 commit 39c3e2f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/buildah-build.1.md
Expand Up @@ -41,7 +41,7 @@ Instead of building for a set of platforms specified using the **--platform** op
**--annotation** *annotation[=value]*

Add an image *annotation* (e.g. annotation=*value*) to the image metadata. Can be used multiple times.
If *annotation* is named, but neither `=` nor a `value` is provided, then the *annotation* is removed from the image.
If *annotation* is named, but neither `=` nor a `value` is provided, then the *annotation* is set to an empty value.

Note: this information is not present in Docker image formats, so it is discarded when writing images in Docker formats.

Expand Down Expand Up @@ -339,7 +339,7 @@ no limit on the number of jobs that run in parallel.
**--label** *label[=value]*

Add an image *label* (e.g. label=*value*) to the image metadata. Can be used multiple times.
If *label* is named, but neither `=` nor a `value` is provided, then the *label* is removed from the image.
If *label* is named, but neither `=` nor a `value` is provided, then the *label* is set to an empty value.

Users can set a special LABEL **io.containers.capabilities=CAP1,CAP2,CAP3** in
a Containerfile that specifies the list of Linux capabilities required for the
Expand Down
4 changes: 2 additions & 2 deletions imagebuildah/stage_executor.go
Expand Up @@ -1564,15 +1564,15 @@ func (s *StageExecutor) commit(ctx context.Context, createdBy string, emptyLayer
if len(label) > 1 {
s.builder.SetLabel(label[0], label[1])
} else {
s.builder.UnsetLabel(label[0])
s.builder.SetLabel(label[0], "")
}
}
for _, annotationSpec := range s.executor.annotations {
annotation := strings.SplitN(annotationSpec, "=", 2)
if len(annotation) > 1 {
s.builder.SetAnnotation(annotation[0], annotation[1])
} else {
s.builder.UnsetAnnotation(annotation[0])
s.builder.SetAnnotation(annotation[0], "")
}
}
if imageRef != nil {
Expand Down
12 changes: 2 additions & 10 deletions tests/bud.bats
Expand Up @@ -717,13 +717,8 @@ _EOF
run_buildah inspect --format '{{printf "%q" .Docker.Config.Labels}}' ${target}
expect_output "$want_output"

want_output='map["io.buildah.version":"'$buildah_version'"]'
run_buildah build --label "test=label" --label test $WITH_POLICY_JSON -t ${target} $BUDFILES/from-scratch
run_buildah inspect --format '{{printf "%q" .Docker.Config.Labels}}' ${target}
expect_output "$want_output"

want_output='map[]'
run_buildah build --label io.buildah.version $WITH_POLICY_JSON -t ${target} $BUDFILES/from-scratch
want_output='map["io.buildah.version":"'$buildah_version'" "test":""]'
run_buildah build --label test $WITH_POLICY_JSON -t ${target} $BUDFILES/from-scratch
run_buildah inspect --format '{{printf "%q" .Docker.Config.Labels}}' ${target}
expect_output "$want_output"
}
Expand All @@ -748,9 +743,6 @@ _EOF
run_buildah build --annotation "test=annotation1,annotation2=z" $WITH_POLICY_JSON -t ${target} $BUDFILES/from-scratch
run_buildah inspect --format '{{index .ImageAnnotations "test"}}' ${target}
expect_output "annotation1,annotation2=z"
run_buildah build --annotation "test=annotation1,annotation2=z" --annotation test $WITH_POLICY_JSON -t ${target} $BUDFILES/from-scratch
run_buildah inspect --format '{{index .ImageAnnotations "test"}}' ${target}
expect_output ""
}

@test "bud-from-scratch-layers" {
Expand Down

0 comments on commit 39c3e2f

Please sign in to comment.