Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .soos.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
],
"ExposePorts": [
"3000:3000"
]
],
"EnvVariables": {
"BUILD_VERSION": "1.2.3",
"BUILD_ENV": "test"
}
}
29 changes: 19 additions & 10 deletions soos.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (

// Configuration : represent .soos.json structure
type Configuration struct {
ImageName string
ExposePorts []string
HashFiles []string
ImageName string
ExposePorts []string
HashFiles []string
EnvVariables map[string]string
}

// DefaultConfig : base for .soos.json
Expand Down Expand Up @@ -146,22 +147,30 @@ func cwd() string {
}

func runImage(imageNameWithTag string) {

args := []string{"run"}

user, userErr := user.Current()
if userErr != nil {
log.Fatal(userErr)
}

dockerRunOptions := []string{"--rm", "-u", user.Uid + ":" + user.Gid, "-v", cwd() + ":/build/app"}

if len(getConfig().ExposePorts) != 0 {
exposePortsArg := "-p" + getConfig().ExposePorts[0]
args = append([]string{"run", "--rm", "-u", user.Uid + ":" + user.Gid, exposePortsArg, "-v", cwd() + ":/build/app", imageNameWithTag}, os.Args[1:]...)
} else {
for _, exposePort := range getConfig().ExposePorts {
dockerRunOptions = append(dockerRunOptions, "-p"+exposePort)
}
}

args = append([]string{"run", "--rm", "-u", user.Uid + ":" + user.Gid, "-v", cwd() + ":/build/app", imageNameWithTag}, os.Args[1:]...)
if len(getConfig().EnvVariables) != 0 {
for envVarName, envVarValue := range getConfig().EnvVariables {
dockerRunOptions = append(dockerRunOptions, "-e", envVarName+"="+envVarValue)
}
}

args := []string{"run"}
args = append(args, dockerRunOptions...)
args = append(args, imageNameWithTag)
args = append(args, os.Args[1:]...)

cmd := exec.Command("docker", args...)

var out bytes.Buffer
Expand Down