@@ -6,9 +6,22 @@ import (
66 "os"
77 "path/filepath"
88 "strings"
9+
10+ "github.com/joho/godotenv"
911)
1012
1113func exportUpstart (cfg * config , path string ) error {
14+ procfile , err := filepath .Abs (cfg .Procfile )
15+ if err != nil {
16+ return err
17+ }
18+ // parse .env the same way `goreman start` does (godotenv), so exported
19+ // values match the runtime environment.
20+ env , err := godotenv .Read (filepath .Join (filepath .Dir (procfile ), ".env" ))
21+ if err != nil {
22+ env = map [string ]string {}
23+ }
24+
1225 for _ , proc := range procs {
1326 f , err := os .Create (filepath .Join (path , "app-" + proc .name + ".conf" ))
1427 if err != nil {
@@ -20,27 +33,6 @@ func exportUpstart(cfg *config, path string) error {
2033 fmt .Fprintf (f , "respawn\n " )
2134 fmt .Fprintf (f , "\n " )
2235
23- env := map [string ]string {}
24- procfile , err := filepath .Abs (cfg .Procfile )
25- if err != nil {
26- return err
27- }
28- b , err := os .ReadFile (filepath .Join (filepath .Dir (procfile ), ".env" ))
29- if err == nil {
30- for _ , line := range strings .Split (string (b ), "\n " ) {
31- token := strings .SplitN (line , "=" , 2 )
32- if len (token ) != 2 {
33- continue
34- }
35- if strings .HasPrefix (token [0 ], "export " ) {
36- token [0 ] = token [0 ][7 :]
37- }
38- token [0 ] = strings .TrimSpace (token [0 ])
39- token [1 ] = strings .TrimSpace (token [1 ])
40- env [token [0 ]] = token [1 ]
41- }
42- }
43-
4436 if proc .setPort {
4537 fmt .Fprintf (f , "env PORT=%d\n " , proc .port )
4638 }
0 commit comments