本文整理汇总了Golang中github.com/docker/libcompose/config.ServiceConfigs.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang ServiceConfigs.Get方法的具体用法?Golang ServiceConfigs.Get怎么用?Golang ServiceConfigs.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/docker/libcompose/config.ServiceConfigs
的用法示例。
在下文中一共展示了ServiceConfigs.Get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ConvertToTaskDefinition
// ConvertToTaskDefinition transforms the yaml configs to its ecs equivalent (task definition)
func ConvertToTaskDefinition(taskDefinitionName string, context *project.Context,
serviceConfigs *config.ServiceConfigs) (*ecs.TaskDefinition, error) {
if serviceConfigs.Len() == 0 {
return nil, errors.New("cannot create a task definition with no containers; invalid service config")
}
logUnsupportedConfigFields(context.Project)
containerDefinitions := []*ecs.ContainerDefinition{}
volumes := make(map[string]string) // map with key:=hostSourcePath value:=VolumeName
for _, name := range serviceConfigs.Keys() {
serviceConfig, ok := serviceConfigs.Get(name)
if !ok {
return nil, fmt.Errorf("Couldn't get service with name=[%s]", name)
}
logUnsupportedServiceConfigFields(name, serviceConfig)
containerDef := &ecs.ContainerDefinition{
Name: aws.String(name),
}
if err := convertToContainerDef(context, serviceConfig, volumes, containerDef); err != nil {
return nil, err
}
containerDefinitions = append(containerDefinitions, containerDef)
}
taskDefinition := &ecs.TaskDefinition{
Family: aws.String(taskDefinitionName),
ContainerDefinitions: containerDefinitions,
Volumes: convertToECSVolumes(volumes),
}
return taskDefinition, nil
}
示例2: getVolumesFrom
func getVolumesFrom(volumesFrom []string, serviceConfigs *config.ServiceConfigs, projectName string) ([]string, error) {
volumes := []string{}
for _, volumeFrom := range volumesFrom {
if serviceConfig, ok := serviceConfigs.Get(volumeFrom); ok {
// It's a service - Use the first one
name := fmt.Sprintf("%s_%s_1", projectName, volumeFrom)
// If a container name is specified, use that instead
if serviceConfig.ContainerName != "" {
name = serviceConfig.ContainerName
}
volumes = append(volumes, name)
} else {
volumes = append(volumes, volumeFrom)
}
}
return volumes, nil
}
示例3: NetworksFromServices
// NetworksFromServices creates a new Networks struct based on networks configurations and
// services configuration. If a network is defined but not used by any service, it will return
// an error along the Networks.
func NetworksFromServices(cli client.NetworkAPIClient, projectName string, networkConfigs map[string]*config.NetworkConfig, services *config.ServiceConfigs, networkEnabled bool) (*Networks, error) {
var err error
networks := make([]*Network, 0, len(networkConfigs))
networkNames := map[string]*yaml.Network{}
for _, serviceName := range services.Keys() {
serviceConfig, _ := services.Get(serviceName)
if serviceConfig.NetworkMode != "" || serviceConfig.Networks == nil || len(serviceConfig.Networks.Networks) == 0 {
continue
}
for _, network := range serviceConfig.Networks.Networks {
if network.Name != "default" {
if _, ok := networkConfigs[network.Name]; !ok {
return nil, fmt.Errorf(`Service "%s" uses an undefined network "%s"`, serviceName, network.Name)
}
}
networkNames[network.Name] = network
}
}
for name, config := range networkConfigs {
network := NewNetwork(projectName, name, config, cli)
networks = append(networks, network)
}
if len(networkNames) != len(networks) {
unused := []string{}
for name := range networkConfigs {
if name == "default" {
continue
}
if _, ok := networkNames[name]; !ok {
unused = append(unused, name)
}
}
if len(unused) != 0 {
err = fmt.Errorf("Some networks were defined but are not used by any service: %v", strings.Join(unused, " "))
}
}
return &Networks{
networks: networks,
networkEnabled: networkEnabled,
}, err
}