本文整理汇总了Golang中github.com/docker/engine-api/types.ServiceUpdateOptions.EncodedRegistryAuth方法的典型用法代码示例。如果您正苦于以下问题:Golang ServiceUpdateOptions.EncodedRegistryAuth方法的具体用法?Golang ServiceUpdateOptions.EncodedRegistryAuth怎么用?Golang ServiceUpdateOptions.EncodedRegistryAuth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/docker/engine-api/types.ServiceUpdateOptions
的用法示例。
在下文中一共展示了ServiceUpdateOptions.EncodedRegistryAuth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: deployServices
func deployServices(
ctx context.Context,
dockerCli *client.DockerCli,
services map[string]bundlefile.Service,
namespace string,
sendAuth bool,
) error {
apiClient := dockerCli.Client()
out := dockerCli.Out()
existingServices, err := getServices(ctx, apiClient, namespace)
if err != nil {
return err
}
existingServiceMap := make(map[string]swarm.Service)
for _, service := range existingServices {
existingServiceMap[service.Spec.Name] = service
}
for internalName, service := range services {
name := fmt.Sprintf("%s_%s", namespace, internalName)
var ports []swarm.PortConfig
for _, portSpec := range service.Ports {
ports = append(ports, swarm.PortConfig{
Protocol: swarm.PortConfigProtocol(portSpec.Protocol),
TargetPort: portSpec.Port,
})
}
serviceSpec := swarm.ServiceSpec{
Annotations: swarm.Annotations{
Name: name,
Labels: getStackLabels(namespace, service.Labels),
},
TaskTemplate: swarm.TaskSpec{
ContainerSpec: swarm.ContainerSpec{
Image: service.Image,
Command: service.Command,
Args: service.Args,
Env: service.Env,
// Service Labels will not be copied to Containers
// automatically during the deployment so we apply
// it here.
Labels: getStackLabels(namespace, nil),
},
},
EndpointSpec: &swarm.EndpointSpec{
Ports: ports,
},
Networks: convertNetworks(service.Networks, namespace, internalName),
}
cspec := &serviceSpec.TaskTemplate.ContainerSpec
if service.WorkingDir != nil {
cspec.Dir = *service.WorkingDir
}
if service.User != nil {
cspec.User = *service.User
}
encodedAuth := ""
if sendAuth {
// Retrieve encoded auth token from the image reference
image := serviceSpec.TaskTemplate.ContainerSpec.Image
encodedAuth, err = dockerCli.RetrieveAuthTokenFromImage(ctx, image)
if err != nil {
return err
}
}
if service, exists := existingServiceMap[name]; exists {
fmt.Fprintf(out, "Updating service %s (id: %s)\n", name, service.ID)
updateOpts := types.ServiceUpdateOptions{}
if sendAuth {
updateOpts.EncodedRegistryAuth = encodedAuth
}
if err := apiClient.ServiceUpdate(
ctx,
service.ID,
service.Version,
serviceSpec,
updateOpts,
); err != nil {
return err
}
} else {
fmt.Fprintf(out, "Creating service %s\n", name)
createOpts := types.ServiceCreateOptions{}
if sendAuth {
createOpts.EncodedRegistryAuth = encodedAuth
}
if _, err := apiClient.ServiceCreate(ctx, serviceSpec, createOpts); err != nil {
return err
}
}
}
//.........这里部分代码省略.........