feat: load every environment from --env-file to workflow (#184)
* feat: load every environment from --env-file to workflow * fix: pass dotenv's environments through by context * updates to support --secret-file Co-authored-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
35
cmd/root.go
35
cmd/root.go
@@ -46,7 +46,8 @@ func Execute(ctx context.Context, version string) {
|
||||
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output")
|
||||
rootCmd.PersistentFlags().BoolVarP(&input.noOutput, "quiet", "q", false, "disable logging of output from steps")
|
||||
rootCmd.PersistentFlags().BoolVarP(&input.dryrun, "dryrun", "n", false, "dryrun mode")
|
||||
rootCmd.PersistentFlags().StringVarP(&input.envfile, "env-file", "", ".env", "environment file to read")
|
||||
rootCmd.PersistentFlags().StringVarP(&input.secretfile, "secret-file", "", "", "file with list of secrets to read from")
|
||||
rootCmd.PersistentFlags().StringVarP(&input.envfile, "env-file", "", ".env", "environment file to read and use as env in the containers")
|
||||
rootCmd.SetArgs(args())
|
||||
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
@@ -92,16 +93,29 @@ func setupLogging(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
}
|
||||
|
||||
func readEnvs(path string, envs map[string]string) bool {
|
||||
if _, err := os.Stat(path); err == nil {
|
||||
env, err := godotenv.Read(path)
|
||||
if err != nil {
|
||||
log.Fatalf("Error loading from %s: %v", path, err)
|
||||
}
|
||||
for k, v := range env {
|
||||
envs[k] = v
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []string) error {
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
envfile := input.Envfile()
|
||||
if _, err := os.Stat(envfile); err == nil {
|
||||
log.Debugf("Loading environment from %s", envfile)
|
||||
err := godotenv.Load(envfile)
|
||||
if err != nil {
|
||||
log.Fatalf("Error loading environment from %s: %v", envfile, err)
|
||||
}
|
||||
}
|
||||
log.Debugf("Loading environment from %s", input.Envfile())
|
||||
envs := make(map[string]string)
|
||||
_ = readEnvs(input.Envfile(), envs)
|
||||
|
||||
log.Debugf("Loading secrets from %s", input.Secretfile())
|
||||
secrets := newSecrets(input.secrets)
|
||||
_ = readEnvs(input.Secretfile(), secrets)
|
||||
|
||||
planner, err := model.NewWorkflowPlanner(input.WorkflowsPath())
|
||||
if err != nil {
|
||||
@@ -149,7 +163,8 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
|
||||
Workdir: input.Workdir(),
|
||||
BindWorkdir: input.bindWorkdir,
|
||||
LogOutput: !input.noOutput,
|
||||
Secrets: newSecrets(input.secrets),
|
||||
Env: envs,
|
||||
Secrets: secrets,
|
||||
Platforms: input.newPlatforms(),
|
||||
}
|
||||
runner, err := runner.New(config)
|
||||
|
Reference in New Issue
Block a user