github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/pkg/model/docker_compose_target.go (about) 1 package model 2 3 import ( 4 "fmt" 5 6 "github.com/tilt-dev/tilt/internal/sliceutils" 7 "github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1" 8 ) 9 10 type DockerComposeTarget struct { 11 Spec v1alpha1.DockerComposeServiceSpec 12 13 Name TargetName 14 15 ServiceYAML string // for diff'ing when config files change 16 17 publishedPorts []int 18 19 inferLinks struct { 20 IsSet bool 21 Value bool 22 } 23 24 Links []Link 25 } 26 27 // TODO(nick): This is a temporary hack until we figure out how we want 28 // to pass these IDs to the docker-compose UX. 29 func (t DockerComposeTarget) ManifestName() ManifestName { 30 return ManifestName(t.Name) 31 } 32 33 func (t DockerComposeTarget) Empty() bool { return t.ID().Empty() } 34 35 func (t DockerComposeTarget) ID() TargetID { 36 return TargetID{ 37 Type: TargetTypeDockerCompose, 38 Name: t.Name, 39 } 40 } 41 42 func (t DockerComposeTarget) DependencyIDs() []TargetID { 43 result := make([]TargetID, 0, len(t.Spec.ImageMaps)) 44 for _, im := range t.Spec.ImageMaps { 45 result = append(result, TargetID{ 46 Type: TargetTypeImage, 47 Name: TargetName(im), 48 }) 49 } 50 return result 51 } 52 53 func (t DockerComposeTarget) PublishedPorts() []int { 54 return append([]int{}, t.publishedPorts...) 55 } 56 57 func (t DockerComposeTarget) InferLinks() bool { 58 if t.inferLinks.IsSet { 59 return t.inferLinks.Value 60 } else { 61 return true 62 } 63 } 64 65 func (t DockerComposeTarget) WithInferLinks(inferLinks bool) DockerComposeTarget { 66 t.inferLinks.IsSet = true 67 t.inferLinks.Value = inferLinks 68 return t 69 } 70 71 func (t DockerComposeTarget) WithLinks(links []Link) DockerComposeTarget { 72 t.Links = links 73 return t 74 } 75 76 func (t DockerComposeTarget) WithPublishedPorts(ports []int) DockerComposeTarget { 77 t.publishedPorts = ports 78 return t 79 } 80 81 func (t DockerComposeTarget) WithImageMapDeps(names []string) DockerComposeTarget { 82 t.Spec.ImageMaps = sliceutils.Dedupe(names) 83 return t 84 } 85 86 func (dc DockerComposeTarget) Validate() error { 87 if dc.ID().Empty() { 88 return fmt.Errorf("[Validate] DockerCompose resource missing name:\n%s", dc.ServiceYAML) 89 } 90 91 if len(dc.Spec.Project.ConfigPaths) == 0 && dc.Spec.Project.YAML == "" { 92 return fmt.Errorf("[Validate] DockerCompose resource %s missing config path", dc.Spec.Service) 93 } 94 95 return nil 96 } 97 98 var _ TargetSpec = DockerComposeTarget{}