mirror of
https://github.com/moby/buildkit.git
synced 2026-08-08 16:50:44 +00:00
llb: add extrahost support
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package llb
|
||||
|
||||
import (
|
||||
_ "crypto/sha256"
|
||||
"net"
|
||||
"sort"
|
||||
|
||||
"github.com/moby/buildkit/solver/pb"
|
||||
@@ -10,11 +11,12 @@ import (
|
||||
)
|
||||
|
||||
type Meta struct {
|
||||
Args []string
|
||||
Env EnvList
|
||||
Cwd string
|
||||
User string
|
||||
ProxyEnv *ProxyEnv
|
||||
Args []string
|
||||
Env EnvList
|
||||
Cwd string
|
||||
User string
|
||||
ProxyEnv *ProxyEnv
|
||||
ExtraHosts []HostIP
|
||||
}
|
||||
|
||||
func NewExecOp(root Output, meta Meta, readOnly bool, c Constraints) *ExecOp {
|
||||
@@ -127,13 +129,22 @@ func (e *ExecOp) Marshal(c *Constraints) (digest.Digest, []byte, *pb.OpMetadata,
|
||||
return e.mounts[i].target < e.mounts[j].target
|
||||
})
|
||||
|
||||
meta := &pb.Meta{
|
||||
Args: e.meta.Args,
|
||||
Env: e.meta.Env.ToArray(),
|
||||
Cwd: e.meta.Cwd,
|
||||
User: e.meta.User,
|
||||
}
|
||||
if len(e.meta.ExtraHosts) > 0 {
|
||||
hosts := make([]*pb.HostIP, len(e.meta.ExtraHosts))
|
||||
for i, h := range e.meta.ExtraHosts {
|
||||
hosts[i] = &pb.HostIP{Host: h.Host, IP: h.IP.String()}
|
||||
}
|
||||
meta.ExtraHosts = hosts
|
||||
}
|
||||
|
||||
peo := &pb.ExecOp{
|
||||
Meta: &pb.Meta{
|
||||
Args: e.meta.Args,
|
||||
Env: e.meta.Env.ToArray(),
|
||||
Cwd: e.meta.Cwd,
|
||||
User: e.meta.User,
|
||||
},
|
||||
Meta: meta,
|
||||
}
|
||||
|
||||
if p := e.meta.ProxyEnv; p != nil {
|
||||
@@ -386,6 +397,12 @@ func Dirf(str string, v ...interface{}) RunOption {
|
||||
})
|
||||
}
|
||||
|
||||
func AddExtraHost(host string, ip net.IP) RunOption {
|
||||
return runOptionFunc(func(ei *ExecInfo) {
|
||||
ei.State = ei.State.AddExtraHost(host, ip)
|
||||
})
|
||||
}
|
||||
|
||||
func Reset(s State) RunOption {
|
||||
return runOptionFunc(func(ei *ExecInfo) {
|
||||
ei.State = ei.State.Reset(s)
|
||||
|
||||
@@ -2,6 +2,7 @@ package llb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"path"
|
||||
|
||||
"github.com/containerd/containerd/platforms"
|
||||
@@ -12,11 +13,12 @@ import (
|
||||
type contextKeyT string
|
||||
|
||||
var (
|
||||
keyArgs = contextKeyT("llb.exec.args")
|
||||
keyDir = contextKeyT("llb.exec.dir")
|
||||
keyEnv = contextKeyT("llb.exec.env")
|
||||
keyUser = contextKeyT("llb.exec.user")
|
||||
keyPlatform = contextKeyT("llb.platform")
|
||||
keyArgs = contextKeyT("llb.exec.args")
|
||||
keyDir = contextKeyT("llb.exec.dir")
|
||||
keyEnv = contextKeyT("llb.exec.env")
|
||||
keyUser = contextKeyT("llb.exec.user")
|
||||
keyExtraHost = contextKeyT("llb.exec.extrahost")
|
||||
keyPlatform = contextKeyT("llb.platform")
|
||||
)
|
||||
|
||||
func addEnv(key, value string) StateOption {
|
||||
@@ -124,6 +126,25 @@ func getPlatform(s State) *specs.Platform {
|
||||
return nil
|
||||
}
|
||||
|
||||
func extraHost(host string, ip net.IP) StateOption {
|
||||
return func(s State) State {
|
||||
return s.WithValue(keyExtraHost, append(getExtraHosts(s), HostIP{Host: host, IP: ip}))
|
||||
}
|
||||
}
|
||||
|
||||
func getExtraHosts(s State) []HostIP {
|
||||
v := s.Value(keyExtraHost)
|
||||
if v != nil {
|
||||
return v.([]HostIP)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type HostIP struct {
|
||||
Host string
|
||||
IP net.IP
|
||||
}
|
||||
|
||||
type EnvList []KeyValue
|
||||
|
||||
type KeyValue struct {
|
||||
|
||||
@@ -3,6 +3,7 @@ package llb
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/moby/buildkit/identity"
|
||||
@@ -181,11 +182,12 @@ func (s State) Run(ro ...RunOption) ExecState {
|
||||
o.SetRunOption(ei)
|
||||
}
|
||||
meta := Meta{
|
||||
Args: getArgs(ei.State),
|
||||
Cwd: getDir(ei.State),
|
||||
Env: getEnv(ei.State),
|
||||
User: getUser(ei.State),
|
||||
ProxyEnv: ei.ProxyEnv,
|
||||
Args: getArgs(ei.State),
|
||||
Cwd: getDir(ei.State),
|
||||
Env: getEnv(ei.State),
|
||||
User: getUser(ei.State),
|
||||
ProxyEnv: ei.ProxyEnv,
|
||||
ExtraHosts: getExtraHosts(ei.State),
|
||||
}
|
||||
|
||||
exec := NewExecOp(s.Output(), meta, ei.ReadonlyRootFS, ei.Constraints)
|
||||
@@ -254,6 +256,10 @@ func (s State) With(so ...StateOption) State {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s State) AddExtraHost(host string, ip net.IP) State {
|
||||
return extraHost(host, ip)(s)
|
||||
}
|
||||
|
||||
type output struct {
|
||||
vertex Vertex
|
||||
getIndex func() (pb.OutputIndex, error)
|
||||
|
||||
Reference in New Issue
Block a user