Skip to content

Commit

Permalink
Add "network" model option with "host" default value.
Browse files Browse the repository at this point in the history
Add "hostenv" option to pass host env vars as is.
  • Loading branch information
silphid committed Jun 16, 2021
1 parent c0dab40 commit 3ad5b7a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/internal/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ type Context struct {
Image string
Build DockerBuild
Env map[string]string
HostEnv []string `yaml:"hostenv,omitempty"`
Mounts map[string]string
Cmd []string
EntryPoint []string
Network string
}

// Clone returns a deep-copy of this context
Expand All @@ -41,6 +43,8 @@ func (c Context) Clone() Context {
for key, value := range c.Build.Args {
clone.Build.Args[key] = value
}
clone.HostEnv = make([]string, len(c.HostEnv))
copy(clone.HostEnv, c.HostEnv)
return clone
}

Expand Down Expand Up @@ -69,6 +73,10 @@ 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
}
merged.HostEnv = append(merged.HostEnv, source.HostEnv...)
return merged
}

Expand Down
18 changes: 14 additions & 4 deletions src/internal/docker/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ 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,
}
Expand All @@ -176,6 +172,11 @@ func runContainer(ctx context.Context, yeyCtx yey.Context, containerName string,
args = append(args, "--env", fmt.Sprintf("%s=%s", name, value))
}

// Env vars passed as-is from host
for _, name := range yeyCtx.HostEnv {
args = append(args, "--env", name)
}

// Mount binds
for key, value := range yeyCtx.Mounts {
args = append(
Expand All @@ -185,10 +186,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 3ad5b7a

Please sign in to comment.