Add output for "secrets" and "configs" on stack deploy

When deploying a stack from a compose file, the output did not show
that a secret or config was created. This patch adds messages for these.

Create a configuration file and compose file:

    $ cat > config.yml <<EOF
    hello: world
    EOF

    $ cat > secret.txt <<EOF
    p@ssw0rd
    EOF

    $ cat > docker-compose.yml <<EOF
    version: "3.3"
    services:
       test:
         image: nginx:alpine
         configs:
         - source: myconfig
           target: /my-config.yml
         secrets:
         - source: mysecret
           target: /my-secret.txt
    configs:
      myconfig:
        file: ./config.yml
    secrets:
      mysecret:
        file: ./secret.txt
    EOF

Before this patch is applied:

    $ docker stack deploy -c docker-compose.yml example
    Creating network example_default
    Creating service example_test

After this patch is applied:

    $ docker stack deploy -c docker-compose.yml example
    Creating network example_default
    Creating secret example_mysecret
    Creating config example_myconfig
    Creating service example_test

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2017-10-03 11:30:45 +02:00
parent 448d56a491
commit a5113f4368
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 2 additions and 0 deletions

View File

@ -224,6 +224,7 @@ func createSecrets(
} }
case apiclient.IsErrSecretNotFound(err): case apiclient.IsErrSecretNotFound(err):
// secret does not exist, then we create a new one. // secret does not exist, then we create a new one.
fmt.Fprintf(dockerCli.Out(), "Creating secret %s\n", secretSpec.Name)
if _, err := client.SecretCreate(ctx, secretSpec); err != nil { if _, err := client.SecretCreate(ctx, secretSpec); err != nil {
return errors.Wrapf(err, "failed to create secret %s", secretSpec.Name) return errors.Wrapf(err, "failed to create secret %s", secretSpec.Name)
} }
@ -251,6 +252,7 @@ func createConfigs(
} }
case apiclient.IsErrConfigNotFound(err): case apiclient.IsErrConfigNotFound(err):
// config does not exist, then we create a new one. // config does not exist, then we create a new one.
fmt.Fprintf(dockerCli.Out(), "Creating config %s\n", configSpec.Name)
if _, err := client.ConfigCreate(ctx, configSpec); err != nil { if _, err := client.ConfigCreate(ctx, configSpec); err != nil {
errors.Wrapf(err, "failed to create config %s", configSpec.Name) errors.Wrapf(err, "failed to create config %s", configSpec.Name)
} }