Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.
Open
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
14 changes: 10 additions & 4 deletions internal/commands/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import (

"github.com/deislabs/cnab-go/action"
"github.com/deislabs/cnab-go/bundle"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/spf13/cobra"

"github.com/docker/app/internal"
"github.com/docker/app/internal/cliopts"
"github.com/docker/app/internal/cnab"
"github.com/docker/app/internal/inspect"
"github.com/docker/app/internal/packager"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/spf13/cobra"
"github.com/docker/app/internal/store"
)

const inspectExample = `- $ docker app inspect my-running-app
Expand Down Expand Up @@ -43,7 +45,11 @@ func inspectCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContex
}

func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOptions, installerContext *cliopts.InstallerContextOptions) error {
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
orchestrator, err := store.GetOrchestrator(dockerCli)
if err != nil {
return err
}
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext(), orchestrator)
if err != nil {
return err
}
Expand Down
15 changes: 10 additions & 5 deletions internal/commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import (
"time"

"github.com/deislabs/cnab-go/action"
"github.com/docker/app/internal"
"github.com/docker/app/internal/cliopts"
"github.com/docker/app/internal/cnab"
"github.com/docker/app/internal/store"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/config"
Expand All @@ -22,6 +18,11 @@ import (
"github.com/docker/go/canonical/json"
"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/docker/app/internal"
"github.com/docker/app/internal/cliopts"
"github.com/docker/app/internal/cnab"
"github.com/docker/app/internal/store"
)

var (
Expand Down Expand Up @@ -71,8 +72,12 @@ func runList(dockerCli command.Cli, opts listOptions, installerContext *cliopts.
if err != nil {
return err
}
orchestrator, err := store.GetOrchestrator(dockerCli)
if err != nil {
return err
}
targetContext := dockerCli.CurrentContext()
installationStore, err := appstore.InstallationStore(targetContext)
installationStore, err := appstore.InstallationStore(targetContext, orchestrator)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion internal/commands/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ func removeCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContext
Example: `$ docker app rm myrunningapp`,
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
orchestrator, err := store.GetOrchestrator(dockerCli)
if err != nil {
return err
}
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext(), orchestrator)
if err != nil {
return err
}
Expand Down
13 changes: 7 additions & 6 deletions internal/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import (
"os"

"github.com/deislabs/cnab-go/claim"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/config"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/docker/app/internal"
"github.com/docker/app/internal/cliopts"
"github.com/docker/app/internal/commands/build"
"github.com/docker/app/internal/commands/image"
"github.com/docker/app/internal/store"
appstore "github.com/docker/app/internal/store"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/config"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

type mainOptions struct {
Expand Down Expand Up @@ -105,12 +106,12 @@ func muteDockerCli(dockerCli command.Cli) func() {
}
}

func prepareStores(targetContext string) (store.ImageStore, store.InstallationStore, store.CredentialStore, error) {
func prepareStores(targetContext string, orchestrator command.Orchestrator) (store.ImageStore, store.InstallationStore, store.CredentialStore, error) {
appstore, err := store.NewApplicationStore(config.Dir())
if err != nil {
return nil, nil, nil, err
}
installationStore, err := appstore.InstallationStore(targetContext)
installationStore, err := appstore.InstallationStore(targetContext, orchestrator)
if err != nil {
return nil, nil, nil, err
}
Expand Down
24 changes: 13 additions & 11 deletions internal/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@ import (
"fmt"
"os"

"github.com/docker/app/internal/packager"

"github.com/docker/app/internal/image"

"github.com/deislabs/cnab-go/driver"
"github.com/docker/app/internal/cliopts"

"github.com/deislabs/cnab-go/action"
"github.com/deislabs/cnab-go/credentials"
bdl "github.com/docker/app/internal/bundle"
"github.com/docker/app/internal/cnab"
"github.com/docker/app/internal/store"
"github.com/deislabs/cnab-go/driver"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/pkg/namesgenerator"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

bdl "github.com/docker/app/internal/bundle"
"github.com/docker/app/internal/cliopts"
"github.com/docker/app/internal/cnab"
"github.com/docker/app/internal/image"
"github.com/docker/app/internal/packager"
"github.com/docker/app/internal/store"
)

type runOptions struct {
Expand Down Expand Up @@ -103,7 +101,11 @@ func runBundle(dockerCli command.Cli, bndl *image.AppImage, opts runOptions, ins
if err := packager.CheckAppVersion(dockerCli.Err(), bndl.Bundle); err != nil {
return err
}
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
orchestrator, err := store.GetOrchestrator(dockerCli)
if err != nil {
return err
}
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext(), orchestrator)
if err != nil {
return err
}
Expand Down
15 changes: 10 additions & 5 deletions internal/commands/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import (
"fmt"
"os"

"github.com/deislabs/cnab-go/driver"

"github.com/deislabs/cnab-go/action"
"github.com/deislabs/cnab-go/credentials"
"github.com/deislabs/cnab-go/driver"
"github.com/docker/cli/cli/command"
"github.com/spf13/cobra"

"github.com/docker/app/internal/bundle"
"github.com/docker/app/internal/cliopts"
"github.com/docker/app/internal/cnab"
"github.com/docker/app/internal/packager"
"github.com/docker/cli/cli/command"
"github.com/spf13/cobra"
"github.com/docker/app/internal/store"
)

type updateOptions struct {
Expand Down Expand Up @@ -41,7 +42,11 @@ func updateCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContext
}

func runUpdate(dockerCli command.Cli, installationName string, opts updateOptions, installerContext *cliopts.InstallerContextOptions) error {
imageStore, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
orchestrator, err := store.GetOrchestrator(dockerCli)
if err != nil {
return err
}
imageStore, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext(), orchestrator)
if err != nil {
return err
}
Expand Down
31 changes: 25 additions & 6 deletions internal/store/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import (
"os"
"path/filepath"

"github.com/deislabs/cnab-go/utils/crud"
cnabCrud "github.com/deislabs/cnab-go/utils/crud"
"github.com/docker/cli/cli/command"
digest "github.com/opencontainers/go-digest"
"github.com/pkg/errors"

appCrud "github.com/docker/app/internal/store/crud"
)

const (
Expand Down Expand Up @@ -51,12 +54,28 @@ func NewApplicationStore(configDir string) (*ApplicationStore, error) {
}

// InstallationStore initializes and returns a context based installation store
func (a ApplicationStore) InstallationStore(context string) (InstallationStore, error) {
path := filepath.Join(a.path, InstallationStoreDirectory, makeDigestedDirectory(context))
if err := os.MkdirAll(path, 0755); err != nil {
return nil, errors.Wrapf(err, "failed to create installation store directory for context %q", context)
func (a ApplicationStore) InstallationStore(context string, orchestrator command.Orchestrator) (InstallationStore, error) {
switch {
// FIXME What if orchestrator.HasKubernetes() and still want to use local store?
case orchestrator.HasKubernetes():
// FIXME Get this namespace, labelKey and labelValue dynamically through cli opts
k8sStore, err := appCrud.NewKubernetesSecretsStore(
appCrud.DefaultKubernetesNamespace,
appCrud.LabelKV{
appCrud.DefaultSecretLabelKey,
appCrud.DefaultSecretLabelValue,
})
if err != nil {
return nil, err
}
return &installationStore{store: k8sStore}, nil
default:
path := filepath.Join(a.path, InstallationStoreDirectory, makeDigestedDirectory(context))
if err := os.MkdirAll(path, 0755); err != nil {
return nil, errors.Wrapf(err, "failed to create installation store directory for context %q", context)
}
return &installationStore{store: cnabCrud.NewFileSystemStore(path, "json")}, nil
}
return &installationStore{store: crud.NewFileSystemStore(path, "json")}, nil
}

// CredentialStore initializes and returns a context based credential store
Expand Down
3 changes: 2 additions & 1 deletion internal/store/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package store
import (
"testing"

"github.com/docker/cli/cli/command"
"gotest.tools/assert"
"gotest.tools/fs"
)
Expand All @@ -17,7 +18,7 @@ func TestNewApplicationStoreInitializesDirectories(t *testing.T) {
assert.Equal(t, appstore.path, dockerConfigDir.Join("app"))

// an installation store is created per context
_, err = appstore.InstallationStore("my-context")
_, err = appstore.InstallationStore("my-context", command.OrchestratorSwarm)
assert.NilError(t, err)

// a credential store is created per context
Expand Down
Loading