mirror of https://github.com/docker/cli.git
add secret support for service update
- add nosuid and noexec to tmpfs Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
parent
4e8f1a7dd9
commit
8554b64b99
|
@ -557,4 +557,6 @@ const (
|
|||
flagHealthTimeout = "health-timeout"
|
||||
flagNoHealthcheck = "no-healthcheck"
|
||||
flagSecret = "secret"
|
||||
flagSecretAdd = "secret-add"
|
||||
flagSecretRemove = "secret-rm"
|
||||
)
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/opts"
|
||||
runconfigopts "github.com/docker/docker/runconfig/opts"
|
||||
"github.com/docker/go-connections/nat"
|
||||
|
@ -54,6 +55,8 @@ func newUpdateCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|||
flags.Var(&opts.labels, flagLabelAdd, "Add or update a service label")
|
||||
flags.Var(&opts.containerLabels, flagContainerLabelAdd, "Add or update a container label")
|
||||
flags.Var(&opts.env, flagEnvAdd, "Add or update an environment variable")
|
||||
flags.Var(newListOptsVar(), flagSecretRemove, "Remove a secret")
|
||||
flags.StringSliceVar(&opts.secrets, flagSecretAdd, []string{}, "Add a secret")
|
||||
flags.Var(&opts.mounts, flagMountAdd, "Add or update a mount on a service")
|
||||
flags.Var(&opts.constraints, flagConstraintAdd, "Add or update a placement constraint")
|
||||
flags.Var(&opts.endpoint.ports, flagPublishAdd, "Add or update a published port")
|
||||
|
@ -97,6 +100,13 @@ func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, serviceID str
|
|||
return err
|
||||
}
|
||||
|
||||
updatedSecrets, err := getUpdatedSecrets(apiClient, flags, spec.TaskTemplate.ContainerSpec.Secrets)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
spec.TaskTemplate.ContainerSpec.Secrets = updatedSecrets
|
||||
|
||||
// only send auth if flag was set
|
||||
sendAuth, err := flags.GetBool(flagRegistryAuth)
|
||||
if err != nil {
|
||||
|
@ -401,6 +411,30 @@ func updateEnvironment(flags *pflag.FlagSet, field *[]string) {
|
|||
*field = removeItems(*field, toRemove, envKey)
|
||||
}
|
||||
|
||||
func getUpdatedSecrets(apiClient client.APIClient, flags *pflag.FlagSet, secrets []*swarm.SecretReference) ([]*swarm.SecretReference, error) {
|
||||
if flags.Changed(flagSecretAdd) {
|
||||
values, err := flags.GetStringSlice(flagSecretAdd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
addSecrets, err := parseSecrets(apiClient, values)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
secrets = append(secrets, addSecrets...)
|
||||
}
|
||||
toRemove := buildToRemoveSet(flags, flagSecretRemove)
|
||||
newSecrets := []*swarm.SecretReference{}
|
||||
for _, secret := range secrets {
|
||||
if _, exists := toRemove[secret.SecretName]; !exists {
|
||||
newSecrets = append(newSecrets, secret)
|
||||
}
|
||||
}
|
||||
|
||||
return newSecrets, nil
|
||||
}
|
||||
|
||||
func envKey(value string) string {
|
||||
kv := strings.SplitN(value, "=", 2)
|
||||
return kv[0]
|
||||
|
|
Loading…
Reference in New Issue