• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang config.ServiceConfigs类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/docker/libcompose/config.ServiceConfigs的典型用法代码示例。如果您正苦于以下问题:Golang ServiceConfigs类的具体用法?Golang ServiceConfigs怎么用?Golang ServiceConfigs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ServiceConfigs类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: RemoveOrphans

// RemoveOrphans implements project.RuntimeProject.RemoveOrphans.
// It will remove orphan containers that are part of the project but not to any services.
func (p *Project) RemoveOrphans(ctx context.Context, projectName string, serviceConfigs *config.ServiceConfigs) error {
	client := p.clientFactory.Create(nil)
	filter := filters.NewArgs()
	filter.Add("label", labels.PROJECT.EqString(projectName))
	containers, err := client.ContainerList(ctx, types.ContainerListOptions{
		Filter: filter,
	})
	if err != nil {
		return err
	}
	currentServices := map[string]struct{}{}
	for _, serviceName := range serviceConfigs.Keys() {
		currentServices[serviceName] = struct{}{}
	}
	for _, container := range containers {
		serviceLabel := container.Labels[labels.SERVICE.Str()]
		if _, ok := currentServices[serviceLabel]; !ok {
			if err := client.ContainerKill(ctx, container.ID, "SIGKILL"); err != nil {
				return err
			}
			if err := client.ContainerRemove(ctx, container.ID, types.ContainerRemoveOptions{
				Force: true,
			}); err != nil {
				return err
			}
		}
	}
	return nil
}
开发者ID:vdemeester,项目名称:libcompose,代码行数:31,代码来源:project.go


示例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
}
开发者ID:jainvipin,项目名称:libcompose,代码行数:17,代码来源:convert.go


示例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
}
开发者ID:jainvipin,项目名称:libcompose,代码行数:44,代码来源:network.go


示例4: 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
}
开发者ID:uttarasridhar,项目名称:amazon-ecs-cli,代码行数:34,代码来源:convert_task_definition.go



注:本文中的github.com/docker/libcompose/config.ServiceConfigs类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang docker.NewProject函数代码示例发布时间:2022-05-23
下一篇:
Golang app.WithProject函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap