service_factory.go 973 B

123456789101112131415161718192021222324252627282930313233343536
  1. package docker
  2. import (
  3. "github.com/rancher/os/pkg/util"
  4. composeConfig "github.com/docker/libcompose/config"
  5. "github.com/docker/libcompose/docker"
  6. "github.com/docker/libcompose/project"
  7. )
  8. type ServiceFactory struct {
  9. Context *docker.Context
  10. Deps map[string][]string
  11. }
  12. func (s *ServiceFactory) Create(project *project.Project, name string, serviceConfig *composeConfig.ServiceConfig) (project.Service, error) {
  13. if after := serviceConfig.Labels["io.rancher.os.after"]; after != "" {
  14. for _, dep := range util.TrimSplit(after, ",") {
  15. if dep == "cloud-init" {
  16. dep = "cloud-init-execute"
  17. }
  18. s.Deps[name] = append(s.Deps[name], dep)
  19. }
  20. }
  21. if before := serviceConfig.Labels["io.rancher.os.before"]; before != "" {
  22. for _, dep := range util.TrimSplit(before, ",") {
  23. if dep == "cloud-init" {
  24. dep = "cloud-init-execute"
  25. }
  26. s.Deps[dep] = append(s.Deps[dep], name)
  27. }
  28. }
  29. return NewService(s, name, serviceConfig, s.Context, project), nil
  30. }