-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to pass env-file to docker compose run #9169
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,4 +127,8 @@ func applyRunOptions(project *types.Project, service *types.ServiceConfig, opts | |
for k, v := range opts.Labels { | ||
service.Labels = service.Labels.Add(k, v) | ||
} | ||
|
||
if opts.ServiceEnvFiles != nil { | ||
service.EnvFile = append(service.EnvFile, opts.ServiceEnvFiles...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to make service envfile an absolute path There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any sample code which I can refer in the repository? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just use: if !filepath.IsAbs(file) {
file, err = filepath.Abs(file)
} |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package compose | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/compose-spec/compose-go/types" | ||
"github.com/docker/compose/v2/pkg/api" | ||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestServiceEnvFiles(t *testing.T) { | ||
|
||
t.Run("Verify service.EnvFile shouldn't modify", func(t *testing.T) { | ||
fooService := types.ServiceConfig{ | ||
Name: "foo", | ||
EnvFile: []string{}, | ||
} | ||
|
||
project := types.Project{ | ||
Name: "test-project", | ||
Services: types.Services{ | ||
fooService, | ||
}, | ||
} | ||
|
||
opts := api.RunOptions{ | ||
ServiceEnvFiles: nil, | ||
} | ||
|
||
applyRunOptions(&project, &fooService, opts) | ||
|
||
assert.Assert(t, len(fooService.EnvFile) == 0) | ||
}) | ||
|
||
t.Run("Verify appends ServiceEnvFiles", func(t *testing.T) { | ||
fooService := &types.ServiceConfig{ | ||
Name: "foo", | ||
EnvFile: []string{"./existing.env"}, | ||
} | ||
|
||
project := types.Project{ | ||
Name: "test-project", | ||
Services: types.Services{ | ||
*fooService, | ||
}, | ||
} | ||
|
||
opts := api.RunOptions{ | ||
ServiceEnvFiles: []string{"./file.env"}, | ||
} | ||
|
||
applyRunOptions(&project, fooService, opts) | ||
|
||
assert.Assert(t, len(fooService.EnvFile) == 2) | ||
assert.Assert(t, fooService.EnvFile[0] == "./existing.env") | ||
assert.Assert(t, fooService.EnvFile[1] == "./file.env") | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: rename flag
--env-from-file
, wdyt ?