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

Commit 76b4d3c

Browse files
Add Uninstall command, to uninstall a claim from the duffle claim store.
It will run the Uninstall CNAB action in the cmd/run/uninstall.go to remove a Docker Application Package deployment. Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
1 parent daa2241 commit 76b4d3c

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

cmd/docker-app/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func newRootCmd(dockerCli *command.DockerCli) *cobra.Command {
4545
func addCommands(cmd *cobra.Command, dockerCli command.Cli) {
4646
cmd.AddCommand(
4747
installCmd(dockerCli),
48+
uninstallCmd(dockerCli),
4849
initCmd(),
4950
inspectCmd(dockerCli),
5051
mergeCmd(dockerCli),

cmd/docker-app/uninstall.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/deislabs/duffle/pkg/action"
7+
"github.com/deislabs/duffle/pkg/claim"
8+
"github.com/deislabs/duffle/pkg/credentials"
9+
"github.com/deislabs/duffle/pkg/utils/crud"
10+
"github.com/docker/cli/cli"
11+
"github.com/docker/cli/cli/command"
12+
"github.com/spf13/cobra"
13+
)
14+
15+
type uninstallOptions struct {
16+
targetContext string
17+
credentialsets []string
18+
}
19+
20+
func uninstallCmd(dockerCli command.Cli) *cobra.Command {
21+
var opts uninstallOptions
22+
23+
cmd := &cobra.Command{
24+
Use: "uninstall <installation-name>",
25+
Short: "Uninstall an application",
26+
Args: cli.ExactArgs(1),
27+
RunE: func(cmd *cobra.Command, args []string) error {
28+
return runUninstall(dockerCli, args[0], opts)
29+
},
30+
}
31+
32+
cmd.Flags().StringVar(&opts.targetContext, "target-context", "", "Context on which to uninstall the application")
33+
cmd.Flags().StringArrayVarP(&opts.credentialsets, "credential-set", "c", []string{}, "Use a duffle credentialset (either a YAML file, or a credential set present in the duffle credential store)")
34+
35+
return cmd
36+
}
37+
38+
func runUninstall(dockerCli command.Cli, claimName string, opts uninstallOptions) error {
39+
muteDockerCli(dockerCli)
40+
h := duffleHome()
41+
42+
claimStore := claim.NewClaimStore(crud.NewFileSystemStore(h.Claims(), "json"))
43+
c, err := claimStore.Read(claimName)
44+
if err != nil {
45+
return err
46+
}
47+
targetContext := getTargetContext(opts.targetContext)
48+
49+
driverImpl, err := prepareDriver(dockerCli)
50+
if err != nil {
51+
return err
52+
}
53+
creds, err := prepareCredentialSet(targetContext, dockerCli.ContextStore(), c.Bundle, opts.credentialsets)
54+
if err != nil {
55+
return err
56+
}
57+
if err := credentials.Validate(creds, c.Bundle.Credentials); err != nil {
58+
return err
59+
}
60+
uninst := &action.Uninstall{
61+
Driver: driverImpl,
62+
}
63+
err = uninst.Run(&c, creds, dockerCli.Out())
64+
if err == nil {
65+
return claimStore.Delete(claimName)
66+
}
67+
if err2 := claimStore.Store(c); err2 != nil {
68+
fmt.Fprintf(dockerCli.Err(), "failed to update claim: %s\n", err2)
69+
}
70+
return err
71+
}

0 commit comments

Comments
 (0)