convert.go 1.1 KB

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