Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit cab6001

Browse files
authored
Merge pull request #732 from rumpl/feat-push-local-store
Only push applications from the local store
2 parents c7927e1 + 1fd4785 commit cab6001

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

e2e/pushpull_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,27 @@ import (
1111
"gotest.tools/icmd"
1212
)
1313

14+
func TestPushUnknown(t *testing.T) {
15+
cmd, cleanup := dockerCli.createTestCmd()
16+
defer cleanup()
17+
18+
t.Run("push unknown reference", func(t *testing.T) {
19+
cmd.Command = dockerCli.Command("app", "push", "unknown")
20+
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
21+
ExitCode: 1,
22+
Err: `could not push "unknown:latest": no such App image: failed to read bundle "docker.io/library/unknown:latest": unknown:latest: reference not found`,
23+
})
24+
})
25+
26+
t.Run("push invalid reference", func(t *testing.T) {
27+
cmd.Command = dockerCli.Command("app", "push", "@")
28+
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
29+
ExitCode: 1,
30+
Err: `could not push "@": invalid reference format`,
31+
})
32+
})
33+
}
34+
1435
func TestPushInsecureRegistry(t *testing.T) {
1536
runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) {
1637
path := filepath.Join("testdata", "local")

internal/commands/push.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"github.com/containerd/containerd/platforms"
1515
"github.com/docker/app/internal"
16-
"github.com/docker/app/internal/cnab"
1716
"github.com/docker/app/internal/log"
1817
"github.com/docker/cli/cli"
1918
"github.com/docker/cli/cli/command"
@@ -53,37 +52,40 @@ func pushCmd(dockerCli command.Cli) *cobra.Command {
5352
}
5453

5554
func runPush(dockerCli command.Cli, name string) error {
55+
defer muteDockerCli(dockerCli)()
5656
bundleStore, err := prepareBundleStore()
5757
if err != nil {
5858
return err
5959
}
6060

61-
defer muteDockerCli(dockerCli)()
6261
// Get the bundle
63-
bndl, ref, err := resolveReferenceAndBundle(dockerCli, bundleStore, name)
62+
ref, err := reference.ParseDockerRef(name)
6463
if err != nil {
65-
return err
64+
return errors.Wrapf(err, "could not push %q", name)
6665
}
6766

68-
cnabRef, err := reference.ParseNormalizedNamed(ref)
67+
bndl, err := resolveReferenceAndBundle(bundleStore, ref)
6968
if err != nil {
7069
return err
7170
}
72-
cnabRef = reference.TagNameOnly(cnabRef)
71+
72+
cnabRef := reference.TagNameOnly(ref)
7373

7474
// Push the bundle
7575
return pushBundle(dockerCli, bndl, cnabRef)
7676
}
7777

78-
func resolveReferenceAndBundle(dockerCli command.Cli, bundleStore store.BundleStore, name string) (*relocated.Bundle, string, error) {
79-
bndl, ref, err := cnab.ResolveBundle(dockerCli, bundleStore, name)
78+
func resolveReferenceAndBundle(bundleStore store.BundleStore, ref reference.Reference) (*relocated.Bundle, error) {
79+
bndl, err := bundleStore.Read(ref)
8080
if err != nil {
81-
return nil, "", err
81+
return nil, errors.Wrapf(err, "could not push %q: no such App image", reference.FamiliarString(ref))
8282
}
83+
8384
if err := bndl.Validate(); err != nil {
84-
return nil, "", err
85+
return nil, err
8586
}
86-
return bndl, ref, err
87+
88+
return bndl, err
8789
}
8890

8991
func pushBundle(dockerCli command.Cli, bndl *relocated.Bundle, cnabRef reference.Named) error {

0 commit comments

Comments
 (0)