MCPcopy Index your code
hub / github.com/docker/cli / runCreate

Function runCreate

cli/command/service/create.go:96–150  ·  view source on GitHub ↗
(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts *serviceOptions)

Source from the content-addressed store, hash-verified

94}
95
96func runCreate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts *serviceOptions) error {
97 apiClient := dockerCLI.Client()
98
99 service, err := opts.ToService(ctx, apiClient, flags)
100 if err != nil {
101 return err
102 }
103
104 specifiedSecrets := opts.secrets.Value()
105 if len(specifiedSecrets) > 0 {
106 // parse and validate secrets
107 secrets, err := ParseSecrets(ctx, apiClient, specifiedSecrets)
108 if err != nil {
109 return err
110 }
111 service.TaskTemplate.ContainerSpec.Secrets = secrets
112 }
113
114 if err := setConfigs(ctx, apiClient, &service, opts); err != nil {
115 return err
116 }
117
118 // only send auth if flag was set
119 var encodedAuth string
120 if opts.registryAuth {
121 // Retrieve encoded auth token from the image reference
122 var err error
123 encodedAuth, err = command.RetrieveAuthTokenFromImage(dockerCLI.ConfigFile(), opts.image)
124 if err != nil {
125 return err
126 }
127 }
128
129 response, err := apiClient.ServiceCreate(ctx, client.ServiceCreateOptions{
130 Spec: service,
131
132 EncodedRegistryAuth: encodedAuth,
133 QueryRegistry: !opts.noResolveImage, // query registry if flag disabling it was not set.
134 })
135 if err != nil {
136 return err
137 }
138
139 for _, warning := range response.Warnings {
140 _, _ = fmt.Fprintln(dockerCLI.Err(), warning)
141 }
142
143 _, _ = fmt.Fprintln(dockerCLI.Out(), response.ID)
144
145 if opts.detach {
146 return nil
147 }
148
149 return WaitOnService(ctx, dockerCLI, response.ID, opts.quiet)
150}
151
152// setConfigs does double duty: it both sets the ConfigReferences of the
153// service, and it sets the service CredentialSpec. This is because there is an

Callers 1

newCreateCommandFunction · 0.70

Calls 9

ParseSecretsFunction · 0.85
setConfigsFunction · 0.85
WaitOnServiceFunction · 0.85
ToServiceMethod · 0.80
ClientMethod · 0.65
ValueMethod · 0.65
ConfigFileMethod · 0.65
ErrMethod · 0.65
OutMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…