Skip to content

Commit

Permalink
tiltfile: compose projects should default to COMPOSE_PROFILES env var (
Browse files Browse the repository at this point in the history
…#6264)

fixes #6250

Signed-off-by: Nick Santos <[email protected]>
  • Loading branch information
nicks authored Nov 23, 2023
1 parent 11c084c commit 764a80b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/tiltfile/docker_compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"
"strings"

"github.com/compose-spec/compose-go/consts"
"github.com/compose-spec/compose-go/loader"
"github.com/compose-spec/compose-go/types"
"github.com/distribution/reference"
Expand All @@ -26,6 +27,7 @@ import (
"github.com/tilt-dev/tilt/internal/tiltfile/starkit"
"github.com/tilt-dev/tilt/internal/tiltfile/value"
"github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"
"github.com/tilt-dev/tilt/pkg/logger"
"github.com/tilt-dev/tilt/pkg/model"
)

Expand Down Expand Up @@ -147,6 +149,12 @@ func (s *tiltfileState) dockerCompose(thread *starlark.Thread, fn *starlark.Buil
project.ProjectPath = filepath.Dir(currentTiltfilePath)
}

if !profiles.IsSet && os.Getenv(consts.ComposeProfiles) != "" {
logger.Get(s.ctx).Infof("Compose project %q loading profiles from environment: %s",
project.Name, os.Getenv(consts.ComposeProfiles))
project.Profiles = strings.Split(os.Getenv(consts.ComposeProfiles), ",")
}

dc := s.dc[project.Name]
if dc == nil {
dc = &dcResourceSet{
Expand Down
17 changes: 17 additions & 0 deletions internal/tiltfile/tiltfile_docker_compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,23 @@ dc_resource('bar')
f.assertNoMoreManifests()
})

t.Run("include specified profile from env var", func(t *testing.T) {
f := newFixture(t)
t.Setenv("COMPOSE_PROFILES", "barprofile")

f.setupFoo()
f.file("docker-compose.yml", twoServiceConfigWithProfiles)
f.file("Tiltfile", `docker_compose('docker-compose.yml')
dc_resource('foo')
dc_resource('bar')
`)
f.load()

_ = f.assertNextManifest("foo")
_ = f.assertNextManifest("bar")
f.assertNoMoreManifests()
})

t.Run("must include profile to have resource", func(t *testing.T) {
f := newFixture(t)

Expand Down
3 changes: 3 additions & 0 deletions internal/tiltfile/value/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (s *StringList) Unpack(v starlark.Value) error {

type StringOrStringList struct {
Values []string
IsSet bool
}

var _ starlark.Unpacker = &StringOrStringList{}
Expand All @@ -87,6 +88,7 @@ func (s *StringOrStringList) Unpack(v starlark.Value) error {
vs, ok := AsString(v)
if ok {
s.Values = []string{vs}
s.IsSet = true
return nil
}

Expand All @@ -112,5 +114,6 @@ func (s *StringOrStringList) Unpack(v starlark.Value) error {
s.Values = append(s.Values, sv)
}

s.IsSet = true
return nil
}

0 comments on commit 764a80b

Please sign in to comment.