-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contd: parse startup.toml and update container data
fixes #319 we extract 3 things from statup.toml: - entrypoint - working dir - enviroment variable
- Loading branch information
Showing
6 changed files
with
242 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package container | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type startup struct { | ||
Entries map[string]entry `toml:"startup"` | ||
} | ||
|
||
type entry struct { | ||
Name string | ||
Args args | ||
} | ||
|
||
type args struct { | ||
Name string | ||
Dir string | ||
Env map[string]string | ||
} | ||
|
||
func (e entry) Entrypoint() string { | ||
if e.Name == "core.system" || | ||
e.Name == "core.base" && e.Args.Name != "" { | ||
return e.Args.Name | ||
} | ||
return "" | ||
} | ||
|
||
func (e entry) WorkingDir() string { | ||
return e.Args.Dir | ||
} | ||
|
||
func (e entry) Envs() []string { | ||
envs := make([]string, 0, len(e.Args.Env)) | ||
for k, v := range e.Args.Env { | ||
envs = append(envs, fmt.Sprintf("%s=%s", k, v)) | ||
} | ||
return envs | ||
} | ||
|
||
// mergeEnvs merge a into b | ||
// all the key from a will endup in b | ||
// if a key is present in both, key from a are kept | ||
func mergeEnvs(a, b []string) []string { | ||
ma := make(map[string]string, len(a)) | ||
mb := make(map[string]string, len(b)) | ||
|
||
for _, s := range a { | ||
ss := strings.SplitN(s, "=", 2) | ||
ma[ss[0]] = ss[1] | ||
} | ||
for _, s := range b { | ||
ss := strings.SplitN(s, "=", 2) | ||
mb[ss[0]] = ss[1] | ||
} | ||
|
||
for ka, va := range ma { | ||
mb[ka] = va | ||
} | ||
|
||
result := make([]string, 0, len(mb)) | ||
for k, v := range mb { | ||
result = append(result, fmt.Sprintf("%s=%s", k, v)) | ||
} | ||
return result | ||
} |
Oops, something went wrong.