Skip to content

Commit

Permalink
Add support to pass env-file to docker compose run
Browse files Browse the repository at this point in the history
Signed-off-by: Vedant Koditkar <[email protected]>
  • Loading branch information
KoditkarVedant committed Jan 24, 2023
1 parent d47f0f3 commit d6e806a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/compose/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type runOptions struct {
noDeps bool
ignoreOrphans bool
quietPull bool
EnvFiles []string
}

func (opts runOptions) apply(project *types.Project) error {
Expand Down Expand Up @@ -156,6 +157,7 @@ func runCommand(p *ProjectOptions, streams api.Streams, backend api.Service) *co
flags := cmd.Flags()
flags.BoolVarP(&opts.Detach, "detach", "d", false, "Run container in background and print container ID")
flags.StringArrayVarP(&opts.environment, "env", "e", []string{}, "Set environment variables")
flags.StringArrayVar(&opts.EnvFiles, "env-file", []string{}, "Read in a file of environment variables")
flags.StringArrayVarP(&opts.labels, "label", "l", []string{}, "Add or override a label")
flags.BoolVar(&opts.Remove, "rm", false, "Automatically remove the container when it exits")
flags.BoolVarP(&opts.noTty, "no-TTY", "T", !streams.Out().IsTerminal(), "Disable pseudo-TTY allocation (default: auto-detected).")
Expand Down Expand Up @@ -233,6 +235,7 @@ func runRun(ctx context.Context, backend api.Service, project *types.Project, op
NoDeps: opts.noDeps,
Index: 0,
QuietPull: opts.quietPull,
EnvFiles: opts.EnvFiles,
}

for i, service := range project.Services {
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ type RunOptions struct {
// QuietPull makes the pulling process quiet
QuietPull bool
// used by exec
Index int
Index int
EnvFiles []string
}

// EventsOptions group options of the Events API
Expand Down
4 changes: 4 additions & 0 deletions pkg/compose/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.EnvFiles != nil {
service.EnvFile = opts.EnvFiles
}
}

0 comments on commit d6e806a

Please sign in to comment.