mirror of
https://github.com/docker/cli.git
synced 2026-09-27 17:56:04 -04:00
add secret support for service update
- add nosuid and noexec to tmpfs
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
Upstream-commit: 8554b64b99
Component: cli
This commit is contained in:
@@ -557,4 +557,6 @@ const (
|
|||||||
flagHealthTimeout = "health-timeout"
|
flagHealthTimeout = "health-timeout"
|
||||||
flagNoHealthcheck = "no-healthcheck"
|
flagNoHealthcheck = "no-healthcheck"
|
||||||
flagSecret = "secret"
|
flagSecret = "secret"
|
||||||
|
flagSecretAdd = "secret-add"
|
||||||
|
flagSecretRemove = "secret-rm"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/cli"
|
"github.com/docker/docker/cli"
|
||||||
"github.com/docker/docker/cli/command"
|
"github.com/docker/docker/cli/command"
|
||||||
|
"github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/opts"
|
"github.com/docker/docker/opts"
|
||||||
runconfigopts "github.com/docker/docker/runconfig/opts"
|
runconfigopts "github.com/docker/docker/runconfig/opts"
|
||||||
"github.com/docker/go-connections/nat"
|
"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.labels, flagLabelAdd, "Add or update a service label")
|
||||||
flags.Var(&opts.containerLabels, flagContainerLabelAdd, "Add or update a container 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(&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.mounts, flagMountAdd, "Add or update a mount on a service")
|
||||||
flags.Var(&opts.constraints, flagConstraintAdd, "Add or update a placement constraint")
|
flags.Var(&opts.constraints, flagConstraintAdd, "Add or update a placement constraint")
|
||||||
flags.Var(&opts.endpoint.ports, flagPublishAdd, "Add or update a published port")
|
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
|
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
|
// only send auth if flag was set
|
||||||
sendAuth, err := flags.GetBool(flagRegistryAuth)
|
sendAuth, err := flags.GetBool(flagRegistryAuth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -401,6 +411,30 @@ func updateEnvironment(flags *pflag.FlagSet, field *[]string) {
|
|||||||
*field = removeItems(*field, toRemove, envKey)
|
*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 {
|
func envKey(value string) string {
|
||||||
kv := strings.SplitN(value, "=", 2)
|
kv := strings.SplitN(value, "=", 2)
|
||||||
return kv[0]
|
return kv[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user