@@ -17,9 +17,10 @@ import (
1717
1818// Configuration : represent .soos.json structure
1919type Configuration struct {
20- ImageName string
21- ExposePorts []string
22- HashFiles []string
20+ ImageName string
21+ ExposePorts []string
22+ HashFiles []string
23+ EnvVariables map [string ]string
2324}
2425
2526// DefaultConfig : base for .soos.json
@@ -146,22 +147,30 @@ func cwd() string {
146147}
147148
148149func runImage (imageNameWithTag string ) {
149-
150- args := []string {"run" }
151-
152150 user , userErr := user .Current ()
153151 if userErr != nil {
154152 log .Fatal (userErr )
155153 }
156154
155+ dockerRunOptions := []string {"--rm" , "-u" , user .Uid + ":" + user .Gid , "-v" , cwd () + ":/build/app" }
156+
157157 if len (getConfig ().ExposePorts ) != 0 {
158- exposePortsArg := "-p" + getConfig ().ExposePorts [0 ]
159- args = append ([]string {"run" , "--rm" , "-u" , user .Uid + ":" + user .Gid , exposePortsArg , "-v" , cwd () + ":/build/app" , imageNameWithTag }, os .Args [1 :]... )
160- } else {
158+ for _ , exposePort := range getConfig ().ExposePorts {
159+ dockerRunOptions = append (dockerRunOptions , "-p" + exposePort )
160+ }
161+ }
161162
162- args = append ([]string {"run" , "--rm" , "-u" , user .Uid + ":" + user .Gid , "-v" , cwd () + ":/build/app" , imageNameWithTag }, os .Args [1 :]... )
163+ if len (getConfig ().EnvVariables ) != 0 {
164+ for envVarName , envVarValue := range getConfig ().EnvVariables {
165+ dockerRunOptions = append (dockerRunOptions , "-e" , envVarName + "=" + envVarValue )
166+ }
163167 }
164168
169+ args := []string {"run" }
170+ args = append (args , dockerRunOptions ... )
171+ args = append (args , imageNameWithTag )
172+ args = append (args , os .Args [1 :]... )
173+
165174 cmd := exec .Command ("docker" , args ... )
166175
167176 var out bytes.Buffer
0 commit comments