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"
"fmt"
"io/fs"
"net"
"path"
"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
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
if mounts := op.Lookup("mount"); mounts.Exists() {
mntOpts, err := p.mountAll(ctx, mounts)

View File

@ -52,6 +52,10 @@ package op
// see https://github.com/dagger/dagger/issues/445
// mount: [string]: "tmpfs" | "cache" | {from: _, path: 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: {