github.com/bdwilliams/libcompose@v0.3.1-0.20160826154243-d81a9bdacff0/config/convert.go (about)

     1  package config
     2  
     3  import (
     4  	"github.com/docker/libcompose/utils"
     5  	"github.com/docker/libcompose/yaml"
     6  )
     7  
     8  // ConvertServices converts a set of v1 service configs to v2 service configs
     9  func ConvertServices(v1Services map[string]*ServiceConfigV1) (map[string]*ServiceConfig, error) {
    10  	v2Services := make(map[string]*ServiceConfig)
    11  	replacementFields := make(map[string]*ServiceConfig)
    12  
    13  	for name, service := range v1Services {
    14  		replacementFields[name] = &ServiceConfig{
    15  			Build: yaml.Build{
    16  				Context:    service.Build,
    17  				Dockerfile: service.Dockerfile,
    18  			},
    19  			Logging: Log{
    20  				Driver:  service.LogDriver,
    21  				Options: service.LogOpt,
    22  			},
    23  			NetworkMode: service.Net,
    24  		}
    25  
    26  		v1Services[name].Build = ""
    27  		v1Services[name].Dockerfile = ""
    28  		v1Services[name].LogDriver = ""
    29  		v1Services[name].LogOpt = nil
    30  		v1Services[name].Net = ""
    31  	}
    32  
    33  	if err := utils.Convert(v1Services, &v2Services); err != nil {
    34  		return nil, err
    35  	}
    36  
    37  	for name := range v2Services {
    38  		v2Services[name].Build = replacementFields[name].Build
    39  		v2Services[name].Logging = replacementFields[name].Logging
    40  		v2Services[name].NetworkMode = replacementFields[name].NetworkMode
    41  	}
    42  
    43  	return v2Services, nil
    44  }