Skip to content

Commit

Permalink
Merge pull request #22 from silphid/network-mode-and-host-env
Browse files Browse the repository at this point in the history
Add "network" model option with "host" default value.
  • Loading branch information
silphid authored Jun 24, 2021
2 parents 0babd8e + d5f65c1 commit fb29086
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/.DS_Store
**/.DS_Store
/.yeyrc.yaml
4 changes: 4 additions & 0 deletions src/internal/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Context struct {
Mounts map[string]string
Cmd []string
EntryPoint []string
Network string
}

// Clone returns a deep-copy of this context
Expand Down Expand Up @@ -69,6 +70,9 @@ func (c Context) Merge(source Context) Context {
for key, value := range source.Build.Args {
merged.Build.Args[key] = value
}
if source.Network != "" {
merged.Network = source.Network
}
return merged
}

Expand Down
19 changes: 14 additions & 5 deletions src/internal/docker/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,17 @@ func runContainer(ctx context.Context, yeyCtx yey.Context, containerName string,
"run",
"-it",
"--name", containerName,
"--env", "LS_COLORS",
"--env", "TERM",
"--env", "TERM_COLOR",
"--env", "TERM_PROGRAM",
"--env", "YEY_WORK_DIR=" + cwd,
"--env", "YEY_CONTEXT=" + yeyCtx.Name,
}

// Context env vars
for name, value := range yeyCtx.Env {
args = append(args, "--env", fmt.Sprintf("%s=%s", name, value))
arg := name
if value != "" {
arg = fmt.Sprintf("%s=%s", name, value)
}
args = append(args, "--env", arg)
}

// Mount binds
Expand All @@ -185,10 +185,19 @@ func runContainer(ctx context.Context, yeyCtx yey.Context, containerName string,
)
}

// Remove container upon exit?
if yeyCtx.Remove != nil && *yeyCtx.Remove {
args = append(args, "--rm")
}

// Network mode
network := yeyCtx.Network
if network == "" {
network = "host"
}
args = append(args, "--network", network)

// Work directory
if options.workDir != "" {
args = append(args, "--workdir", options.workDir)
}
Expand Down

0 comments on commit fb29086

Please sign in to comment.