Skip to content

Commit

Permalink
tiltfile: Adds links to dc_resources (#4164)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Benoist committed Feb 5, 2021
1 parent facd4e6 commit e8edef3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/tiltfile/docker_compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/tilt-dev/tilt/internal/container"
"github.com/tilt-dev/tilt/internal/dockercompose"
"github.com/tilt-dev/tilt/internal/tiltfile/io"
"github.com/tilt-dev/tilt/internal/tiltfile/links"
"github.com/tilt-dev/tilt/internal/tiltfile/starkit"
"github.com/tilt-dev/tilt/internal/tiltfile/value"
"github.com/tilt-dev/tilt/pkg/model"
Expand Down Expand Up @@ -91,6 +92,7 @@ func (s *tiltfileState) dcResource(thread *starlark.Thread, fn *starlark.Builtin
var imageVal starlark.Value
var triggerMode triggerMode
var resourceDepsVal starlark.Sequence
var links links.LinkList

if err := s.unpackArgs(fn.Name(), args, kwargs,
"name", &name,
Expand All @@ -106,6 +108,7 @@ func (s *tiltfileState) dcResource(thread *starlark.Thread, fn *starlark.Builtin

"trigger_mode?", &triggerMode,
"resource_deps?", &resourceDepsVal,
"links?", &links,
); err != nil {
return nil, err
}
Expand All @@ -130,6 +133,7 @@ func (s *tiltfileState) dcResource(thread *starlark.Thread, fn *starlark.Builtin
}

svc.TriggerMode = triggerMode
svc.Links = links.Links

if imageRefAsStr != nil {
normalized, err := container.ParseNamed(*imageRefAsStr)
Expand Down Expand Up @@ -182,6 +186,7 @@ type dcService struct {
PublishedPorts []int

TriggerMode triggerMode
Links []model.Link

resourceDeps []string
}
Expand Down Expand Up @@ -276,6 +281,7 @@ func (s *tiltfileState) dcServiceToManifest(service *dcService, dcSet dcResource
ConfigPaths: dcSet.configPaths,
YAMLRaw: service.ServiceConfig,
DfRaw: service.DfContents,
Links: service.Links,
}.WithDependencyIDs(service.DependencyIDs).
WithPublishedPorts(service.PublishedPorts).
WithIgnoredLocalDirectories(service.MountedLocalDirs)
Expand Down
30 changes: 30 additions & 0 deletions internal/tiltfile/tiltfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (

type localResourceLinks []model.Link
type k8sResourceLinks []model.Link
type dcResourceLinks []model.Link

const simpleDockerfile = "FROM golang:1.10"

Expand Down Expand Up @@ -814,6 +815,33 @@ k8s_resource('foo', links=EXPR)
db(image("gcr.io/foo")),
deployment("foo"))
})

t.Run("dc-"+c.name, func(t *testing.T) {
f := newFixture(t)
defer f.TearDown()

f.file("docker-compose.yml", `version: '3.0'
services:
foo:
image: gcr.io/foo
`)
s := `
docker_compose('docker-compose.yml')
dc_resource('foo', links=EXPR)`

s = strings.Replace(s, "EXPR", c.expr, -1)
f.file("Tiltfile", s)

if c.errorMsg != "" {
f.loadErrString(c.errorMsg)
return
}

f.load()
f.assertNextManifest("foo",
dcResourceLinks(c.expected),
)
})
}
}

Expand Down Expand Up @@ -5975,6 +6003,8 @@ func (f *fixture) assertNextManifest(name model.ManifestName, opts ...interface{

case []model.PortForward:
assert.Equal(f.t, opt, m.K8sTarget().PortForwards)
case dcResourceLinks:
f.assertLinks(opt, m.DockerComposeTarget().Links)
case localResourceLinks:
f.assertLinks(opt, m.LocalTarget().Links)
case k8sResourceLinks:
Expand Down
7 changes: 7 additions & 0 deletions pkg/model/docker_compose_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type DockerComposeTarget struct {
dependencyIDs []TargetID

publishedPorts []int

Links []Link
}

// TODO(nick): This is a temporary hack until we figure out how we want
Expand Down Expand Up @@ -60,6 +62,11 @@ func (t DockerComposeTarget) PublishedPorts() []int {
return append([]int{}, t.publishedPorts...)
}

func (t DockerComposeTarget) WithLinks(links []Link) DockerComposeTarget {
t.Links = links
return t
}

func (t DockerComposeTarget) WithPublishedPorts(ports []int) DockerComposeTarget {
t.publishedPorts = ports
return t
Expand Down

0 comments on commit e8edef3

Please sign in to comment.