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

[1.19] buildah manifest add localimage should work #2957

Merged
merged 2 commits into from
Feb 5, 2021
Merged
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
10 changes: 9 additions & 1 deletion cmd/buildah/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,15 @@ func manifestAddCmd(c *cobra.Command, args []string, opts manifestAddOpts) error

digest, err := list.Add(getContext(), systemContext, ref, opts.all)
if err != nil {
return err
var storeErr error
// check if the local image exists
if ref, _, storeErr = util.FindImage(store, "", systemContext, imageSpec); storeErr != nil {
return err
}
digest, storeErr = list.Add(getContext(), systemContext, ref, opts.all)
if storeErr != nil {
return err
}
}

if opts.os != "" {
Expand Down
20 changes: 10 additions & 10 deletions commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func checkRegistrySourcesAllows(forWhat string, dest types.ImageReference) (inse
return false, nil
}

func (b *Builder) addManifest(ctx context.Context, manifestName string, imageSpec string) error {
func (b *Builder) addManifest(ctx context.Context, manifestName string, imageSpec string) (string, error) {
var create bool
systemContext := &types.SystemContext{}
var list manifests.List
Expand All @@ -235,38 +235,35 @@ func (b *Builder) addManifest(ctx context.Context, manifestName string, imageSpe
} else {
_, list, err = manifests.LoadFromImage(b.store, listImage.ID)
if err != nil {
return err
return "", err
}
}

names, err := util.ExpandNames([]string{manifestName}, "", systemContext, b.store)
if err != nil {
return errors.Wrapf(err, "error encountered while expanding image name %q", manifestName)
return "", errors.Wrapf(err, "error encountered while expanding image name %q", manifestName)
}

ref, err := alltransports.ParseImageName(imageSpec)
if err != nil {
if ref, err = alltransports.ParseImageName(util.DefaultTransport + imageSpec); err != nil {
// check if the local image exists
if ref, _, err = util.FindImage(b.store, "", systemContext, imageSpec); err != nil {
return err
return "", err
}
}
}

if _, err = list.Add(ctx, systemContext, ref, true); err != nil {
return err
return "", err
}
var imageID string
if create {
imageID, err = list.SaveToImage(b.store, "", names, manifest.DockerV2ListMediaType)
} else {
imageID, err = list.SaveToImage(b.store, listImage.ID, nil, "")
}
if err == nil {
fmt.Printf("%s\n", imageID)
}
return err
return imageID, err
}

// Commit writes the contents of the container, along with its updated
Expand Down Expand Up @@ -489,9 +486,12 @@ func (b *Builder) Commit(ctx context.Context, dest types.ImageReference, options
}

if options.Manifest != "" {
if err := b.addManifest(ctx, options.Manifest, imgID); err != nil {
manifestID, err := b.addManifest(ctx, options.Manifest, imgID)
if err != nil {
return imgID, nil, "", err
}
logrus.Debugf("added imgID %s to manifestID %s", imgID, manifestID)

}
return imgID, ref, manifestDigest, nil
}
Expand Down
2 changes: 2 additions & 0 deletions imagebuildah/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ type Executor struct {
imageInfoLock sync.Mutex
imageInfoCache map[string]imageTypeAndHistoryAndDiffIDs
fromOverride string
manifest string
}

type imageTypeAndHistoryAndDiffIDs struct {
Expand Down Expand Up @@ -231,6 +232,7 @@ func NewExecutor(store storage.Store, options BuildOptions, mainNode *parser.Nod
logRusage: options.LogRusage,
imageInfoCache: make(map[string]imageTypeAndHistoryAndDiffIDs),
fromOverride: options.From,
manifest: options.Manifest,
}
if exec.err == nil {
exec.err = os.Stderr
Expand Down
1 change: 1 addition & 0 deletions imagebuildah/stage_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,7 @@ func (s *StageExecutor) commit(ctx context.Context, createdBy string, emptyLayer
MaxRetries: s.executor.maxPullPushRetries,
RetryDelay: s.executor.retryPullPushDelay,
HistoryTimestamp: s.executor.timestamp,
Manifest: s.executor.manifest,
}
imgID, _, manifestDigest, err := s.builder.Commit(ctx, imageRef, options)
if err != nil {
Expand Down
50 changes: 47 additions & 3 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,9 @@ function _test_http() {
starthttpd "${TESTSDIR}/bud/$testdir"
target=scratch-image
run_buildah bud --signature-policy ${TESTSDIR}/policy.json \
-t ${target} \
"$@" \
http://0.0.0.0:${HTTP_SERVER_PORT}/$urlpath
-t ${target} \
"$@" \
http://0.0.0.0:${HTTP_SERVER_PORT}/$urlpath
stophttpd
run_buildah from ${target}
}
Expand Down Expand Up @@ -2507,3 +2507,47 @@ _EOF
# run_buildah run $cid arch
# expect_output --substring "aarch64"
}

@test "bud with --manifest flag new manifest" {
_prefetch alpine
mytmpdir=${TESTDIR}/my-dir
mkdir -p ${mytmpdir}
cat > $mytmpdir/Containerfile << _EOF
from alpine
run echo hello
_EOF

run_buildah bud -q --manifest=testlist -t arch-test --signature-policy ${TESTSDIR}/policy.json ${mytmpdir} <<< input
cid=$output
run_buildah images
expect_output --substring testlist

run_buildah inspect --format '{{ .FromImageDigest }}' $cid
digest=$output

run_buildah manifest inspect testlist
expect_output --substring $digest
}

@test "bud with --manifest flag existing manifest" {
_prefetch alpine
mytmpdir=${TESTDIR}/my-dir
mkdir -p ${mytmpdir}
cat > $mytmpdir/Containerfile << _EOF
from alpine
run echo hello
_EOF

run_buildah manifest create testlist

run_buildah bud -q --manifest=testlist -t arch-test --signature-policy ${TESTSDIR}/policy.json ${mytmpdir} <<< input
cid=$output
run_buildah images
expect_output --substring testlist

run_buildah inspect --format '{{ .FromImageDigest }}' $cid
digest=$output

run_buildah manifest inspect testlist
expect_output --substring $digest
}
7 changes: 7 additions & 0 deletions tests/lists.bats
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ IMAGE_LIST_S390X_INSTANCE_DIGEST=sha256:882a20ee0df7399a445285361d38b711c299ca09
run_buildah manifest add foo ${IMAGE_LIST}
}

@test "manifest-add local image" {
target=scratch-image
run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch
run_buildah manifest create foo
run_buildah manifest add foo ${target}
}

@test "manifest-add-one" {
run_buildah manifest create foo
run_buildah manifest add --arch=arm64 foo ${IMAGE_LIST_INSTANCE}
Expand Down