runCreate creates a config with the given options.
(ctx context.Context, dockerCLI command.Cli, options createOptions)
| 66 | |
| 67 | // runCreate creates a config with the given options. |
| 68 | func runCreate(ctx context.Context, dockerCLI command.Cli, options createOptions) error { |
| 69 | apiClient := dockerCLI.Client() |
| 70 | |
| 71 | configData, err := readConfigData(dockerCLI.In(), options.file) |
| 72 | if err != nil { |
| 73 | return fmt.Errorf("error reading content from %q: %v", options.file, err) |
| 74 | } |
| 75 | |
| 76 | spec := swarm.ConfigSpec{ |
| 77 | Annotations: swarm.Annotations{ |
| 78 | Name: options.name, |
| 79 | Labels: opts.ConvertKVStringsToMap(options.labels.GetSlice()), |
| 80 | }, |
| 81 | Data: configData, |
| 82 | } |
| 83 | if options.templateDriver != "" { |
| 84 | spec.Templating = &swarm.Driver{ |
| 85 | Name: options.templateDriver, |
| 86 | } |
| 87 | } |
| 88 | r, err := apiClient.ConfigCreate(ctx, client.ConfigCreateOptions{ |
| 89 | Spec: spec, |
| 90 | }) |
| 91 | if err != nil { |
| 92 | return err |
| 93 | } |
| 94 | |
| 95 | _, _ = fmt.Fprintln(dockerCLI.Out(), r.ID) |
| 96 | return nil |
| 97 | } |
| 98 | |
| 99 | // maxConfigSize is the maximum byte length of the [swarm.ConfigSpec.Data] field, |
| 100 | // as defined by [MaxConfigSize] in SwarmKit. |
no test coverage detected
searching dependent graphs…