Skip to content

Commit ba77bd5

Browse files
committed
Environment variables and file with environment variables now can defined in same time
1 parent 3c3b749 commit ba77bd5

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

cli/cli.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
// App props
3131
const (
3232
APP = "init-exporter"
33-
VER = "0.13.0"
33+
VER = "0.14.0"
3434
DESC = "Utility for exporting services described by Procfile to init system"
3535
)
3636

common/init-exporter.spec

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242

4343
Summary: Utility for exporting services described by Procfile to init system
4444
Name: init-exporter
45-
Version: 0.13.0
46-
Release: 1%{?dist}
45+
Version: 0.14.0
46+
Release: 0%{?dist}
4747
Group: Development/Tools
4848
License: MIT
4949
URL: https://github.com/funbox/init-exporter
@@ -132,6 +132,10 @@ rm -rf %{buildroot}
132132
###############################################################################
133133

134134
%changelog
135+
* Wed Apr 26 2017 Anton Novojilov <[email protected]> - 0.14.0-0
136+
- Environment variables and file with environment variables now can defined
137+
in same time
138+
135139
* Mon Apr 24 2017 Anton Novojilov <[email protected]> - 0.13.0-1
136140
- [init-exporter-converter] Replaced text/template by basic procfile rendering
137141

export/export_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (s *ExportSuite) TestUpstartExport(c *C) {
187187
c.Assert(service2Helper[4:], DeepEquals,
188188
[]string{
189189
"[[ -r /etc/profile.d/rbenv.sh ]] && source /etc/profile.d/rbenv.sh", "",
190-
"cd /srv/service/working-dir && exec env $(cat /srv/service/working-dir/shared/env.vars 2>/dev/null | xargs) /bin/echo 'service2'",
190+
"cd /srv/service/working-dir && exec env $(cat /srv/service/working-dir/shared/env.vars 2>/dev/null | xargs) STAGING=true /bin/echo 'service2'",
191191
""},
192192
)
193193

@@ -370,7 +370,7 @@ func (s *ExportSuite) TestSystemdExport(c *C) {
370370
c.Assert(service2Helper[4:], DeepEquals,
371371
[]string{
372372
"[[ -r /etc/profile.d/rbenv.sh ]] && source /etc/profile.d/rbenv.sh", "",
373-
"exec env $(cat /srv/service/working-dir/shared/env.vars 2>/dev/null | xargs) /bin/echo 'service2'",
373+
"exec env $(cat /srv/service/working-dir/shared/env.vars 2>/dev/null | xargs) STAGING=true /bin/echo 'service2'",
374374
""},
375375
)
376376

@@ -425,6 +425,7 @@ func createTestApp(helperDir, targetDir string) *procfile.Application {
425425
Application: app,
426426
Options: &procfile.ServiceOptions{
427427
EnvFile: "shared/env.vars",
428+
Env: map[string]string{"STAGING": "true"},
428429
WorkingDir: "/srv/service/working-dir",
429430
ReloadSignal: "SIGUSR2",
430431
IsRespawnEnabled: true,

procfile/procfile.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@ func (so *ServiceOptions) Validate() []error {
159159
errs.Add(checkPath(so.LogFile))
160160
errs.Add(checkPath(so.EnvFile))
161161

162-
if so.IsEnvSet() && so.IsEnvFileSet() {
163-
errs.Add(fmt.Errorf("Environment file and environment variables cannot be defined in same time"))
164-
}
165-
166162
for envName, envVal := range so.Env {
167163
errs.Add(checkEnv(envName, envVal))
168164
}
@@ -184,10 +180,16 @@ func (s *Service) HasPostCmd() bool {
184180
func (s *Service) GetCommandExec(command string) string {
185181
var result = "exec "
186182

187-
if s.Options.IsEnvSet() {
188-
result += "env " + s.Options.EnvString() + " "
189-
} else if s.Options.IsEnvFileSet() {
190-
result += "env $(cat " + s.Options.FullEnvFilePath() + " 2>/dev/null | xargs) "
183+
if s.Options.IsEnvSet() || s.Options.IsEnvFileSet() {
184+
result += "env "
185+
186+
if s.Options.IsEnvFileSet() {
187+
result += "$(cat " + s.Options.FullEnvFilePath() + " 2>/dev/null | xargs) "
188+
}
189+
190+
if s.Options.IsEnvSet() {
191+
result += s.Options.EnvString() + " "
192+
}
191193
}
192194

193195
switch command {
@@ -357,10 +359,14 @@ func convertMapType(m map[interface{}]interface{}) map[string]string {
357359
// mergeServiceOptions merge two ServiceOptions structs
358360
func mergeServiceOptions(dst, src *ServiceOptions) {
359361

360-
if !dst.IsEnvFileSet() && src.IsEnvSet() {
362+
if src.IsEnvSet() {
361363
mergeStringMaps(dst.Env, src.Env)
362364
}
363365

366+
if dst.EnvFile == "" {
367+
dst.EnvFile = src.EnvFile
368+
}
369+
364370
if dst.WorkingDir == "" {
365371
dst.WorkingDir = src.WorkingDir
366372
}

procfile/procfile_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (s *ProcfileSuite) TestProcV2Parsing(c *C) {
121121
c.Assert(service.Options.RespawnInterval, Equals, 22)
122122
c.Assert(service.Options.IsRespawnEnabled, Equals, false)
123123
c.Assert(service.Options.EnvFile, Equals, "shared/env.file")
124-
c.Assert(service.Options.EnvString(), Equals, "")
124+
c.Assert(service.Options.EnvString(), Equals, "RAILS_ENV=production TEST=true")
125125
c.Assert(service.Options.LimitFile, Equals, 8192)
126126
c.Assert(service.Options.LimitProc, Equals, 8192)
127127
c.Assert(service.Application, NotNil)

0 commit comments

Comments
 (0)