Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions internal/services/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,21 @@ func lookupProcessCompose(projectDir, path string) string {

return ""
}

// LookupProcessComposeOverride finds the process-compose override file in the given directory.
// process-compose supports override files that are merged with the base configuration.
// See: https://f1bonacc1.github.io/process-compose/merge/
func LookupProcessComposeOverride(projectDir string) string {
overrideFiles := []string{
filepath.Join(projectDir, "process-compose.override.yaml"),
filepath.Join(projectDir, "process-compose.override.yml"),
}

for _, p := range overrideFiles {
if fi, err := os.Stat(p); err == nil && !fi.IsDir() {
return p
}
}

return ""
}
72 changes: 72 additions & 0 deletions internal/services/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2024 Jetify Inc. and contributors. All rights reserved.
// Use of this source code is governed by the license in the LICENSE file.

package services

import (
"os"
"path/filepath"
"testing"
)

func TestLookupProcessComposeOverride(t *testing.T) {
tests := []struct {
name string
files []string
wantFileName string
}{
{
name: "no override file",
files: []string{},
wantFileName: "",
},
{
name: "yaml override",
files: []string{"process-compose.override.yaml"},
wantFileName: "process-compose.override.yaml",
},
{
name: "yml override",
files: []string{"process-compose.override.yml"},
wantFileName: "process-compose.override.yml",
},
{
name: "yaml takes precedence over yml",
files: []string{"process-compose.override.yaml", "process-compose.override.yml"},
wantFileName: "process-compose.override.yaml",
},
{
name: "ignores non-override files",
files: []string{"process-compose.yaml", "other.yaml"},
wantFileName: "",
},
}

for _, testCase := range tests {
t.Run(testCase.name, func(t *testing.T) {
// Create temp directory
tempDir := t.TempDir()

// Create test files
for _, f := range testCase.files {
path := filepath.Join(tempDir, f)
if err := os.WriteFile(path, []byte("# test"), 0644); err != nil {
t.Fatalf("Failed to create test file %s: %v", f, err)
}
}

got := LookupProcessComposeOverride(tempDir)

if testCase.wantFileName == "" {
if got != "" {
t.Errorf("LookupProcessComposeOverride() = %q, want empty string", got)
}
} else {
want := filepath.Join(tempDir, testCase.wantFileName)
if got != want {
t.Errorf("LookupProcessComposeOverride() = %q, want %q", got, want)
}
}
})
}
}
7 changes: 7 additions & 0 deletions internal/services/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ func StartProcessManager(
flags = append(flags, "-f", s.ProcessComposePath)
}

// Add override file if it exists. Override files are merged with base configuration
// and allow individual developers to customize their local development environment.
// See: https://f1bonacc1.github.io/process-compose/merge/
if overrideFile := LookupProcessComposeOverride(projectDir); overrideFile != "" {
flags = append(flags, "-f", overrideFile)
}

flags = append(flags, processComposeConfig.ExtraFlags...)

if processComposeConfig.Background {
Expand Down