Skip to content

Commit

Permalink
use ExtraHosts for Git/HTTP
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
  • Loading branch information
vito committed Jul 18, 2023
1 parent 633e143 commit 0c71523
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
26 changes: 26 additions & 0 deletions core/schema/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,32 @@ func (s *gitSchema) tree(ctx *router.Context, parent gitRef, args gitTreeArgs) (
if args.SSHAuthSocket != "" {
opts = append(opts, llb.MountSSHSock(args.SSHAuthSocket.LLBID()))
}

hosts := llb.ExtraHosts{}
if parent.Repository.ServiceHost != nil {
svc, err := parent.Repository.ServiceHost.ToService()
if err != nil {
return nil, err
}

running, err := core.AllServices.Start(ctx, s.gw, svc)
if err != nil {
return nil, err
}

host, err := svc.Hostname()
if err != nil {
return nil, err
}

hosts = append(hosts, llb.HostIP{
Host: host,
IP: running.IP,
})

opts = append(opts, hosts)
}

var svcs core.ServiceBindings
if parent.Repository.ServiceHost != nil {
svcs = core.ServiceBindings{*parent.Repository.ServiceHost: nil}
Expand Down
25 changes: 24 additions & 1 deletion core/schema/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,35 @@ type httpArgs struct {
func (s *httpSchema) http(ctx *router.Context, parent *core.Query, args httpArgs) (*core.File, error) {
pipeline := parent.PipelinePath()

hosts := llb.ExtraHosts{}
if args.ExperimentalServiceHost != nil {
svc, err := args.ExperimentalServiceHost.ToService()
if err != nil {
return nil, err
}

running, err := core.AllServices.Start(ctx, s.gw, svc)
if err != nil {
return nil, err
}

host, err := svc.Hostname()
if err != nil {
return nil, err
}

hosts = append(hosts, llb.HostIP{
Host: host,
IP: running.IP,
})
}

// Use a filename that is set to the URL. Buildkit internally stores some cache metadata of etags
// and http checksums using an id based on this name, so setting it to the URL maximizes our chances
// of following more optimized cache codepaths.
// Do a hash encode to prevent conflicts with use of `/` in the URL while also not hitting max filename limits
filename := digest.FromString(args.URL).Encoded()
st := llb.HTTP(args.URL, llb.Filename(filename))
st := llb.HTTP(args.URL, llb.Filename(filename), hosts)

svcs := core.ServiceBindings{}
if args.ExperimentalServiceHost != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/moby/buildkit => github.com/vito/buildkit v0.10.1-0.20230618015906-18eecc789079
replace github.com/moby/buildkit => github.com/vito/buildkit v0.10.1-0.20230618050111-46c7a2e53218
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1941,8 +1941,8 @@ github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc/go.mod h1:ZjcWmF
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/vito/buildkit v0.10.1-0.20230618015906-18eecc789079 h1:j0TpkHbGq8ho32Rvj8gZXoYV0NJo6qiOf/eU92C8jIk=
github.com/vito/buildkit v0.10.1-0.20230618015906-18eecc789079/go.mod h1:6Y1HYDrxg3sY5gBY2FVaEvQpswBj3g/ck7aKYCjOkk0=
github.com/vito/buildkit v0.10.1-0.20230618050111-46c7a2e53218 h1:wPherC9uFUNd2X/GjZHelX4D1uewQca6WPUMOypx2Bc=
github.com/vito/buildkit v0.10.1-0.20230618050111-46c7a2e53218/go.mod h1:6Y1HYDrxg3sY5gBY2FVaEvQpswBj3g/ck7aKYCjOkk0=
github.com/vito/progrock v0.7.1-0.20230628234355-c8ce2c2e3c24 h1:E6NeGFp8/YGYHnWtwzP5lrphxXLmoKsoAvdwuIkUTOk=
github.com/vito/progrock v0.7.1-0.20230628234355-c8ce2c2e3c24/go.mod h1:YjiMvY2X47zc9H5je8w4V59cTSrV2d0vQPwJOB5TLH8=
github.com/vito/vt100 v0.1.2 h1:gRhKJ/shHTRfMHg+Wc5ExHJzV6HHZqyQIAL52x4EUmA=
Expand Down

0 comments on commit 0c71523

Please sign in to comment.