Skip to content

Commit

Permalink
#40
Browse files Browse the repository at this point in the history
  • Loading branch information
ufasoli committed Aug 23, 2020
1 parent 9973079 commit 1c2b28c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 258 deletions.
2 changes: 2 additions & 0 deletions cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ var genCmd = &cobra.Command{
Image: platys.Platys.PlatformStack + ":" + platys.Platys.PlatformStackVersion,
Tty: true,
Env: env,
User: currentUser(),
},
&container.HostConfig{

Mounts: []mount.Mount{
{
Target: "/tmp/config.yml", // path in the container
Expand Down
18 changes: 12 additions & 6 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ By default 'config.yml' is used for the name of the config file, which is create
copied := 0
copyNext := false

for _, n := range servicesYml {
for i, n := range servicesYml {

if copyNext {
n.Value = "true"
if strings.Contains(servicesYml[i-1].Value, "_enable") { // change the value of the key only if it's a service (i.e don't do this for use timezone etc.)
n.Value = "true"
}

updatedYml = append(updatedYml, n)
copied++
copyNext = false
Expand Down Expand Up @@ -111,7 +114,7 @@ By default 'config.yml' is used for the name of the config file, which is create
}
}

updatedYml = updatedYml[:copied]
updatedYml = updatedYml[:copied] //create a new slice by copying the updated one
ymlConfig.Content[0].Content = updatedYml
}

Expand All @@ -130,13 +133,16 @@ By default 'config.yml' is used for the name of the config file, which is create
b, _ := yaml.Marshal(&ymlConfig)
b = addRootIndent(b, 6)

file, err := os.OpenFile(configFile, os.O_WRONLY|os.O_CREATE, 0755)

file, err := os.OpenFile(configFile, os.O_RDWR|os.O_CREATE, 0755)
defer file.Close()
if err != nil {
log.Fatal(fmt.Sprintf("Unable to open file %v", err))
}

defer file.Close()
err = file.Truncate(0) // clear the contents of the file as to do not have stale data when writing (will append)
if err != nil {
log.Fatal(fmt.Sprintf("Unable to clear file [%v] contents [%v]", configFile, err))
}

for _, s := range strings.SplitN(string(b), "\n", -1) { // write updated config file
_, err = file.Write([]byte(s + "\n"))
Expand Down
9 changes: 9 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"io"
"log"
"os"
"os/user"
)

var Stack string
Expand Down Expand Up @@ -216,3 +217,11 @@ func in_array(val string, list []string) bool {
}
return false
}

func currentUser() string {
usr, err := user.Current()
if err != nil {
log.Fatal("Unable to start docker container as current user cannot be determined")
}
return usr.Uid + ":" + usr.Gid
}
252 changes: 0 additions & 252 deletions config.yml

This file was deleted.

0 comments on commit 1c2b28c

Please sign in to comment.