Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #732 from rumpl/feat-push-local-store
Browse files Browse the repository at this point in the history
Only push applications from the local store
  • Loading branch information
rumpl authored Nov 12, 2019
2 parents c7927e1 + 1fd4785 commit cab6001
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
21 changes: 21 additions & 0 deletions e2e/pushpull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ import (
"gotest.tools/icmd"
)

func TestPushUnknown(t *testing.T) {
cmd, cleanup := dockerCli.createTestCmd()
defer cleanup()

t.Run("push unknown reference", func(t *testing.T) {
cmd.Command = dockerCli.Command("app", "push", "unknown")
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
ExitCode: 1,
Err: `could not push "unknown:latest": no such App image: failed to read bundle "docker.io/library/unknown:latest": unknown:latest: reference not found`,
})
})

t.Run("push invalid reference", func(t *testing.T) {
cmd.Command = dockerCli.Command("app", "push", "@")
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
ExitCode: 1,
Err: `could not push "@": invalid reference format`,
})
})
}

func TestPushInsecureRegistry(t *testing.T) {
runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) {
path := filepath.Join("testdata", "local")
Expand Down
24 changes: 13 additions & 11 deletions internal/commands/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/containerd/containerd/platforms"
"github.com/docker/app/internal"
"github.com/docker/app/internal/cnab"
"github.com/docker/app/internal/log"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
Expand Down Expand Up @@ -53,37 +52,40 @@ func pushCmd(dockerCli command.Cli) *cobra.Command {
}

func runPush(dockerCli command.Cli, name string) error {
defer muteDockerCli(dockerCli)()
bundleStore, err := prepareBundleStore()
if err != nil {
return err
}

defer muteDockerCli(dockerCli)()
// Get the bundle
bndl, ref, err := resolveReferenceAndBundle(dockerCli, bundleStore, name)
ref, err := reference.ParseDockerRef(name)
if err != nil {
return err
return errors.Wrapf(err, "could not push %q", name)
}

cnabRef, err := reference.ParseNormalizedNamed(ref)
bndl, err := resolveReferenceAndBundle(bundleStore, ref)
if err != nil {
return err
}
cnabRef = reference.TagNameOnly(cnabRef)

cnabRef := reference.TagNameOnly(ref)

// Push the bundle
return pushBundle(dockerCli, bndl, cnabRef)
}

func resolveReferenceAndBundle(dockerCli command.Cli, bundleStore store.BundleStore, name string) (*relocated.Bundle, string, error) {
bndl, ref, err := cnab.ResolveBundle(dockerCli, bundleStore, name)
func resolveReferenceAndBundle(bundleStore store.BundleStore, ref reference.Reference) (*relocated.Bundle, error) {
bndl, err := bundleStore.Read(ref)
if err != nil {
return nil, "", err
return nil, errors.Wrapf(err, "could not push %q: no such App image", reference.FamiliarString(ref))
}

if err := bndl.Validate(); err != nil {
return nil, "", err
return nil, err
}
return bndl, ref, err

return bndl, err
}

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

0 comments on commit cab6001

Please sign in to comment.