diff --git a/cli/cli.go b/cli/cli.go index 6f52512..03d7f8e 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -30,7 +30,7 @@ import ( // App props const ( APP = "init-exporter" - VER = "0.13.0" + VER = "0.14.0" DESC = "Utility for exporting services described by Procfile to init system" ) diff --git a/common/init-exporter.spec b/common/init-exporter.spec index a860dd6..d7596a6 100644 --- a/common/init-exporter.spec +++ b/common/init-exporter.spec @@ -42,8 +42,8 @@ Summary: Utility for exporting services described by Procfile to init system Name: init-exporter -Version: 0.13.0 -Release: 1%{?dist} +Version: 0.14.0 +Release: 0%{?dist} Group: Development/Tools License: MIT URL: https://github.com/funbox/init-exporter @@ -132,6 +132,10 @@ rm -rf %{buildroot} ############################################################################### %changelog +* Wed Apr 26 2017 Anton Novojilov - 0.14.0-0 +- Environment variables and file with environment variables now can defined + in same time + * Mon Apr 24 2017 Anton Novojilov - 0.13.0-1 - [init-exporter-converter] Replaced text/template by basic procfile rendering diff --git a/export/export_test.go b/export/export_test.go index 68edf00..846f64b 100644 --- a/export/export_test.go +++ b/export/export_test.go @@ -187,7 +187,7 @@ func (s *ExportSuite) TestUpstartExport(c *C) { c.Assert(service2Helper[4:], DeepEquals, []string{ "[[ -r /etc/profile.d/rbenv.sh ]] && source /etc/profile.d/rbenv.sh", "", - "cd /srv/service/working-dir && exec env $(cat /srv/service/working-dir/shared/env.vars 2>/dev/null | xargs) /bin/echo 'service2'", + "cd /srv/service/working-dir && exec env $(cat /srv/service/working-dir/shared/env.vars 2>/dev/null | xargs) STAGING=true /bin/echo 'service2'", ""}, ) @@ -370,7 +370,7 @@ func (s *ExportSuite) TestSystemdExport(c *C) { c.Assert(service2Helper[4:], DeepEquals, []string{ "[[ -r /etc/profile.d/rbenv.sh ]] && source /etc/profile.d/rbenv.sh", "", - "exec env $(cat /srv/service/working-dir/shared/env.vars 2>/dev/null | xargs) /bin/echo 'service2'", + "exec env $(cat /srv/service/working-dir/shared/env.vars 2>/dev/null | xargs) STAGING=true /bin/echo 'service2'", ""}, ) @@ -425,6 +425,7 @@ func createTestApp(helperDir, targetDir string) *procfile.Application { Application: app, Options: &procfile.ServiceOptions{ EnvFile: "shared/env.vars", + Env: map[string]string{"STAGING": "true"}, WorkingDir: "/srv/service/working-dir", ReloadSignal: "SIGUSR2", IsRespawnEnabled: true, diff --git a/procfile/procfile.go b/procfile/procfile.go index 3285864..528260e 100644 --- a/procfile/procfile.go +++ b/procfile/procfile.go @@ -159,10 +159,6 @@ func (so *ServiceOptions) Validate() []error { errs.Add(checkPath(so.LogFile)) errs.Add(checkPath(so.EnvFile)) - if so.IsEnvSet() && so.IsEnvFileSet() { - errs.Add(fmt.Errorf("Environment file and environment variables cannot be defined in same time")) - } - for envName, envVal := range so.Env { errs.Add(checkEnv(envName, envVal)) } @@ -184,10 +180,16 @@ func (s *Service) HasPostCmd() bool { func (s *Service) GetCommandExec(command string) string { var result = "exec " - if s.Options.IsEnvSet() { - result += "env " + s.Options.EnvString() + " " - } else if s.Options.IsEnvFileSet() { - result += "env $(cat " + s.Options.FullEnvFilePath() + " 2>/dev/null | xargs) " + if s.Options.IsEnvSet() || s.Options.IsEnvFileSet() { + result += "env " + + if s.Options.IsEnvFileSet() { + result += "$(cat " + s.Options.FullEnvFilePath() + " 2>/dev/null | xargs) " + } + + if s.Options.IsEnvSet() { + result += s.Options.EnvString() + " " + } } switch command { @@ -357,10 +359,14 @@ func convertMapType(m map[interface{}]interface{}) map[string]string { // mergeServiceOptions merge two ServiceOptions structs func mergeServiceOptions(dst, src *ServiceOptions) { - if !dst.IsEnvFileSet() && src.IsEnvSet() { + if src.IsEnvSet() { mergeStringMaps(dst.Env, src.Env) } + if dst.EnvFile == "" { + dst.EnvFile = src.EnvFile + } + if dst.WorkingDir == "" { dst.WorkingDir = src.WorkingDir } diff --git a/procfile/procfile_test.go b/procfile/procfile_test.go index 6affdfe..fb68fc5 100644 --- a/procfile/procfile_test.go +++ b/procfile/procfile_test.go @@ -121,7 +121,7 @@ func (s *ProcfileSuite) TestProcV2Parsing(c *C) { c.Assert(service.Options.RespawnInterval, Equals, 22) c.Assert(service.Options.IsRespawnEnabled, Equals, false) c.Assert(service.Options.EnvFile, Equals, "shared/env.file") - c.Assert(service.Options.EnvString(), Equals, "") + c.Assert(service.Options.EnvString(), Equals, "RAILS_ENV=production TEST=true") c.Assert(service.Options.LimitFile, Equals, 8192) c.Assert(service.Options.LimitProc, Equals, 8192) c.Assert(service.Application, NotNil)