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
  • Loading branch information
KoditkarVedant committed Feb 13, 2022
1 parent 10ca031 commit 25c370a
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 @@ -54,6 +54,7 @@ type runOptions struct {
name string
noDeps bool
quietPull bool
EnvFiles []string
}

func (opts runOptions) apply(project *types.Project) error {
Expand Down Expand Up @@ -141,6 +142,7 @@ func runCommand(p *projectOptions, backend api.Service) *cobra.Command {
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", false, "Disable pseudo-noTty allocation. By default docker compose run allocates a TTY")
Expand Down Expand Up @@ -212,6 +214,7 @@ func runRun(ctx context.Context, backend api.Service, project *types.Project, op
NoDeps: opts.noDeps,
Index: 0,
QuietPull: opts.quietPull,
EnvFiles: opts.EnvFiles,
}
exitCode, err := backend.RunOneOffContainer(ctx, project, runOpts)
if exitCode != 0 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,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 @@ -222,4 +222,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 25c370a

Please sign in to comment.