-
Notifications
You must be signed in to change notification settings - Fork 557
/
state.go
38 lines (33 loc) · 914 Bytes
/
state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package httpdns
import (
"strconv"
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/solver/pb"
)
// HTTP is a helper mimicking the llb.HTTP function, but with the ability to
// set additional attributes.
func HTTP(url string, namespace string, opts ...llb.HTTPOption) llb.State {
hi := &llb.HTTPInfo{}
for _, o := range opts {
o.SetHTTPOption(hi)
}
attrs := map[string]string{}
if hi.Checksum != "" {
attrs[pb.AttrHTTPChecksum] = hi.Checksum.String()
}
if hi.Filename != "" {
attrs[pb.AttrHTTPFilename] = hi.Filename
}
if hi.Perm != 0 {
attrs[pb.AttrHTTPPerm] = "0" + strconv.FormatInt(int64(hi.Perm), 8)
}
if hi.UID != 0 {
attrs[pb.AttrHTTPUID] = strconv.Itoa(hi.UID)
}
if hi.GID != 0 {
attrs[pb.AttrHTTPGID] = strconv.Itoa(hi.GID)
}
attrs[AttrDNSNamespace] = namespace
source := llb.NewSource(url, attrs, hi.Constraints)
return llb.NewState(source.Output())
}