This repository was archived by the owner on Jul 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathupdate.go
More file actions
106 lines (94 loc) · 3.08 KB
/
update.go
File metadata and controls
106 lines (94 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package commands
import (
"fmt"
"os"
"github.com/cnabio/cnab-go/driver"
"github.com/cnabio/cnab-go/action"
"github.com/cnabio/cnab-go/credentials"
"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"
)
type updateOptions struct {
cliopts.ParametersOptions
credentialOptions
bundleOrDockerApp string
}
func updateCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContextOptions) *cobra.Command {
var opts updateOptions
cmd := &cobra.Command{
Use: "update [OPTIONS] RUNNING_APP",
Short: "Update a running App",
Example: `$ docker app update myrunningapp --set key=value`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runUpdate(dockerCli, args[0], opts, installerContext)
},
}
opts.ParametersOptions.AddFlags(cmd.Flags())
opts.credentialOptions.addFlags(cmd.Flags())
cmd.Flags().StringVar(&opts.bundleOrDockerApp, "image", "", "Override the running App with another App image")
return cmd
}
func runUpdate(dockerCli command.Cli, installationName string, opts updateOptions, installerContext *cliopts.InstallerContextOptions) error {
imageStore, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
if err != nil {
return err
}
installation, err := installationStore.Read(installationName)
if err != nil {
return err
}
if IsInstallationFailed(installation) {
return fmt.Errorf("Running App %q cannot be updated, please use 'docker app run' instead", installationName)
}
if opts.bundleOrDockerApp != "" {
b, _, err := cnab.ResolveBundle(dockerCli, imageStore, opts.bundleOrDockerApp)
if err != nil {
return err
}
installation.Bundle = b.Bundle
}
if err := packager.CheckAppVersion(dockerCli.Err(), installation.Bundle); err != nil {
return err
}
if err := bundle.MergeBundleParameters(installation,
bundle.WithFileParameters(opts.ParametersFiles),
bundle.WithCommandLineParameters(opts.Overrides),
bundle.WithSendRegistryAuth(opts.sendRegistryAuth),
); err != nil {
return err
}
defer muteDockerCli(dockerCli)()
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, os.Stdout)
if err != nil {
return err
}
creds, err := prepareCredentialSet(installation.Bundle, opts.CredentialSetOpts(dockerCli, credentialStore)...)
if err != nil {
return err
}
if err := credentials.Validate(creds, installation.Bundle.Credentials); err != nil {
return err
}
u := &action.Upgrade{
Driver: driverImpl,
}
cfgFunc := func(op *driver.Operation) error {
op.Out = dockerCli.Out()
return nil
}
err = u.Run(&installation.Claim, creds, cfgFunc, cnab.WithRelocationMap(installation))
err2 := installationStore.Store(installation)
if err != nil {
return fmt.Errorf("Update failed: %s\n%s", err, errBuf)
}
if err2 != nil {
return err2
}
fmt.Fprintf(dockerCli.Out(), "Running App %q updated on context %q\n", installationName, dockerCli.CurrentContext())
return nil
}