当前位置: 首页>>代码示例>>Golang>>正文


Golang APIProject.GetServiceConfig方法代码示例

本文整理汇总了Golang中github.com/docker/libcompose/project.APIProject.GetServiceConfig方法的典型用法代码示例。如果您正苦于以下问题:Golang APIProject.GetServiceConfig方法的具体用法?Golang APIProject.GetServiceConfig怎么用?Golang APIProject.GetServiceConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/docker/libcompose/project.APIProject的用法示例。


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

示例1: createShipment

func createShipment(username string, token string, shipmentName string, dockerCompose DockerCompose, shipment ComposeShipment, dockerComposeProject project.APIProject) {
	userName, token, _ := Login()

	//map a ComposeShipment object (based on compose files) into
	//a new NewShipmentEnvironment object

	if Verbose {
		log.Println("creating shipment environment")
	}

	//create object used to create a new shipment environment from scratch
	newShipment := NewShipmentEnvironment{
		Username: userName,
		Token:    token,
		Info: NewShipmentInfo{
			Name:  shipmentName,
			Group: shipment.Group,
		},
	}

	//add shipment-level env vars
	newShipment.Info.Vars = make([]EnvVarPayload, 0)
	newShipment.Info.Vars = append(newShipment.Info.Vars, envVar("CUSTOMER", shipment.Group))
	newShipment.Info.Vars = append(newShipment.Info.Vars, envVar("PROPERTY", shipment.Property))
	newShipment.Info.Vars = append(newShipment.Info.Vars, envVar("PROJECT", shipment.Project))
	newShipment.Info.Vars = append(newShipment.Info.Vars, envVar("PRODUCT", shipment.Product))

	//create environment
	newShipment.Environment = NewEnvironment{
		Name: shipment.Env,
		Vars: make([]EnvVarPayload, 0),
	}

	//add environment-level env vars
	for name, value := range shipment.Environment {
		newShipment.Environment.Vars = append(newShipment.Environment.Vars, envVar(name, value))
	}

	//containers

	//iterate defined containers and apply container level updates
	newShipment.Containers = make([]NewContainer, 0)
	for containerIndex, container := range shipment.Containers {

		if Verbose {
			log.Printf("processing container: %v", container)
		}

		//lookup the container in the list of services in the docker-compose file
		dockerService := dockerCompose.Services[container]

		if dockerService.Image == "" {
			log.Fatalln("'image' is required in docker compose file")
		}

		//parse image:tag and map to name/version
		parsedImage := strings.Split(dockerService.Image, ":")

		newContainer := NewContainer{
			Name:    container,
			Image:   dockerService.Image,
			Version: parsedImage[1],
			Vars:    make([]EnvVarPayload, 0),
			Ports:   make([]PortPayload, 0),
		}

		//container-level env vars

		serviceConfig, success := dockerComposeProject.GetServiceConfig(newContainer.Name)
		if !success {
			log.Fatal("error getting service config")
		}

		envVarMap := serviceConfig.Environment.ToMap()

		for name, value := range envVarMap {
			if name != "" {
				if Verbose {
					log.Println("processing " + name)
				}
				newContainer.Vars = append(newContainer.Vars, envVar(name, value))
			}
		}

		//map the docker compose service ports to harbor ports
		if len(dockerService.Ports) == 0 {
			log.Fatalln("At least one port mapping is required in docker compose file.")
		}

		parsedPort := strings.Split(dockerService.Ports[0], ":")

		//validate health check
		healthCheck := dockerService.Environment["HEALTHCHECK"]
		if healthCheck == "" {
			log.Fatalln("A container-level 'HEALTHCHECK' environment variable is required")
		}

		//map first port in docker compose to default primary HTTP "PORT"

		external, err := strconv.Atoi(parsedPort[0])
//.........这里部分代码省略.........
开发者ID:turnerlabs,项目名称:harbor-compose,代码行数:101,代码来源:up.go

示例2: updateShipment

func updateShipment(username string, token string, currentShipment *ShipmentEnvironment, shipmentName string, dockerCompose DockerCompose, shipment ComposeShipment, dockerComposeProject project.APIProject) {

	//map a ComposeShipment object (based on compose files) into
	//a series of API call to update a shipment

	//iterate defined containers and apply container level updates
	for _, container := range shipment.Containers {
		if Verbose {
			log.Printf("processing container: %v", container)
		}

		//lookup the container in the list of services in the docker-compose file
		dockerService := dockerCompose.Services[container]

		//update the shipment/container with the new image
		if !shipment.IgnoreImageVersion {
			UpdateContainerImage(username, token, shipmentName, shipment, container, dockerService)
		}

		serviceConfig, success := dockerComposeProject.GetServiceConfig(container)
		if !success {
			log.Fatal("error getting service config")
		}

		envVarMap := serviceConfig.Environment.ToMap()

		for evName, evValue := range envVarMap {
			if evName != "" {
				if Verbose {
					log.Println("processing " + evName)
				}

				//create an envvar object
				envVarPayload := envVar(evName, evValue)

				//save the envvar
				SaveEnvVar(username, token, shipmentName, shipment, envVarPayload, container)
			}
		}

	}

	//convert the specified barge into an env var
	if len(shipment.Barge) > 0 {

		//initialize the environment map if it doesn't exist
		if shipment.Environment == nil {
			shipment.Environment = make(map[string]string)
		}

		//set the BARGE env var
		shipment.Environment["BARGE"] = shipment.Barge
	}

	//update shipment/environment-level envvars
	for evName, evValue := range shipment.Environment {

		if Verbose {
			log.Println("processing " + evName)
		}

		//create an envvar object
		envVarPayload := envVar(evName, evValue)

		//save the envvar
		SaveEnvVar(username, token, shipmentName, shipment, envVarPayload, "")

	} //envvars

	//update shipment level configuration
	UpdateShipment(username, token, shipmentName, shipment)

	//trigger shipment
	_, messages := Trigger(shipmentName, shipment.Env)

	for _, msg := range messages {
		fmt.Println(msg)
	}

	//if replicas is changing from 0, then show wait messages
	if ec2Provider(currentShipment.Providers).Replicas == 0 {
		fmt.Println("Please allow up to 5 minutes for DNS changes to take effect.")
	}
}
开发者ID:turnerlabs,项目名称:harbor-compose,代码行数:84,代码来源:up.go


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