Skip to content

Commit

Permalink
Merge pull request #294 from depot/compose-project
Browse files Browse the repository at this point in the history
Correctly generate Compose project name if not specified
  • Loading branch information
jacobwgillespie authored Jul 24, 2024
2 parents df2c6a6 + b66fe04 commit 37c4635
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"regexp"
"strings"

"github.com/compose-spec/compose-go/v2/consts"
"github.com/compose-spec/compose-go/v2/dotenv"
"github.com/compose-spec/compose-go/v2/loader"
"github.com/compose-spec/compose-go/v2/types"
Expand Down Expand Up @@ -49,6 +50,19 @@ func TargetTags(files []bake.File) (map[string][]string, error) {
Environment: envs,
}
opts := func(options *loader.Options) {
if nameFromEnv, ok := envs[consts.ComposeProjectName]; ok && nameFromEnv != "" {
options.SetProjectName(nameFromEnv, true)
} else {
path, err := filepath.Abs(files[0].Name)
if err != nil {
return
}
absWorkingDir := filepath.Dir(path)
options.SetProjectName(
loader.NormalizeProjectName(filepath.Base(absWorkingDir)),
false,
)
}
options.SkipNormalization = true
}

Expand Down Expand Up @@ -130,6 +144,11 @@ func isComposeFile(file string, content []byte) bool {
}

opts := func(options *loader.Options) {
projectName := "bake"
if v, ok := envs[consts.ComposeProjectName]; ok && v != "" {
projectName = v
}
options.SetProjectName(projectName, false)
options.SkipNormalization = true
options.SkipConsistencyCheck = true
}
Expand Down

0 comments on commit 37c4635

Please sign in to comment.