Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef Gabrielsson committed Mar 5, 2022
1 parent 6ce2025 commit 2e71f1c
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 38 deletions.
14 changes: 10 additions & 4 deletions dotyaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Services struct {
DnsOpt []string `yaml:"dns_opt,omitempty"`
Devices []string `yaml:"devices,omitempty"`
ContainerName string `yaml:"container_name,omitempty"`
Entrypoint interface{} `yaml:"entrypoint,omitempty"`
EnvFile interface{} `yaml:"env_file,omitempty"`
Environment interface{} `yaml:"environment,omitempty"`
Expose interface{} `yaml:"expose,omitempty"`
Expand All @@ -28,10 +29,14 @@ type Services struct {
Pid string `yaml:"pid,omitempty"`
PidsLimit int16 `yaml:"pids_limit,omitempty"`
Restart string `yaml:"restart,omitempty"`
Privileged bool `yaml:"privileged,omitempty"`
StopSignal string `yaml:"stop_signal,omitempty"`
Sysctls interface{} `yaml:"sysctls,omitempty"`
Tmpfs interface{} `yaml:"tmpfs,omitempty"`
Tty bool `yaml:"tty,omitempty"`
User string `yaml:"user,omitempty"`
Volumes []string `yaml:"volumes,omitempty"`
WorkingDir string `yaml:"working_dir,omitempty"`
}

type Volumes struct {
Expand All @@ -42,10 +47,6 @@ type Ports struct {
Ports []string `yaml:"ports"`
}

type Restart struct {
Restart string `yaml:"restart"`
}

type Environment struct {
Environment interface{} `yaml:"environment"`
}
Expand Down Expand Up @@ -171,3 +172,8 @@ func convertToArray(t interface{}) []string {

return arr
}

func convertToString(p []string) string {
justString := strings.Join(p, " ")
return justString
}
89 changes: 55 additions & 34 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,51 @@ func buildCommand(e *Yaml, l []EnvironmentVariable) Command {
arr = append(arr, "--cpu-shares", v.CpuShares)
}

for i := range v.Devices {
arr = append(arr, "--device", v.Devices[i])
}

if v.Dns != nil {
for _, r := range convertToArray(v.Dns) {
arr = append(arr, "--dns", r)
}
}

if v.DnsSearch != nil {
for _, r := range convertToArray(v.DnsSearch) {
arr = append(arr, "--dns-search", r)
}
}

for i := range v.DnsOpt {
arr = append(arr, "--dns-opt", v.DnsOpt[i])
}

if v.Entrypoint != nil {
p := normalizeValue(v.Entrypoint)
arr = append(arr, "--entrypoint", convertToString(p))
}

if v.EnvFile != nil {
for _, r := range convertToArray(v.EnvFile) {
arr = append(arr, "--env-file", r)
}
}

if v.Expose != nil {
for _, r := range convertToArray(v.Expose) {
arr = append(arr, "--expose", r)
}
}

if v.Init != "" {
if _, err := strconv.ParseBool(v.Init); err == nil {
arr = append(arr, "--init")
} else {
arr = append(arr, "--init-path", v.Init)
}
}

if v.Pid != "" {
arr = append(arr, "--pid", v.Pid)
}
Expand All @@ -183,6 +228,10 @@ func buildCommand(e *Yaml, l []EnvironmentVariable) Command {
arr = append(arr, "--platform", v.Platform)
}

if v.Privileged {
arr = append(arr, "--privileged")
}

if v.Restart != "" {
arr = append(arr, "--restart", v.Restart)
}
Expand All @@ -202,44 +251,16 @@ func buildCommand(e *Yaml, l []EnvironmentVariable) Command {
}
}

if v.EnvFile != nil {
for _, r := range convertToArray(v.EnvFile) {
arr = append(arr, "--env-file", r)
}
}

if v.Expose != nil {
for _, r := range convertToArray(v.Expose) {
arr = append(arr, "--expose", r)
}
if v.Tty {
arr = append(arr, "--tty")
}

for i := range v.Devices {
arr = append(arr, "--device", v.Devices[i])
if v.User != "" {
arr = append(arr, "--user", v.User)
}

if v.Dns != nil {
for _, r := range convertToArray(v.Dns) {
arr = append(arr, "--dns", r)
}
}

if v.DnsSearch != nil {
for _, r := range convertToArray(v.DnsSearch) {
arr = append(arr, "--dns-search", r)
}
}

for i := range v.DnsOpt {
arr = append(arr, "--dns-opt", v.DnsOpt[i])
}

if v.Init != "" {
if _, err := strconv.ParseBool(v.Init); err == nil {
arr = append(arr, "--init")
} else {
arr = append(arr, "--init-path", v.Init)
}
if v.WorkingDir != "" {
arr = append(arr, "--workdir", v.WorkingDir)
}

arr = append(arr, v.Image)
Expand Down

0 comments on commit 2e71f1c

Please sign in to comment.