Implement user & hosts for Exec

Signed-off-by: dubo-dubon-duponey <dubodubonduponey+github@pm.me>
This commit is contained in:
dubo-dubon-duponey 2021-05-11 14:36:57 -07:00 committed by Solomon Hykes
parent 2237b11bc0
commit ca6930bd02
2 changed files with 32 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io/fs" "io/fs"
"net"
"path" "path"
"strings" "strings"
@ -392,6 +393,33 @@ func (p *Pipeline) Exec(ctx context.Context, op *compiler.Value, st llb.State) (
// There's an ongoing proposal that would fix this: https://github.com/moby/buildkit/issues/1213 // There's an ongoing proposal that would fix this: https://github.com/moby/buildkit/issues/1213
opts = append(opts, llb.IgnoreCache) opts = append(opts, llb.IgnoreCache)
} }
if hosts := op.Lookup("hosts"); hosts.Exists() {
fields, err := hosts.Fields()
if err != nil {
return st, err
}
for _, host := range fields {
s, err := host.Value.String()
if err != nil {
return st, err
}
if err != nil {
return st, err
}
opts = append(opts, llb.AddExtraHost(host.Label(), net.ParseIP(s)))
}
}
if user := op.Lookup("user"); user.Exists() {
u, err := user.String()
if err != nil {
return st, err
}
opts = append(opts, llb.User(u))
}
// mounts // mounts
if mounts := op.Lookup("mount"); mounts.Exists() { if mounts := op.Lookup("mount"); mounts.Exists() {
mntOpts, err := p.mountAll(ctx, mounts) mntOpts, err := p.mountAll(ctx, mounts)

View File

@ -52,6 +52,10 @@ package op
// see https://github.com/dagger/dagger/issues/445 // see https://github.com/dagger/dagger/issues/445
// mount: [string]: "tmpfs" | "cache" | {from: _, path: string | *"/"} // mount: [string]: "tmpfs" | "cache" | {from: _, path: string | *"/"}
mount: [string]: _ mount: [string]: _
// Map of hostnames to ip
hosts?: [string]: string
// User to exec with (if left empty, will default to the set user in the image)
user?: string
} }
#DockerLogin: { #DockerLogin: {