Skip to content

Commit

Permalink
Merge pull request containers#5147 from nalind/small-fixups
Browse files Browse the repository at this point in the history
createConfigsAndManifests: clear history before cw-specific logic
  • Loading branch information
openshift-merge-bot[bot] authored Nov 9, 2023
2 parents 0f44269 + af394a8 commit 700882c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
23 changes: 12 additions & 11 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,18 @@ func (i *containerImageRef) createConfigsAndManifests() (v1.Image, v1.Manifest,
}
// Always replace this value, since we're newer than our base image.
dimage.Created = created
// Clear the list of diffIDs, since we always repopulate it.
dimage.RootFS = &docker.V2S2RootFS{}
dimage.RootFS.Type = docker.TypeLayers
dimage.RootFS.DiffIDs = []digest.Digest{}
// Only clear the history if we're squashing, otherwise leave it be so
// that we can append entries to it. Clear the parent, too, we no
// longer include its layers and history.
if i.confidentialWorkload.Convert || i.squash || i.omitHistory {
dimage.Parent = ""
dimage.History = []docker.V2S2History{}
}

// If we're producing a confidential workload, override the command and
// assorted other settings that aren't expected to work correctly.
if i.confidentialWorkload.Convert {
Expand All @@ -304,17 +316,6 @@ func (i *containerImageRef) createConfigsAndManifests() (v1.Image, v1.Manifest,
dimage.Config.ExposedPorts = nil
oimage.Config.ExposedPorts = nil
}
// Clear the list of diffIDs, since we always repopulate it.
dimage.RootFS = &docker.V2S2RootFS{}
dimage.RootFS.Type = docker.TypeLayers
dimage.RootFS.DiffIDs = []digest.Digest{}
// Only clear the history if we're squashing, otherwise leave it be so
// that we can append entries to it. Clear the parent, too, we no
// longer include its layers and history.
if i.confidentialWorkload.Convert || i.squash || i.omitHistory {
dimage.Parent = ""
dimage.History = []docker.V2S2History{}
}

// Build empty manifests. The Layers lists will be populated later.
omanifest := v1.Manifest{
Expand Down
3 changes: 2 additions & 1 deletion imagebuildah/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"sync"

"github.com/containerd/containerd/platforms"
"github.com/containers/buildah"
"github.com/containers/buildah/define"
internalUtil "github.com/containers/buildah/internal/util"
"github.com/containers/buildah/pkg/parse"
Expand Down Expand Up @@ -672,7 +673,7 @@ func baseImages(dockerfilenames []string, dockerfilecontents [][]byte, from stri
}
}
base := child.Next.Value
if base != "scratch" && !nicknames[base] {
if base != "" && base != buildah.BaseImageFakeName && !nicknames[base] {
headingArgs := argsMapToSlice(stage.Builder.HeadingArgs)
userArgs := argsMapToSlice(stage.Builder.Args)
// append heading args so if --build-arg key=value is not
Expand Down
2 changes: 1 addition & 1 deletion imagebuildah/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ func (b *Executor) Build(ctx context.Context, stages imagebuilder.Stages) (image
b.fromOverride = ""
}
base := child.Next.Value
if base != "scratch" {
if base != "" && base != buildah.BaseImageFakeName {
if replaceBuildContext, ok := b.additionalBuildContexts[child.Next.Value]; ok {
if replaceBuildContext.IsImage {
child.Next.Value = replaceBuildContext.Value
Expand Down
2 changes: 1 addition & 1 deletion new.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func newBuilder(ctx context.Context, store storage.Store, options BuilderOptions

systemContext := getSystemContext(store, options.SystemContext, options.SignaturePolicyPath)

if options.FromImage != "" && options.FromImage != "scratch" {
if options.FromImage != "" && options.FromImage != BaseImageFakeName {
imageRuntime, err := libimage.RuntimeFromStore(store, &libimage.RuntimeOptions{SystemContext: systemContext})
if err != nil {
return nil, err
Expand Down
7 changes: 7 additions & 0 deletions new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"testing"

"github.com/containers/storage"
"github.com/openshift/imagebuilder"
"github.com/stretchr/testify/assert"
)

func TestGetImageName(t *testing.T) {
Expand All @@ -26,3 +28,8 @@ func TestGetImageName(t *testing.T) {
}
}
}

func TestNoBaseImageSpecifierIsScratch(t *testing.T) {
assert.Equal(t, "scratch", imagebuilder.NoBaseImageSpecifier) // juuuuust in case
assert.Equal(t, "scratch", BaseImageFakeName)
}
8 changes: 2 additions & 6 deletions pkg/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,10 @@ func DefaultPlatform() string {
// Platform separates the platform string into os, arch and variant,
// accepting any of $arch, $os/$arch, or $os/$arch/$variant.
func Platform(platform string) (os, arch, variant string, err error) {
if platform == "local" || platform == "" || platform == "/" {
platform = strings.Trim(platform, "/")
if platform == "local" || platform == "" {
return Platform(DefaultPlatform())
}
if platform[len(platform)-1] == '/' || platform[0] == '/' {
// If --platform string has format as `some/plat/string/`
// or `/some/plat/string` make it `some/plat/string`
platform = strings.Trim(platform, "/")
}
platformSpec, err := platforms.Parse(platform)
if err != nil {
return "", "", "", fmt.Errorf("invalid platform syntax for --platform=%q: %w", platform, err)
Expand Down

0 comments on commit 700882c

Please sign in to comment.