id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
161,700 | moby/buildkit | session/manager.go | HandleConn | func (sm *Manager) HandleConn(ctx context.Context, conn net.Conn, opts map[string][]string) error {
sm.mu.Lock()
return sm.handleConn(ctx, conn, opts)
} | go | func (sm *Manager) HandleConn(ctx context.Context, conn net.Conn, opts map[string][]string) error {
sm.mu.Lock()
return sm.handleConn(ctx, conn, opts)
} | [
"func",
"(",
"sm",
"*",
"Manager",
")",
"HandleConn",
"(",
"ctx",
"context",
".",
"Context",
",",
"conn",
"net",
".",
"Conn",
",",
"opts",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"error",
"{",
"sm",
".",
"mu",
".",
"Lock",
"(",
")",
... | // HandleConn handles an incoming raw connection | [
"HandleConn",
"handles",
"an",
"incoming",
"raw",
"connection"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/session/manager.go#L95-L98 |
161,701 | moby/buildkit | session/manager.go | handleConn | func (sm *Manager) handleConn(ctx context.Context, conn net.Conn, opts map[string][]string) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
opts = canonicalHeaders(opts)
h := http.Header(opts)
id := h.Get(headerSessionID)
name := h.Get(headerSessionName)
sharedKey := h.Get(headerSessionSharedKey)
ctx, cc, err := grpcClientConn(ctx, conn)
if err != nil {
sm.mu.Unlock()
return err
}
c := &client{
Session: Session{
id: id,
name: name,
sharedKey: sharedKey,
ctx: ctx,
cancelCtx: cancel,
done: make(chan struct{}),
},
cc: cc,
supported: make(map[string]struct{}),
}
for _, m := range opts[headerSessionMethod] {
c.supported[strings.ToLower(m)] = struct{}{}
}
sm.sessions[id] = c
sm.updateCondition.Broadcast()
sm.mu.Unlock()
defer func() {
sm.mu.Lock()
delete(sm.sessions, id)
sm.mu.Unlock()
}()
<-c.ctx.Done()
conn.Close()
close(c.done)
return nil
} | go | func (sm *Manager) handleConn(ctx context.Context, conn net.Conn, opts map[string][]string) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
opts = canonicalHeaders(opts)
h := http.Header(opts)
id := h.Get(headerSessionID)
name := h.Get(headerSessionName)
sharedKey := h.Get(headerSessionSharedKey)
ctx, cc, err := grpcClientConn(ctx, conn)
if err != nil {
sm.mu.Unlock()
return err
}
c := &client{
Session: Session{
id: id,
name: name,
sharedKey: sharedKey,
ctx: ctx,
cancelCtx: cancel,
done: make(chan struct{}),
},
cc: cc,
supported: make(map[string]struct{}),
}
for _, m := range opts[headerSessionMethod] {
c.supported[strings.ToLower(m)] = struct{}{}
}
sm.sessions[id] = c
sm.updateCondition.Broadcast()
sm.mu.Unlock()
defer func() {
sm.mu.Lock()
delete(sm.sessions, id)
sm.mu.Unlock()
}()
<-c.ctx.Done()
conn.Close()
close(c.done)
return nil
} | [
"func",
"(",
"sm",
"*",
"Manager",
")",
"handleConn",
"(",
"ctx",
"context",
".",
"Context",
",",
"conn",
"net",
".",
"Conn",
",",
"opts",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"error",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",... | // caller needs to take lock, this function will release it | [
"caller",
"needs",
"to",
"take",
"lock",
"this",
"function",
"will",
"release",
"it"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/session/manager.go#L101-L149 |
161,702 | moby/buildkit | session/manager.go | Get | func (sm *Manager) Get(ctx context.Context, id string) (Caller, error) {
// session prefix is used to identify vertexes with different contexts so
// they would not collide, but for lookup we don't need the prefix
if p := strings.SplitN(id, ":", 2); len(p) == 2 && len(p[1]) > 0 {
id = p[1]
}
ctx, cancel := context.WithCancel(ctx)
defer cancel()
go func() {
select {
case <-ctx.Done():
sm.updateCondition.Broadcast()
}
}()
var c *client
sm.mu.Lock()
for {
select {
case <-ctx.Done():
sm.mu.Unlock()
return nil, errors.Wrapf(ctx.Err(), "no active session for %s", id)
default:
}
var ok bool
c, ok = sm.sessions[id]
if !ok || c.closed() {
sm.updateCondition.Wait()
continue
}
sm.mu.Unlock()
break
}
return c, nil
} | go | func (sm *Manager) Get(ctx context.Context, id string) (Caller, error) {
// session prefix is used to identify vertexes with different contexts so
// they would not collide, but for lookup we don't need the prefix
if p := strings.SplitN(id, ":", 2); len(p) == 2 && len(p[1]) > 0 {
id = p[1]
}
ctx, cancel := context.WithCancel(ctx)
defer cancel()
go func() {
select {
case <-ctx.Done():
sm.updateCondition.Broadcast()
}
}()
var c *client
sm.mu.Lock()
for {
select {
case <-ctx.Done():
sm.mu.Unlock()
return nil, errors.Wrapf(ctx.Err(), "no active session for %s", id)
default:
}
var ok bool
c, ok = sm.sessions[id]
if !ok || c.closed() {
sm.updateCondition.Wait()
continue
}
sm.mu.Unlock()
break
}
return c, nil
} | [
"func",
"(",
"sm",
"*",
"Manager",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
")",
"(",
"Caller",
",",
"error",
")",
"{",
"// session prefix is used to identify vertexes with different contexts so",
"// they would not collide, but for lookup... | // Get returns a session by ID | [
"Get",
"returns",
"a",
"session",
"by",
"ID"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/session/manager.go#L152-L190 |
161,703 | moby/buildkit | util/flightcontrol/flightcontrol.go | Do | func (g *Group) Do(ctx context.Context, key string, fn func(ctx context.Context) (interface{}, error)) (v interface{}, err error) {
var backoff time.Duration
for {
v, err = g.do(ctx, key, fn)
if err == nil || errors.Cause(err) != errRetry {
return v, err
}
// backoff logic
if backoff >= 3*time.Second {
err = errors.Wrapf(errRetryTimeout, "flightcontrol")
return v, err
}
runtime.Gosched()
if backoff > 0 {
time.Sleep(backoff)
backoff *= 2
} else {
backoff = time.Millisecond
}
}
} | go | func (g *Group) Do(ctx context.Context, key string, fn func(ctx context.Context) (interface{}, error)) (v interface{}, err error) {
var backoff time.Duration
for {
v, err = g.do(ctx, key, fn)
if err == nil || errors.Cause(err) != errRetry {
return v, err
}
// backoff logic
if backoff >= 3*time.Second {
err = errors.Wrapf(errRetryTimeout, "flightcontrol")
return v, err
}
runtime.Gosched()
if backoff > 0 {
time.Sleep(backoff)
backoff *= 2
} else {
backoff = time.Millisecond
}
}
} | [
"func",
"(",
"g",
"*",
"Group",
")",
"Do",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
"string",
",",
"fn",
"func",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
")",
"(",
"v",
"interface",
"{",... | // Do executes a context function syncronized by the key | [
"Do",
"executes",
"a",
"context",
"function",
"syncronized",
"by",
"the",
"key"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/flightcontrol/flightcontrol.go#L34-L54 |
161,704 | moby/buildkit | util/flightcontrol/flightcontrol.go | signal | func (c *sharedContext) signal() {
select {
case <-c.done:
default:
var err error
for _, ctx := range c.ctxs {
select {
case <-ctx.Done():
err = ctx.Err()
default:
return
}
}
c.err = err
close(c.done)
}
} | go | func (c *sharedContext) signal() {
select {
case <-c.done:
default:
var err error
for _, ctx := range c.ctxs {
select {
case <-ctx.Done():
err = ctx.Err()
default:
return
}
}
c.err = err
close(c.done)
}
} | [
"func",
"(",
"c",
"*",
"sharedContext",
")",
"signal",
"(",
")",
"{",
"select",
"{",
"case",
"<-",
"c",
".",
"done",
":",
"default",
":",
"var",
"err",
"error",
"\n",
"for",
"_",
",",
"ctx",
":=",
"range",
"c",
".",
"ctxs",
"{",
"select",
"{",
... | // call with lock | [
"call",
"with",
"lock"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/flightcontrol/flightcontrol.go#L236-L252 |
161,705 | moby/buildkit | snapshot/blobmapping/snapshotter.go | Remove | func (s *Snapshotter) Remove(ctx context.Context, key string) error {
_, blob, err := s.GetBlob(ctx, key)
if err != nil {
return err
}
blobs, err := s.opt.MetadataStore.Search(index(blob))
if err != nil {
return err
}
if err := s.SnapshotterBase.Remove(ctx, key); err != nil {
return err
}
if len(blobs) == 1 && blobs[0].ID() == key { // last snapshot
if err := s.opt.Content.Delete(ctx, blob); err != nil {
logrus.Errorf("failed to delete blob %v: %+v", blob, err)
}
}
return nil
} | go | func (s *Snapshotter) Remove(ctx context.Context, key string) error {
_, blob, err := s.GetBlob(ctx, key)
if err != nil {
return err
}
blobs, err := s.opt.MetadataStore.Search(index(blob))
if err != nil {
return err
}
if err := s.SnapshotterBase.Remove(ctx, key); err != nil {
return err
}
if len(blobs) == 1 && blobs[0].ID() == key { // last snapshot
if err := s.opt.Content.Delete(ctx, blob); err != nil {
logrus.Errorf("failed to delete blob %v: %+v", blob, err)
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"Snapshotter",
")",
"Remove",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
"string",
")",
"error",
"{",
"_",
",",
"blob",
",",
"err",
":=",
"s",
".",
"GetBlob",
"(",
"ctx",
",",
"key",
")",
"\n",
"if",
"err",
"!=",
... | // Remove also removes a reference to a blob. If it is a last reference then it deletes it the blob as well
// Remove is not safe to be called concurrently | [
"Remove",
"also",
"removes",
"a",
"reference",
"to",
"a",
"blob",
".",
"If",
"it",
"is",
"a",
"last",
"reference",
"then",
"it",
"deletes",
"it",
"the",
"blob",
"as",
"well",
"Remove",
"is",
"not",
"safe",
"to",
"be",
"called",
"concurrently"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/snapshot/blobmapping/snapshotter.go#L51-L72 |
161,706 | moby/buildkit | snapshot/blobmapping/snapshotter.go | SetBlob | func (s *Snapshotter) SetBlob(ctx context.Context, key string, diffID, blobsum digest.Digest) error {
info, err := s.opt.Content.Info(ctx, blobsum)
if err != nil {
return err
}
if _, ok := info.Labels["containerd.io/uncompressed"]; !ok {
labels := map[string]string{
"containerd.io/uncompressed": diffID.String(),
}
if _, err := s.opt.Content.Update(ctx, content.Info{
Digest: blobsum,
Labels: labels,
}, "labels.containerd.io/uncompressed"); err != nil {
return err
}
}
md, _ := s.opt.MetadataStore.Get(key)
v, err := metadata.NewValue(DiffPair{DiffID: diffID, Blobsum: blobsum})
if err != nil {
return err
}
v.Index = index(blobsum)
return md.Update(func(b *bolt.Bucket) error {
return md.SetValue(b, blobKey, v)
})
} | go | func (s *Snapshotter) SetBlob(ctx context.Context, key string, diffID, blobsum digest.Digest) error {
info, err := s.opt.Content.Info(ctx, blobsum)
if err != nil {
return err
}
if _, ok := info.Labels["containerd.io/uncompressed"]; !ok {
labels := map[string]string{
"containerd.io/uncompressed": diffID.String(),
}
if _, err := s.opt.Content.Update(ctx, content.Info{
Digest: blobsum,
Labels: labels,
}, "labels.containerd.io/uncompressed"); err != nil {
return err
}
}
md, _ := s.opt.MetadataStore.Get(key)
v, err := metadata.NewValue(DiffPair{DiffID: diffID, Blobsum: blobsum})
if err != nil {
return err
}
v.Index = index(blobsum)
return md.Update(func(b *bolt.Bucket) error {
return md.SetValue(b, blobKey, v)
})
} | [
"func",
"(",
"s",
"*",
"Snapshotter",
")",
"SetBlob",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
"string",
",",
"diffID",
",",
"blobsum",
"digest",
".",
"Digest",
")",
"error",
"{",
"info",
",",
"err",
":=",
"s",
".",
"opt",
".",
"Content",
... | // Validates that there is no blob associated with the snapshot.
// Checks that there is a blob in the content store.
// If same blob has already been set then this is a noop. | [
"Validates",
"that",
"there",
"is",
"no",
"blob",
"associated",
"with",
"the",
"snapshot",
".",
"Checks",
"that",
"there",
"is",
"a",
"blob",
"in",
"the",
"content",
"store",
".",
"If",
"same",
"blob",
"has",
"already",
"been",
"set",
"then",
"this",
"is... | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/snapshot/blobmapping/snapshotter.go#L109-L136 |
161,707 | moby/buildkit | solver/scheduler.go | signal | func (s *scheduler) signal(e *edge) {
s.muQ.Lock()
if _, ok := s.waitq[e]; !ok {
d := &dispatcher{e: e}
if s.last == nil {
s.next = d
} else {
s.last.next = d
}
s.last = d
s.waitq[e] = struct{}{}
s.cond.Signal()
}
s.muQ.Unlock()
} | go | func (s *scheduler) signal(e *edge) {
s.muQ.Lock()
if _, ok := s.waitq[e]; !ok {
d := &dispatcher{e: e}
if s.last == nil {
s.next = d
} else {
s.last.next = d
}
s.last = d
s.waitq[e] = struct{}{}
s.cond.Signal()
}
s.muQ.Unlock()
} | [
"func",
"(",
"s",
"*",
"scheduler",
")",
"signal",
"(",
"e",
"*",
"edge",
")",
"{",
"s",
".",
"muQ",
".",
"Lock",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"s",
".",
"waitq",
"[",
"e",
"]",
";",
"!",
"ok",
"{",
"d",
":=",
"&",
"dispatch... | // signal notifies that an edge needs to be processed again | [
"signal",
"notifies",
"that",
"an",
"edge",
"needs",
"to",
"be",
"processed",
"again"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/scheduler.go#L193-L207 |
161,708 | moby/buildkit | solver/scheduler.go | build | func (s *scheduler) build(ctx context.Context, edge Edge) (CachedResult, error) {
s.mu.Lock()
e := s.ef.getEdge(edge)
if e == nil {
s.mu.Unlock()
return nil, errors.Errorf("invalid request %v for build", edge)
}
wait := make(chan struct{})
var p *pipe.Pipe
p = s.newPipe(e, nil, pipe.Request{Payload: &edgeRequest{desiredState: edgeStatusComplete}})
p.OnSendCompletion = func() {
p.Receiver.Receive()
if p.Receiver.Status().Completed {
close(wait)
}
}
s.mu.Unlock()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
go func() {
<-ctx.Done()
p.Receiver.Cancel()
}()
<-wait
if err := p.Receiver.Status().Err; err != nil {
return nil, err
}
return p.Receiver.Status().Value.(*edgeState).result.Clone(), nil
} | go | func (s *scheduler) build(ctx context.Context, edge Edge) (CachedResult, error) {
s.mu.Lock()
e := s.ef.getEdge(edge)
if e == nil {
s.mu.Unlock()
return nil, errors.Errorf("invalid request %v for build", edge)
}
wait := make(chan struct{})
var p *pipe.Pipe
p = s.newPipe(e, nil, pipe.Request{Payload: &edgeRequest{desiredState: edgeStatusComplete}})
p.OnSendCompletion = func() {
p.Receiver.Receive()
if p.Receiver.Status().Completed {
close(wait)
}
}
s.mu.Unlock()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
go func() {
<-ctx.Done()
p.Receiver.Cancel()
}()
<-wait
if err := p.Receiver.Status().Err; err != nil {
return nil, err
}
return p.Receiver.Status().Value.(*edgeState).result.Clone(), nil
} | [
"func",
"(",
"s",
"*",
"scheduler",
")",
"build",
"(",
"ctx",
"context",
".",
"Context",
",",
"edge",
"Edge",
")",
"(",
"CachedResult",
",",
"error",
")",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"e",
":=",
"s",
".",
"ef",
".",
"getEdg... | // build evaluates edge into a result | [
"build",
"evaluates",
"edge",
"into",
"a",
"result"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/scheduler.go#L210-L244 |
161,709 | moby/buildkit | solver/scheduler.go | newPipe | func (s *scheduler) newPipe(target, from *edge, req pipe.Request) *pipe.Pipe {
p := &edgePipe{
Pipe: pipe.New(req),
Target: target,
From: from,
}
s.signal(target)
if from != nil {
p.OnSendCompletion = func() {
p.mu.Lock()
defer p.mu.Unlock()
s.signal(p.From)
}
s.outgoing[from] = append(s.outgoing[from], p)
}
s.incoming[target] = append(s.incoming[target], p)
p.OnReceiveCompletion = func() {
p.mu.Lock()
defer p.mu.Unlock()
s.signal(p.Target)
}
return p.Pipe
} | go | func (s *scheduler) newPipe(target, from *edge, req pipe.Request) *pipe.Pipe {
p := &edgePipe{
Pipe: pipe.New(req),
Target: target,
From: from,
}
s.signal(target)
if from != nil {
p.OnSendCompletion = func() {
p.mu.Lock()
defer p.mu.Unlock()
s.signal(p.From)
}
s.outgoing[from] = append(s.outgoing[from], p)
}
s.incoming[target] = append(s.incoming[target], p)
p.OnReceiveCompletion = func() {
p.mu.Lock()
defer p.mu.Unlock()
s.signal(p.Target)
}
return p.Pipe
} | [
"func",
"(",
"s",
"*",
"scheduler",
")",
"newPipe",
"(",
"target",
",",
"from",
"*",
"edge",
",",
"req",
"pipe",
".",
"Request",
")",
"*",
"pipe",
".",
"Pipe",
"{",
"p",
":=",
"&",
"edgePipe",
"{",
"Pipe",
":",
"pipe",
".",
"New",
"(",
"req",
"... | // newPipe creates a new request pipe between two edges | [
"newPipe",
"creates",
"a",
"new",
"request",
"pipe",
"between",
"two",
"edges"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/scheduler.go#L247-L270 |
161,710 | moby/buildkit | solver/scheduler.go | newRequestWithFunc | func (s *scheduler) newRequestWithFunc(e *edge, f func(context.Context) (interface{}, error)) pipe.Receiver {
pp, start := pipe.NewWithFunction(f)
p := &edgePipe{
Pipe: pp,
From: e,
}
p.OnSendCompletion = func() {
p.mu.Lock()
defer p.mu.Unlock()
s.signal(p.From)
}
s.outgoing[e] = append(s.outgoing[e], p)
go start()
return p.Receiver
} | go | func (s *scheduler) newRequestWithFunc(e *edge, f func(context.Context) (interface{}, error)) pipe.Receiver {
pp, start := pipe.NewWithFunction(f)
p := &edgePipe{
Pipe: pp,
From: e,
}
p.OnSendCompletion = func() {
p.mu.Lock()
defer p.mu.Unlock()
s.signal(p.From)
}
s.outgoing[e] = append(s.outgoing[e], p)
go start()
return p.Receiver
} | [
"func",
"(",
"s",
"*",
"scheduler",
")",
"newRequestWithFunc",
"(",
"e",
"*",
"edge",
",",
"f",
"func",
"(",
"context",
".",
"Context",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
")",
"pipe",
".",
"Receiver",
"{",
"pp",
",",
"start",
":=",... | // newRequestWithFunc creates a new request pipe that invokes a async function | [
"newRequestWithFunc",
"creates",
"a",
"new",
"request",
"pipe",
"that",
"invokes",
"a",
"async",
"function"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/scheduler.go#L273-L287 |
161,711 | moby/buildkit | solver/scheduler.go | mergeTo | func (s *scheduler) mergeTo(target, src *edge) bool {
if !target.edge.Vertex.Options().IgnoreCache && src.edge.Vertex.Options().IgnoreCache {
return false
}
for _, inc := range s.incoming[src] {
inc.mu.Lock()
inc.Target = target
s.incoming[target] = append(s.incoming[target], inc)
inc.mu.Unlock()
}
for _, out := range s.outgoing[src] {
out.mu.Lock()
out.From = target
s.outgoing[target] = append(s.outgoing[target], out)
out.mu.Unlock()
out.Receiver.Cancel()
}
delete(s.incoming, src)
delete(s.outgoing, src)
s.signal(target)
for i, d := range src.deps {
for _, k := range d.keys {
target.secondaryExporters = append(target.secondaryExporters, expDep{i, CacheKeyWithSelector{CacheKey: k, Selector: src.cacheMap.Deps[i].Selector}})
}
if d.slowCacheKey != nil {
target.secondaryExporters = append(target.secondaryExporters, expDep{i, CacheKeyWithSelector{CacheKey: *d.slowCacheKey}})
}
if d.result != nil {
for _, dk := range d.result.CacheKeys() {
target.secondaryExporters = append(target.secondaryExporters, expDep{i, CacheKeyWithSelector{CacheKey: dk, Selector: src.cacheMap.Deps[i].Selector}})
}
}
}
// TODO(tonistiigi): merge cache providers
return true
} | go | func (s *scheduler) mergeTo(target, src *edge) bool {
if !target.edge.Vertex.Options().IgnoreCache && src.edge.Vertex.Options().IgnoreCache {
return false
}
for _, inc := range s.incoming[src] {
inc.mu.Lock()
inc.Target = target
s.incoming[target] = append(s.incoming[target], inc)
inc.mu.Unlock()
}
for _, out := range s.outgoing[src] {
out.mu.Lock()
out.From = target
s.outgoing[target] = append(s.outgoing[target], out)
out.mu.Unlock()
out.Receiver.Cancel()
}
delete(s.incoming, src)
delete(s.outgoing, src)
s.signal(target)
for i, d := range src.deps {
for _, k := range d.keys {
target.secondaryExporters = append(target.secondaryExporters, expDep{i, CacheKeyWithSelector{CacheKey: k, Selector: src.cacheMap.Deps[i].Selector}})
}
if d.slowCacheKey != nil {
target.secondaryExporters = append(target.secondaryExporters, expDep{i, CacheKeyWithSelector{CacheKey: *d.slowCacheKey}})
}
if d.result != nil {
for _, dk := range d.result.CacheKeys() {
target.secondaryExporters = append(target.secondaryExporters, expDep{i, CacheKeyWithSelector{CacheKey: dk, Selector: src.cacheMap.Deps[i].Selector}})
}
}
}
// TODO(tonistiigi): merge cache providers
return true
} | [
"func",
"(",
"s",
"*",
"scheduler",
")",
"mergeTo",
"(",
"target",
",",
"src",
"*",
"edge",
")",
"bool",
"{",
"if",
"!",
"target",
".",
"edge",
".",
"Vertex",
".",
"Options",
"(",
")",
".",
"IgnoreCache",
"&&",
"src",
".",
"edge",
".",
"Vertex",
... | // mergeTo merges the state from one edge to another. source edge is discarded. | [
"mergeTo",
"merges",
"the",
"state",
"from",
"one",
"edge",
"to",
"another",
".",
"source",
"edge",
"is",
"discarded",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/scheduler.go#L290-L330 |
161,712 | moby/buildkit | session/sshforward/sshprovider/agentprovider.go | NewSSHAgentProvider | func NewSSHAgentProvider(confs []AgentConfig) (session.Attachable, error) {
m := map[string]source{}
for _, conf := range confs {
if len(conf.Paths) == 0 || len(conf.Paths) == 1 && conf.Paths[0] == "" {
conf.Paths = []string{os.Getenv("SSH_AUTH_SOCK")}
}
if conf.Paths[0] == "" {
return nil, errors.Errorf("invalid empty ssh agent socket, make sure SSH_AUTH_SOCK is set")
}
src, err := toAgentSource(conf.Paths)
if err != nil {
return nil, err
}
if conf.ID == "" {
conf.ID = sshforward.DefaultID
}
if _, ok := m[conf.ID]; ok {
return nil, errors.Errorf("invalid duplicate ID %s", conf.ID)
}
m[conf.ID] = src
}
return &socketProvider{m: m}, nil
} | go | func NewSSHAgentProvider(confs []AgentConfig) (session.Attachable, error) {
m := map[string]source{}
for _, conf := range confs {
if len(conf.Paths) == 0 || len(conf.Paths) == 1 && conf.Paths[0] == "" {
conf.Paths = []string{os.Getenv("SSH_AUTH_SOCK")}
}
if conf.Paths[0] == "" {
return nil, errors.Errorf("invalid empty ssh agent socket, make sure SSH_AUTH_SOCK is set")
}
src, err := toAgentSource(conf.Paths)
if err != nil {
return nil, err
}
if conf.ID == "" {
conf.ID = sshforward.DefaultID
}
if _, ok := m[conf.ID]; ok {
return nil, errors.Errorf("invalid duplicate ID %s", conf.ID)
}
m[conf.ID] = src
}
return &socketProvider{m: m}, nil
} | [
"func",
"NewSSHAgentProvider",
"(",
"confs",
"[",
"]",
"AgentConfig",
")",
"(",
"session",
".",
"Attachable",
",",
"error",
")",
"{",
"m",
":=",
"map",
"[",
"string",
"]",
"source",
"{",
"}",
"\n",
"for",
"_",
",",
"conf",
":=",
"range",
"confs",
"{"... | // NewSSHAgentProvider creates a session provider that allows access to ssh agent | [
"NewSSHAgentProvider",
"creates",
"a",
"session",
"provider",
"that",
"allows",
"access",
"to",
"ssh",
"agent"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/session/sshforward/sshprovider/agentprovider.go#L28-L53 |
161,713 | moby/buildkit | frontend/dockerfile/parser/parser.go | Dump | func (node *Node) Dump() string {
str := ""
str += node.Value
if len(node.Flags) > 0 {
str += fmt.Sprintf(" %q", node.Flags)
}
for _, n := range node.Children {
str += "(" + n.Dump() + ")\n"
}
for n := node.Next; n != nil; n = n.Next {
if len(n.Children) > 0 {
str += " " + n.Dump()
} else {
str += " " + strconv.Quote(n.Value)
}
}
return strings.TrimSpace(str)
} | go | func (node *Node) Dump() string {
str := ""
str += node.Value
if len(node.Flags) > 0 {
str += fmt.Sprintf(" %q", node.Flags)
}
for _, n := range node.Children {
str += "(" + n.Dump() + ")\n"
}
for n := node.Next; n != nil; n = n.Next {
if len(n.Children) > 0 {
str += " " + n.Dump()
} else {
str += " " + strconv.Quote(n.Value)
}
}
return strings.TrimSpace(str)
} | [
"func",
"(",
"node",
"*",
"Node",
")",
"Dump",
"(",
")",
"string",
"{",
"str",
":=",
"\"",
"\"",
"\n",
"str",
"+=",
"node",
".",
"Value",
"\n\n",
"if",
"len",
"(",
"node",
".",
"Flags",
")",
">",
"0",
"{",
"str",
"+=",
"fmt",
".",
"Sprintf",
... | // Dump dumps the AST defined by `node` as a list of sexps.
// Returns a string suitable for printing. | [
"Dump",
"dumps",
"the",
"AST",
"defined",
"by",
"node",
"as",
"a",
"list",
"of",
"sexps",
".",
"Returns",
"a",
"string",
"suitable",
"for",
"printing",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/parser/parser.go#L43-L64 |
161,714 | moby/buildkit | frontend/dockerfile/parser/parser.go | AddChild | func (node *Node) AddChild(child *Node, startLine, endLine int) {
child.lines(startLine, endLine)
if node.StartLine < 0 {
node.StartLine = startLine
}
node.endLine = endLine
node.Children = append(node.Children, child)
} | go | func (node *Node) AddChild(child *Node, startLine, endLine int) {
child.lines(startLine, endLine)
if node.StartLine < 0 {
node.StartLine = startLine
}
node.endLine = endLine
node.Children = append(node.Children, child)
} | [
"func",
"(",
"node",
"*",
"Node",
")",
"AddChild",
"(",
"child",
"*",
"Node",
",",
"startLine",
",",
"endLine",
"int",
")",
"{",
"child",
".",
"lines",
"(",
"startLine",
",",
"endLine",
")",
"\n",
"if",
"node",
".",
"StartLine",
"<",
"0",
"{",
"nod... | // AddChild adds a new child node, and updates line information | [
"AddChild",
"adds",
"a",
"new",
"child",
"node",
"and",
"updates",
"line",
"information"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/parser/parser.go#L72-L79 |
161,715 | moby/buildkit | frontend/dockerfile/parser/parser.go | setEscapeToken | func (d *Directive) setEscapeToken(s string) error {
if s != "`" && s != "\\" {
return fmt.Errorf("invalid ESCAPE '%s'. Must be ` or \\", s)
}
d.escapeToken = rune(s[0])
d.lineContinuationRegex = regexp.MustCompile(`\` + s + `[ \t]*$`)
return nil
} | go | func (d *Directive) setEscapeToken(s string) error {
if s != "`" && s != "\\" {
return fmt.Errorf("invalid ESCAPE '%s'. Must be ` or \\", s)
}
d.escapeToken = rune(s[0])
d.lineContinuationRegex = regexp.MustCompile(`\` + s + `[ \t]*$`)
return nil
} | [
"func",
"(",
"d",
"*",
"Directive",
")",
"setEscapeToken",
"(",
"s",
"string",
")",
"error",
"{",
"if",
"s",
"!=",
"\"",
"\"",
"&&",
"s",
"!=",
"\"",
"\\\\",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\\\",
"\"",
",",
"s",
")",
"\n... | // setEscapeToken sets the default token for escaping characters in a Dockerfile. | [
"setEscapeToken",
"sets",
"the",
"default",
"token",
"for",
"escaping",
"characters",
"in",
"a",
"Dockerfile",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/parser/parser.go#L101-L108 |
161,716 | moby/buildkit | frontend/dockerfile/parser/parser.go | newNodeFromLine | func newNodeFromLine(line string, directive *Directive) (*Node, error) {
cmd, flags, args, err := splitCommand(line)
if err != nil {
return nil, err
}
fn := dispatch[cmd]
// Ignore invalid Dockerfile instructions
if fn == nil {
fn = parseIgnore
}
next, attrs, err := fn(args, directive)
if err != nil {
return nil, err
}
return &Node{
Value: cmd,
Original: line,
Flags: flags,
Next: next,
Attributes: attrs,
}, nil
} | go | func newNodeFromLine(line string, directive *Directive) (*Node, error) {
cmd, flags, args, err := splitCommand(line)
if err != nil {
return nil, err
}
fn := dispatch[cmd]
// Ignore invalid Dockerfile instructions
if fn == nil {
fn = parseIgnore
}
next, attrs, err := fn(args, directive)
if err != nil {
return nil, err
}
return &Node{
Value: cmd,
Original: line,
Flags: flags,
Next: next,
Attributes: attrs,
}, nil
} | [
"func",
"newNodeFromLine",
"(",
"line",
"string",
",",
"directive",
"*",
"Directive",
")",
"(",
"*",
"Node",
",",
"error",
")",
"{",
"cmd",
",",
"flags",
",",
"args",
",",
"err",
":=",
"splitCommand",
"(",
"line",
")",
"\n",
"if",
"err",
"!=",
"nil",... | // newNodeFromLine splits the line into parts, and dispatches to a function
// based on the command and command arguments. A Node is created from the
// result of the dispatch. | [
"newNodeFromLine",
"splits",
"the",
"line",
"into",
"parts",
"and",
"dispatches",
"to",
"a",
"function",
"based",
"on",
"the",
"command",
"and",
"command",
"arguments",
".",
"A",
"Node",
"is",
"created",
"from",
"the",
"result",
"of",
"the",
"dispatch",
"."
... | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/parser/parser.go#L174-L197 |
161,717 | moby/buildkit | frontend/dockerfile/parser/parser.go | PrintWarnings | func (r *Result) PrintWarnings(out io.Writer) {
if len(r.Warnings) == 0 {
return
}
fmt.Fprintf(out, strings.Join(r.Warnings, "\n")+"\n")
} | go | func (r *Result) PrintWarnings(out io.Writer) {
if len(r.Warnings) == 0 {
return
}
fmt.Fprintf(out, strings.Join(r.Warnings, "\n")+"\n")
} | [
"func",
"(",
"r",
"*",
"Result",
")",
"PrintWarnings",
"(",
"out",
"io",
".",
"Writer",
")",
"{",
"if",
"len",
"(",
"r",
".",
"Warnings",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"strings",
".",
"J... | // PrintWarnings to the writer | [
"PrintWarnings",
"to",
"the",
"writer"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/parser/parser.go#L207-L212 |
161,718 | moby/buildkit | client/ociindex/ociindex.go | PutDescToIndex | func PutDescToIndex(index *v1.Index, desc v1.Descriptor, tag string) error {
if index == nil {
index = &v1.Index{}
}
if index.SchemaVersion == 0 {
index.SchemaVersion = 2
}
if tag != "" {
if desc.Annotations == nil {
desc.Annotations = make(map[string]string)
}
desc.Annotations[v1.AnnotationRefName] = tag
// remove existing manifests with the same tag
var manifests []v1.Descriptor
for _, m := range index.Manifests {
if m.Annotations[v1.AnnotationRefName] != tag {
manifests = append(manifests, m)
}
}
index.Manifests = manifests
}
index.Manifests = append(index.Manifests, desc)
return nil
} | go | func PutDescToIndex(index *v1.Index, desc v1.Descriptor, tag string) error {
if index == nil {
index = &v1.Index{}
}
if index.SchemaVersion == 0 {
index.SchemaVersion = 2
}
if tag != "" {
if desc.Annotations == nil {
desc.Annotations = make(map[string]string)
}
desc.Annotations[v1.AnnotationRefName] = tag
// remove existing manifests with the same tag
var manifests []v1.Descriptor
for _, m := range index.Manifests {
if m.Annotations[v1.AnnotationRefName] != tag {
manifests = append(manifests, m)
}
}
index.Manifests = manifests
}
index.Manifests = append(index.Manifests, desc)
return nil
} | [
"func",
"PutDescToIndex",
"(",
"index",
"*",
"v1",
".",
"Index",
",",
"desc",
"v1",
".",
"Descriptor",
",",
"tag",
"string",
")",
"error",
"{",
"if",
"index",
"==",
"nil",
"{",
"index",
"=",
"&",
"v1",
".",
"Index",
"{",
"}",
"\n",
"}",
"\n",
"if... | // PutDescToIndex puts desc to index with tag.
// Existing manifests with the same tag will be removed from the index. | [
"PutDescToIndex",
"puts",
"desc",
"to",
"index",
"with",
"tag",
".",
"Existing",
"manifests",
"with",
"the",
"same",
"tag",
"will",
"be",
"removed",
"from",
"the",
"index",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/client/ociindex/ociindex.go#L20-L43 |
161,719 | moby/buildkit | frontend/dockerfile/instructions/parse.go | ParseCommand | func ParseCommand(node *parser.Node) (Command, error) {
s, err := ParseInstruction(node)
if err != nil {
return nil, err
}
if c, ok := s.(Command); ok {
return c, nil
}
return nil, errors.Errorf("%T is not a command type", s)
} | go | func ParseCommand(node *parser.Node) (Command, error) {
s, err := ParseInstruction(node)
if err != nil {
return nil, err
}
if c, ok := s.(Command); ok {
return c, nil
}
return nil, errors.Errorf("%T is not a command type", s)
} | [
"func",
"ParseCommand",
"(",
"node",
"*",
"parser",
".",
"Node",
")",
"(",
"Command",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"ParseInstruction",
"(",
"node",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
... | // ParseCommand converts an AST to a typed Command | [
"ParseCommand",
"converts",
"an",
"AST",
"to",
"a",
"typed",
"Command"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/instructions/parse.go#L100-L109 |
161,720 | moby/buildkit | frontend/dockerfile/instructions/parse.go | IsUnknownInstruction | func IsUnknownInstruction(err error) bool {
_, ok := err.(*UnknownInstruction)
if !ok {
var pe *parseError
if pe, ok = err.(*parseError); ok {
_, ok = pe.inner.(*UnknownInstruction)
}
}
return ok
} | go | func IsUnknownInstruction(err error) bool {
_, ok := err.(*UnknownInstruction)
if !ok {
var pe *parseError
if pe, ok = err.(*parseError); ok {
_, ok = pe.inner.(*UnknownInstruction)
}
}
return ok
} | [
"func",
"IsUnknownInstruction",
"(",
"err",
"error",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"UnknownInstruction",
")",
"\n",
"if",
"!",
"ok",
"{",
"var",
"pe",
"*",
"parseError",
"\n",
"if",
"pe",
",",
"ok",
"=",
"err",
".",
... | // IsUnknownInstruction checks if the error is an UnknownInstruction or a parseError containing an UnknownInstruction | [
"IsUnknownInstruction",
"checks",
"if",
"the",
"error",
"is",
"an",
"UnknownInstruction",
"or",
"a",
"parseError",
"containing",
"an",
"UnknownInstruction"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/instructions/parse.go#L122-L131 |
161,721 | moby/buildkit | frontend/dockerfile/instructions/parse.go | Parse | func Parse(ast *parser.Node) (stages []Stage, metaArgs []ArgCommand, err error) {
for _, n := range ast.Children {
cmd, err := ParseInstruction(n)
if err != nil {
return nil, nil, &parseError{inner: err, node: n}
}
if len(stages) == 0 {
// meta arg case
if a, isArg := cmd.(*ArgCommand); isArg {
metaArgs = append(metaArgs, *a)
continue
}
}
switch c := cmd.(type) {
case *Stage:
stages = append(stages, *c)
case Command:
stage, err := CurrentStage(stages)
if err != nil {
return nil, nil, err
}
stage.AddCommand(c)
default:
return nil, nil, errors.Errorf("%T is not a command type", cmd)
}
}
return stages, metaArgs, nil
} | go | func Parse(ast *parser.Node) (stages []Stage, metaArgs []ArgCommand, err error) {
for _, n := range ast.Children {
cmd, err := ParseInstruction(n)
if err != nil {
return nil, nil, &parseError{inner: err, node: n}
}
if len(stages) == 0 {
// meta arg case
if a, isArg := cmd.(*ArgCommand); isArg {
metaArgs = append(metaArgs, *a)
continue
}
}
switch c := cmd.(type) {
case *Stage:
stages = append(stages, *c)
case Command:
stage, err := CurrentStage(stages)
if err != nil {
return nil, nil, err
}
stage.AddCommand(c)
default:
return nil, nil, errors.Errorf("%T is not a command type", cmd)
}
}
return stages, metaArgs, nil
} | [
"func",
"Parse",
"(",
"ast",
"*",
"parser",
".",
"Node",
")",
"(",
"stages",
"[",
"]",
"Stage",
",",
"metaArgs",
"[",
"]",
"ArgCommand",
",",
"err",
"error",
")",
"{",
"for",
"_",
",",
"n",
":=",
"range",
"ast",
".",
"Children",
"{",
"cmd",
",",
... | // Parse a Dockerfile into a collection of buildable stages.
// metaArgs is a collection of ARG instructions that occur before the first FROM. | [
"Parse",
"a",
"Dockerfile",
"into",
"a",
"collection",
"of",
"buildable",
"stages",
".",
"metaArgs",
"is",
"a",
"collection",
"of",
"ARG",
"instructions",
"that",
"occur",
"before",
"the",
"first",
"FROM",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/instructions/parse.go#L144-L172 |
161,722 | moby/buildkit | session/session.go | NewSession | func NewSession(ctx context.Context, name, sharedKey string) (*Session, error) {
id := identity.NewID()
serverOpts := []grpc.ServerOption{}
if span := opentracing.SpanFromContext(ctx); span != nil {
tracer := span.Tracer()
serverOpts = []grpc.ServerOption{
grpc.StreamInterceptor(otgrpc.OpenTracingStreamServerInterceptor(span.Tracer(), traceFilter())),
grpc.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer, traceFilter())),
}
}
s := &Session{
id: id,
name: name,
sharedKey: sharedKey,
grpcServer: grpc.NewServer(serverOpts...),
}
grpc_health_v1.RegisterHealthServer(s.grpcServer, health.NewServer())
return s, nil
} | go | func NewSession(ctx context.Context, name, sharedKey string) (*Session, error) {
id := identity.NewID()
serverOpts := []grpc.ServerOption{}
if span := opentracing.SpanFromContext(ctx); span != nil {
tracer := span.Tracer()
serverOpts = []grpc.ServerOption{
grpc.StreamInterceptor(otgrpc.OpenTracingStreamServerInterceptor(span.Tracer(), traceFilter())),
grpc.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer, traceFilter())),
}
}
s := &Session{
id: id,
name: name,
sharedKey: sharedKey,
grpcServer: grpc.NewServer(serverOpts...),
}
grpc_health_v1.RegisterHealthServer(s.grpcServer, health.NewServer())
return s, nil
} | [
"func",
"NewSession",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
",",
"sharedKey",
"string",
")",
"(",
"*",
"Session",
",",
"error",
")",
"{",
"id",
":=",
"identity",
".",
"NewID",
"(",
")",
"\n\n",
"serverOpts",
":=",
"[",
"]",
"grpc",
".",... | // NewSession returns a new long running session | [
"NewSession",
"returns",
"a",
"new",
"long",
"running",
"session"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/session/session.go#L45-L67 |
161,723 | moby/buildkit | session/session.go | Run | func (s *Session) Run(ctx context.Context, dialer Dialer) error {
ctx, cancel := context.WithCancel(ctx)
s.cancelCtx = cancel
s.done = make(chan struct{})
defer cancel()
defer close(s.done)
meta := make(map[string][]string)
meta[headerSessionID] = []string{s.id}
meta[headerSessionName] = []string{s.name}
meta[headerSessionSharedKey] = []string{s.sharedKey}
for name, svc := range s.grpcServer.GetServiceInfo() {
for _, method := range svc.Methods {
meta[headerSessionMethod] = append(meta[headerSessionMethod], MethodURL(name, method.Name))
}
}
conn, err := dialer(ctx, "h2c", meta)
if err != nil {
return errors.Wrap(err, "failed to dial gRPC")
}
s.conn = conn
serve(ctx, s.grpcServer, conn)
return nil
} | go | func (s *Session) Run(ctx context.Context, dialer Dialer) error {
ctx, cancel := context.WithCancel(ctx)
s.cancelCtx = cancel
s.done = make(chan struct{})
defer cancel()
defer close(s.done)
meta := make(map[string][]string)
meta[headerSessionID] = []string{s.id}
meta[headerSessionName] = []string{s.name}
meta[headerSessionSharedKey] = []string{s.sharedKey}
for name, svc := range s.grpcServer.GetServiceInfo() {
for _, method := range svc.Methods {
meta[headerSessionMethod] = append(meta[headerSessionMethod], MethodURL(name, method.Name))
}
}
conn, err := dialer(ctx, "h2c", meta)
if err != nil {
return errors.Wrap(err, "failed to dial gRPC")
}
s.conn = conn
serve(ctx, s.grpcServer, conn)
return nil
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
",",
"dialer",
"Dialer",
")",
"error",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithCancel",
"(",
"ctx",
")",
"\n",
"s",
".",
"cancelCtx",
"=",
"cancel",
... | // Run activates the session | [
"Run",
"activates",
"the",
"session"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/session/session.go#L80-L105 |
161,724 | moby/buildkit | frontend/gateway/grpcclient/client.go | defaultCaps | func defaultCaps() []apicaps.PBCap {
return []apicaps.PBCap{
{ID: string(pb.CapSolveBase), Enabled: true},
{ID: string(pb.CapSolveInlineReturn), Enabled: true},
{ID: string(pb.CapResolveImage), Enabled: true},
{ID: string(pb.CapReadFile), Enabled: true},
}
} | go | func defaultCaps() []apicaps.PBCap {
return []apicaps.PBCap{
{ID: string(pb.CapSolveBase), Enabled: true},
{ID: string(pb.CapSolveInlineReturn), Enabled: true},
{ID: string(pb.CapResolveImage), Enabled: true},
{ID: string(pb.CapReadFile), Enabled: true},
}
} | [
"func",
"defaultCaps",
"(",
")",
"[",
"]",
"apicaps",
".",
"PBCap",
"{",
"return",
"[",
"]",
"apicaps",
".",
"PBCap",
"{",
"{",
"ID",
":",
"string",
"(",
"pb",
".",
"CapSolveBase",
")",
",",
"Enabled",
":",
"true",
"}",
",",
"{",
"ID",
":",
"stri... | // defaultCaps returns the capabilities that were implemented when capabilities
// support was added. This list is frozen and should never be changed. | [
"defaultCaps",
"returns",
"the",
"capabilities",
"that",
"were",
"implemented",
"when",
"capabilities",
"support",
"was",
"added",
".",
"This",
"list",
"is",
"frozen",
"and",
"should",
"never",
"be",
"changed",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/gateway/grpcclient/client.go#L175-L182 |
161,725 | moby/buildkit | frontend/gateway/grpcclient/client.go | defaultLLBCaps | func defaultLLBCaps() []apicaps.PBCap {
return []apicaps.PBCap{
{ID: string(opspb.CapSourceImage), Enabled: true},
{ID: string(opspb.CapSourceLocal), Enabled: true},
{ID: string(opspb.CapSourceLocalUnique), Enabled: true},
{ID: string(opspb.CapSourceLocalSessionID), Enabled: true},
{ID: string(opspb.CapSourceLocalIncludePatterns), Enabled: true},
{ID: string(opspb.CapSourceLocalFollowPaths), Enabled: true},
{ID: string(opspb.CapSourceLocalExcludePatterns), Enabled: true},
{ID: string(opspb.CapSourceLocalSharedKeyHint), Enabled: true},
{ID: string(opspb.CapSourceGit), Enabled: true},
{ID: string(opspb.CapSourceGitKeepDir), Enabled: true},
{ID: string(opspb.CapSourceGitFullURL), Enabled: true},
{ID: string(opspb.CapSourceHTTP), Enabled: true},
{ID: string(opspb.CapSourceHTTPChecksum), Enabled: true},
{ID: string(opspb.CapSourceHTTPPerm), Enabled: true},
{ID: string(opspb.CapSourceHTTPUIDGID), Enabled: true},
{ID: string(opspb.CapBuildOpLLBFileName), Enabled: true},
{ID: string(opspb.CapExecMetaBase), Enabled: true},
{ID: string(opspb.CapExecMetaProxy), Enabled: true},
{ID: string(opspb.CapExecMountBind), Enabled: true},
{ID: string(opspb.CapExecMountCache), Enabled: true},
{ID: string(opspb.CapExecMountCacheSharing), Enabled: true},
{ID: string(opspb.CapExecMountSelector), Enabled: true},
{ID: string(opspb.CapExecMountTmpfs), Enabled: true},
{ID: string(opspb.CapExecMountSecret), Enabled: true},
{ID: string(opspb.CapConstraints), Enabled: true},
{ID: string(opspb.CapPlatform), Enabled: true},
{ID: string(opspb.CapMetaIgnoreCache), Enabled: true},
{ID: string(opspb.CapMetaDescription), Enabled: true},
{ID: string(opspb.CapMetaExportCache), Enabled: true},
}
} | go | func defaultLLBCaps() []apicaps.PBCap {
return []apicaps.PBCap{
{ID: string(opspb.CapSourceImage), Enabled: true},
{ID: string(opspb.CapSourceLocal), Enabled: true},
{ID: string(opspb.CapSourceLocalUnique), Enabled: true},
{ID: string(opspb.CapSourceLocalSessionID), Enabled: true},
{ID: string(opspb.CapSourceLocalIncludePatterns), Enabled: true},
{ID: string(opspb.CapSourceLocalFollowPaths), Enabled: true},
{ID: string(opspb.CapSourceLocalExcludePatterns), Enabled: true},
{ID: string(opspb.CapSourceLocalSharedKeyHint), Enabled: true},
{ID: string(opspb.CapSourceGit), Enabled: true},
{ID: string(opspb.CapSourceGitKeepDir), Enabled: true},
{ID: string(opspb.CapSourceGitFullURL), Enabled: true},
{ID: string(opspb.CapSourceHTTP), Enabled: true},
{ID: string(opspb.CapSourceHTTPChecksum), Enabled: true},
{ID: string(opspb.CapSourceHTTPPerm), Enabled: true},
{ID: string(opspb.CapSourceHTTPUIDGID), Enabled: true},
{ID: string(opspb.CapBuildOpLLBFileName), Enabled: true},
{ID: string(opspb.CapExecMetaBase), Enabled: true},
{ID: string(opspb.CapExecMetaProxy), Enabled: true},
{ID: string(opspb.CapExecMountBind), Enabled: true},
{ID: string(opspb.CapExecMountCache), Enabled: true},
{ID: string(opspb.CapExecMountCacheSharing), Enabled: true},
{ID: string(opspb.CapExecMountSelector), Enabled: true},
{ID: string(opspb.CapExecMountTmpfs), Enabled: true},
{ID: string(opspb.CapExecMountSecret), Enabled: true},
{ID: string(opspb.CapConstraints), Enabled: true},
{ID: string(opspb.CapPlatform), Enabled: true},
{ID: string(opspb.CapMetaIgnoreCache), Enabled: true},
{ID: string(opspb.CapMetaDescription), Enabled: true},
{ID: string(opspb.CapMetaExportCache), Enabled: true},
}
} | [
"func",
"defaultLLBCaps",
"(",
")",
"[",
"]",
"apicaps",
".",
"PBCap",
"{",
"return",
"[",
"]",
"apicaps",
".",
"PBCap",
"{",
"{",
"ID",
":",
"string",
"(",
"opspb",
".",
"CapSourceImage",
")",
",",
"Enabled",
":",
"true",
"}",
",",
"{",
"ID",
":",... | // defaultLLBCaps returns the LLB capabilities that were implemented when capabilities
// support was added. This list is frozen and should never be changed. | [
"defaultLLBCaps",
"returns",
"the",
"LLB",
"capabilities",
"that",
"were",
"implemented",
"when",
"capabilities",
"support",
"was",
"added",
".",
"This",
"list",
"is",
"frozen",
"and",
"should",
"never",
"be",
"changed",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/gateway/grpcclient/client.go#L186-L218 |
161,726 | moby/buildkit | cache/contenthash/checksum.go | needsScan | func (cc *cacheContext) needsScan(root *iradix.Node, p string) (bool, error) {
var linksWalked int
return cc.needsScanFollow(root, p, &linksWalked)
} | go | func (cc *cacheContext) needsScan(root *iradix.Node, p string) (bool, error) {
var linksWalked int
return cc.needsScanFollow(root, p, &linksWalked)
} | [
"func",
"(",
"cc",
"*",
"cacheContext",
")",
"needsScan",
"(",
"root",
"*",
"iradix",
".",
"Node",
",",
"p",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"linksWalked",
"int",
"\n",
"return",
"cc",
".",
"needsScanFollow",
"(",
"root",
"... | // needsScan returns false if path is in the tree or a parent path is in tree
// and subpath is missing | [
"needsScan",
"returns",
"false",
"if",
"path",
"is",
"in",
"the",
"tree",
"or",
"a",
"parent",
"path",
"is",
"in",
"tree",
"and",
"subpath",
"is",
"missing"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/cache/contenthash/checksum.go#L672-L675 |
161,727 | moby/buildkit | client/llb/resolver.go | WithMetaResolver | func WithMetaResolver(mr ImageMetaResolver) ImageOption {
return imageOptionFunc(func(ii *ImageInfo) {
ii.metaResolver = mr
})
} | go | func WithMetaResolver(mr ImageMetaResolver) ImageOption {
return imageOptionFunc(func(ii *ImageInfo) {
ii.metaResolver = mr
})
} | [
"func",
"WithMetaResolver",
"(",
"mr",
"ImageMetaResolver",
")",
"ImageOption",
"{",
"return",
"imageOptionFunc",
"(",
"func",
"(",
"ii",
"*",
"ImageInfo",
")",
"{",
"ii",
".",
"metaResolver",
"=",
"mr",
"\n",
"}",
")",
"\n",
"}"
] | // WithMetaResolver adds a metadata resolver to an image | [
"WithMetaResolver",
"adds",
"a",
"metadata",
"resolver",
"to",
"an",
"image"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/client/llb/resolver.go#L11-L15 |
161,728 | moby/buildkit | source/http/httpsource.go | urlHash | func (hs *httpSourceHandler) urlHash() (digest.Digest, error) {
dt, err := json.Marshal(struct {
Filename string
Perm, UID, GID int
}{
Filename: getFileName(hs.src.URL, hs.src.Filename, nil),
Perm: hs.src.Perm,
UID: hs.src.UID,
GID: hs.src.GID,
})
if err != nil {
return "", err
}
return digest.FromBytes(dt), nil
} | go | func (hs *httpSourceHandler) urlHash() (digest.Digest, error) {
dt, err := json.Marshal(struct {
Filename string
Perm, UID, GID int
}{
Filename: getFileName(hs.src.URL, hs.src.Filename, nil),
Perm: hs.src.Perm,
UID: hs.src.UID,
GID: hs.src.GID,
})
if err != nil {
return "", err
}
return digest.FromBytes(dt), nil
} | [
"func",
"(",
"hs",
"*",
"httpSourceHandler",
")",
"urlHash",
"(",
")",
"(",
"digest",
".",
"Digest",
",",
"error",
")",
"{",
"dt",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"struct",
"{",
"Filename",
"string",
"\n",
"Perm",
",",
"UID",
",",
"G... | // urlHash is internal hash the etag is stored by that doesn't leak outside
// this package. | [
"urlHash",
"is",
"internal",
"hash",
"the",
"etag",
"is",
"stored",
"by",
"that",
"doesn",
"t",
"leak",
"outside",
"this",
"package",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/source/http/httpsource.go#L87-L101 |
161,729 | moby/buildkit | source/git/gitsource.go | Supported | func Supported() error {
if err := exec.Command("git", "version").Run(); err != nil {
return errors.Wrap(err, "failed to find git binary")
}
return nil
} | go | func Supported() error {
if err := exec.Command("git", "version").Run(); err != nil {
return errors.Wrap(err, "failed to find git binary")
}
return nil
} | [
"func",
"Supported",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
"... | // Supported returns nil if the system supports Git source | [
"Supported",
"returns",
"nil",
"if",
"the",
"system",
"supports",
"Git",
"source"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/source/git/gitsource.go#L42-L47 |
161,730 | moby/buildkit | util/binfmt_misc/detect.go | WarnIfUnsupported | func WarnIfUnsupported(pfs []string) {
def := defaultPlatform()
for _, p := range pfs {
if p != def {
if p == "linux/amd64" {
if err := amd64Supported(); err != nil {
printPlatfromWarning(p, err)
}
}
if p == "linux/arm64" {
if err := arm64Supported(); err != nil {
printPlatfromWarning(p, err)
}
}
if strings.HasPrefix(p, "linux/arm/v6") || strings.HasPrefix(p, "linux/arm/v7") {
if err := armSupported(); err != nil {
printPlatfromWarning(p, err)
}
}
}
}
} | go | func WarnIfUnsupported(pfs []string) {
def := defaultPlatform()
for _, p := range pfs {
if p != def {
if p == "linux/amd64" {
if err := amd64Supported(); err != nil {
printPlatfromWarning(p, err)
}
}
if p == "linux/arm64" {
if err := arm64Supported(); err != nil {
printPlatfromWarning(p, err)
}
}
if strings.HasPrefix(p, "linux/arm/v6") || strings.HasPrefix(p, "linux/arm/v7") {
if err := armSupported(); err != nil {
printPlatfromWarning(p, err)
}
}
}
}
} | [
"func",
"WarnIfUnsupported",
"(",
"pfs",
"[",
"]",
"string",
")",
"{",
"def",
":=",
"defaultPlatform",
"(",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"pfs",
"{",
"if",
"p",
"!=",
"def",
"{",
"if",
"p",
"==",
"\"",
"\"",
"{",
"if",
"err",
... | //WarnIfUnsupported validates the platforms and show warning message if there is,
//the end user could fix the issue based on those warning, and thus no need to drop
//the platform from the candidates. | [
"WarnIfUnsupported",
"validates",
"the",
"platforms",
"and",
"show",
"warning",
"message",
"if",
"there",
"is",
"the",
"end",
"user",
"could",
"fix",
"the",
"issue",
"based",
"on",
"those",
"warning",
"and",
"thus",
"no",
"need",
"to",
"drop",
"the",
"platfo... | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/binfmt_misc/detect.go#L36-L57 |
161,731 | moby/buildkit | util/network/network.go | Default | func Default() map[pb.NetMode]Provider {
return map[pb.NetMode]Provider{
// FIXME: still uses host if no provider configured
pb.NetMode_UNSET: NewHostProvider(),
pb.NetMode_HOST: NewHostProvider(),
pb.NetMode_NONE: NewNoneProvider(),
}
} | go | func Default() map[pb.NetMode]Provider {
return map[pb.NetMode]Provider{
// FIXME: still uses host if no provider configured
pb.NetMode_UNSET: NewHostProvider(),
pb.NetMode_HOST: NewHostProvider(),
pb.NetMode_NONE: NewNoneProvider(),
}
} | [
"func",
"Default",
"(",
")",
"map",
"[",
"pb",
".",
"NetMode",
"]",
"Provider",
"{",
"return",
"map",
"[",
"pb",
".",
"NetMode",
"]",
"Provider",
"{",
"// FIXME: still uses host if no provider configured",
"pb",
".",
"NetMode_UNSET",
":",
"NewHostProvider",
"(",... | // Default returns the default network provider set | [
"Default",
"returns",
"the",
"default",
"network",
"provider",
"set"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/network/network.go#L11-L18 |
161,732 | moby/buildkit | util/dockerexporter/dockerexporter.go | Export | func (de *DockerExporter) Export(ctx context.Context, store content.Provider, desc ocispec.Descriptor, writer io.Writer) error {
tw := tar.NewWriter(writer)
defer tw.Close()
dockerManifest, err := dockerManifestRecord(ctx, store, desc, de.Names)
if err != nil {
return err
}
records := []tarRecord{
ociLayoutFile(""),
ociIndexRecord(desc),
*dockerManifest,
}
algorithms := map[string]struct{}{}
exportHandler := func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
records = append(records, blobRecord(store, desc))
algorithms[desc.Digest.Algorithm().String()] = struct{}{}
return nil, nil
}
// Get all the children for a descriptor
childrenHandler := images.ChildrenHandler(store)
handlers := images.Handlers(
childrenHandler,
images.HandlerFunc(exportHandler),
)
// Walk sequentially since the number of fetchs is likely one and doing in
// parallel requires locking the export handler
if err := images.Walk(ctx, handlers, desc); err != nil {
return err
}
if len(algorithms) > 0 {
records = append(records, directoryRecord("blobs/", 0755))
for alg := range algorithms {
records = append(records, directoryRecord("blobs/"+alg+"/", 0755))
}
}
return writeTar(ctx, tw, records)
} | go | func (de *DockerExporter) Export(ctx context.Context, store content.Provider, desc ocispec.Descriptor, writer io.Writer) error {
tw := tar.NewWriter(writer)
defer tw.Close()
dockerManifest, err := dockerManifestRecord(ctx, store, desc, de.Names)
if err != nil {
return err
}
records := []tarRecord{
ociLayoutFile(""),
ociIndexRecord(desc),
*dockerManifest,
}
algorithms := map[string]struct{}{}
exportHandler := func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
records = append(records, blobRecord(store, desc))
algorithms[desc.Digest.Algorithm().String()] = struct{}{}
return nil, nil
}
// Get all the children for a descriptor
childrenHandler := images.ChildrenHandler(store)
handlers := images.Handlers(
childrenHandler,
images.HandlerFunc(exportHandler),
)
// Walk sequentially since the number of fetchs is likely one and doing in
// parallel requires locking the export handler
if err := images.Walk(ctx, handlers, desc); err != nil {
return err
}
if len(algorithms) > 0 {
records = append(records, directoryRecord("blobs/", 0755))
for alg := range algorithms {
records = append(records, directoryRecord("blobs/"+alg+"/", 0755))
}
}
return writeTar(ctx, tw, records)
} | [
"func",
"(",
"de",
"*",
"DockerExporter",
")",
"Export",
"(",
"ctx",
"context",
".",
"Context",
",",
"store",
"content",
".",
"Provider",
",",
"desc",
"ocispec",
".",
"Descriptor",
",",
"writer",
"io",
".",
"Writer",
")",
"error",
"{",
"tw",
":=",
"tar... | // Export exports tarball into writer. | [
"Export",
"exports",
"tarball",
"into",
"writer",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/dockerexporter/dockerexporter.go#L29-L73 |
161,733 | moby/buildkit | cmd/buildctl/common/common.go | ResolveClient | func ResolveClient(c *cli.Context) (*client.Client, error) {
serverName := c.GlobalString("tlsservername")
if serverName == "" {
// guess servername as hostname of target address
uri, err := url.Parse(c.GlobalString("addr"))
if err != nil {
return nil, err
}
serverName = uri.Hostname()
}
caCert := c.GlobalString("tlscacert")
cert := c.GlobalString("tlscert")
key := c.GlobalString("tlskey")
opts := []client.ClientOpt{client.WithFailFast()}
ctx := CommandContext(c)
if span := opentracing.SpanFromContext(ctx); span != nil {
opts = append(opts, client.WithTracer(span.Tracer()))
}
if caCert != "" || cert != "" || key != "" {
opts = append(opts, client.WithCredentials(serverName, caCert, cert, key))
}
timeout := time.Duration(c.GlobalInt("timeout"))
ctx, cancel := context.WithTimeout(ctx, timeout*time.Second)
defer cancel()
return client.New(ctx, c.GlobalString("addr"), opts...)
} | go | func ResolveClient(c *cli.Context) (*client.Client, error) {
serverName := c.GlobalString("tlsservername")
if serverName == "" {
// guess servername as hostname of target address
uri, err := url.Parse(c.GlobalString("addr"))
if err != nil {
return nil, err
}
serverName = uri.Hostname()
}
caCert := c.GlobalString("tlscacert")
cert := c.GlobalString("tlscert")
key := c.GlobalString("tlskey")
opts := []client.ClientOpt{client.WithFailFast()}
ctx := CommandContext(c)
if span := opentracing.SpanFromContext(ctx); span != nil {
opts = append(opts, client.WithTracer(span.Tracer()))
}
if caCert != "" || cert != "" || key != "" {
opts = append(opts, client.WithCredentials(serverName, caCert, cert, key))
}
timeout := time.Duration(c.GlobalInt("timeout"))
ctx, cancel := context.WithTimeout(ctx, timeout*time.Second)
defer cancel()
return client.New(ctx, c.GlobalString("addr"), opts...)
} | [
"func",
"ResolveClient",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"(",
"*",
"client",
".",
"Client",
",",
"error",
")",
"{",
"serverName",
":=",
"c",
".",
"GlobalString",
"(",
"\"",
"\"",
")",
"\n",
"if",
"serverName",
"==",
"\"",
"\"",
"{",
"// ... | // ResolveClient resolves a client from CLI args | [
"ResolveClient",
"resolves",
"a",
"client",
"from",
"CLI",
"args"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/cmd/buildctl/common/common.go#L14-L45 |
161,734 | moby/buildkit | util/progress/progress.go | FromContext | func FromContext(ctx context.Context, opts ...WriterOption) (Writer, bool, context.Context) {
v := ctx.Value(contextKey)
pw, ok := v.(*progressWriter)
if !ok {
if pw, ok := v.(*MultiWriter); ok {
return pw, true, ctx
}
return &noOpWriter{}, false, ctx
}
pw = newWriter(pw)
for _, o := range opts {
o(pw)
}
ctx = context.WithValue(ctx, contextKey, pw)
return pw, true, ctx
} | go | func FromContext(ctx context.Context, opts ...WriterOption) (Writer, bool, context.Context) {
v := ctx.Value(contextKey)
pw, ok := v.(*progressWriter)
if !ok {
if pw, ok := v.(*MultiWriter); ok {
return pw, true, ctx
}
return &noOpWriter{}, false, ctx
}
pw = newWriter(pw)
for _, o := range opts {
o(pw)
}
ctx = context.WithValue(ctx, contextKey, pw)
return pw, true, ctx
} | [
"func",
"FromContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"...",
"WriterOption",
")",
"(",
"Writer",
",",
"bool",
",",
"context",
".",
"Context",
")",
"{",
"v",
":=",
"ctx",
".",
"Value",
"(",
"contextKey",
")",
"\n",
"pw",
",",
"ok"... | // FromContext returns a progress writer from a context. | [
"FromContext",
"returns",
"a",
"progress",
"writer",
"from",
"a",
"context",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/progress/progress.go#L22-L37 |
161,735 | moby/buildkit | util/progress/progress.go | NewContext | func NewContext(ctx context.Context) (Reader, context.Context, func()) {
pr, pw, cancel := pipe()
ctx = WithProgress(ctx, pw)
return pr, ctx, cancel
} | go | func NewContext(ctx context.Context) (Reader, context.Context, func()) {
pr, pw, cancel := pipe()
ctx = WithProgress(ctx, pw)
return pr, ctx, cancel
} | [
"func",
"NewContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"Reader",
",",
"context",
".",
"Context",
",",
"func",
"(",
")",
")",
"{",
"pr",
",",
"pw",
",",
"cancel",
":=",
"pipe",
"(",
")",
"\n",
"ctx",
"=",
"WithProgress",
"(",
"ctx",
... | // NewContext returns a new context and a progress reader that captures all
// progress items writtern to this context. Last returned parameter is a closer
// function to signal that no new writes will happen to this context. | [
"NewContext",
"returns",
"a",
"new",
"context",
"and",
"a",
"progress",
"reader",
"that",
"captures",
"all",
"progress",
"items",
"writtern",
"to",
"this",
"context",
".",
"Last",
"returned",
"parameter",
"is",
"a",
"closer",
"function",
"to",
"signal",
"that"... | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/progress/progress.go#L44-L48 |
161,736 | moby/buildkit | client/llb/state.go | WithExportCache | func WithExportCache() ConstraintsOpt {
return constraintsOptFunc(func(c *Constraints) {
c.Metadata.ExportCache = &pb.ExportCache{Value: true}
})
} | go | func WithExportCache() ConstraintsOpt {
return constraintsOptFunc(func(c *Constraints) {
c.Metadata.ExportCache = &pb.ExportCache{Value: true}
})
} | [
"func",
"WithExportCache",
"(",
")",
"ConstraintsOpt",
"{",
"return",
"constraintsOptFunc",
"(",
"func",
"(",
"c",
"*",
"Constraints",
")",
"{",
"c",
".",
"Metadata",
".",
"ExportCache",
"=",
"&",
"pb",
".",
"ExportCache",
"{",
"Value",
":",
"true",
"}",
... | // WithExportCache forces results for this vertex to be exported with the cache | [
"WithExportCache",
"forces",
"results",
"for",
"this",
"vertex",
"to",
"be",
"exported",
"with",
"the",
"cache"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/client/llb/state.go#L438-L442 |
161,737 | moby/buildkit | client/llb/state.go | WithoutExportCache | func WithoutExportCache() ConstraintsOpt {
return constraintsOptFunc(func(c *Constraints) {
// ExportCache with value false means to disable exporting
c.Metadata.ExportCache = &pb.ExportCache{Value: false}
})
} | go | func WithoutExportCache() ConstraintsOpt {
return constraintsOptFunc(func(c *Constraints) {
// ExportCache with value false means to disable exporting
c.Metadata.ExportCache = &pb.ExportCache{Value: false}
})
} | [
"func",
"WithoutExportCache",
"(",
")",
"ConstraintsOpt",
"{",
"return",
"constraintsOptFunc",
"(",
"func",
"(",
"c",
"*",
"Constraints",
")",
"{",
"// ExportCache with value false means to disable exporting",
"c",
".",
"Metadata",
".",
"ExportCache",
"=",
"&",
"pb",
... | // WithoutExportCache sets results for this vertex to be not exported with
// the cache | [
"WithoutExportCache",
"sets",
"results",
"for",
"this",
"vertex",
"to",
"be",
"not",
"exported",
"with",
"the",
"cache"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/client/llb/state.go#L446-L451 |
161,738 | moby/buildkit | client/llb/state.go | WithCaps | func WithCaps(caps apicaps.CapSet) ConstraintsOpt {
return constraintsOptFunc(func(c *Constraints) {
c.Caps = &caps
})
} | go | func WithCaps(caps apicaps.CapSet) ConstraintsOpt {
return constraintsOptFunc(func(c *Constraints) {
c.Caps = &caps
})
} | [
"func",
"WithCaps",
"(",
"caps",
"apicaps",
".",
"CapSet",
")",
"ConstraintsOpt",
"{",
"return",
"constraintsOptFunc",
"(",
"func",
"(",
"c",
"*",
"Constraints",
")",
"{",
"c",
".",
"Caps",
"=",
"&",
"caps",
"\n",
"}",
")",
"\n",
"}"
] | // WithCaps exposes supported LLB caps to the marshaler | [
"WithCaps",
"exposes",
"supported",
"LLB",
"caps",
"to",
"the",
"marshaler"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/client/llb/state.go#L463-L467 |
161,739 | moby/buildkit | examples/buildkit1/buildkit.go | goFromGit | func goFromGit(repo, tag string) llb.StateOption {
src := llb.Image("docker.io/library/alpine:latest").
Run(llb.Shlex("apk add --no-cache git")).
Run(llb.Shlexf("git clone https://%[1]s.git /go/src/%[1]s", repo)).
Dirf("/go/src/%s", repo).
Run(llb.Shlexf("git checkout -q %s", tag)).Root()
return func(s llb.State) llb.State {
return s.With(copyFrom(src, "/go", "/")).Reset(s).Dir(src.GetDir())
}
} | go | func goFromGit(repo, tag string) llb.StateOption {
src := llb.Image("docker.io/library/alpine:latest").
Run(llb.Shlex("apk add --no-cache git")).
Run(llb.Shlexf("git clone https://%[1]s.git /go/src/%[1]s", repo)).
Dirf("/go/src/%s", repo).
Run(llb.Shlexf("git checkout -q %s", tag)).Root()
return func(s llb.State) llb.State {
return s.With(copyFrom(src, "/go", "/")).Reset(s).Dir(src.GetDir())
}
} | [
"func",
"goFromGit",
"(",
"repo",
",",
"tag",
"string",
")",
"llb",
".",
"StateOption",
"{",
"src",
":=",
"llb",
".",
"Image",
"(",
"\"",
"\"",
")",
".",
"Run",
"(",
"llb",
".",
"Shlex",
"(",
"\"",
"\"",
")",
")",
".",
"Run",
"(",
"llb",
".",
... | // goFromGit is a helper for cloning a git repo, checking out a tag and copying
// source directory into | [
"goFromGit",
"is",
"a",
"helper",
"for",
"cloning",
"a",
"git",
"repo",
"checking",
"out",
"a",
"tag",
"and",
"copying",
"source",
"directory",
"into"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/examples/buildkit1/buildkit.go#L84-L93 |
161,740 | moby/buildkit | session/filesync/filesync.go | NewFSSyncProvider | func NewFSSyncProvider(dirs []SyncedDir) session.Attachable {
p := &fsSyncProvider{
dirs: map[string]SyncedDir{},
}
for _, d := range dirs {
p.dirs[d.Name] = d
}
return p
} | go | func NewFSSyncProvider(dirs []SyncedDir) session.Attachable {
p := &fsSyncProvider{
dirs: map[string]SyncedDir{},
}
for _, d := range dirs {
p.dirs[d.Name] = d
}
return p
} | [
"func",
"NewFSSyncProvider",
"(",
"dirs",
"[",
"]",
"SyncedDir",
")",
"session",
".",
"Attachable",
"{",
"p",
":=",
"&",
"fsSyncProvider",
"{",
"dirs",
":",
"map",
"[",
"string",
"]",
"SyncedDir",
"{",
"}",
",",
"}",
"\n",
"for",
"_",
",",
"d",
":=",... | // NewFSSyncProvider creates a new provider for sending files from client | [
"NewFSSyncProvider",
"creates",
"a",
"new",
"provider",
"for",
"sending",
"files",
"from",
"client"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/session/filesync/filesync.go#L42-L50 |
161,741 | moby/buildkit | session/filesync/filesync.go | FSSync | func FSSync(ctx context.Context, c session.Caller, opt FSSendRequestOpt) error {
var pr *protocol
for _, p := range supportedProtocols {
if isProtoSupported(p.name) && c.Supports(session.MethodURL(_FileSync_serviceDesc.ServiceName, p.name)) {
pr = &p
break
}
}
if pr == nil {
return errors.New("no local sources enabled")
}
opts := make(map[string][]string)
if opt.OverrideExcludes {
opts[keyOverrideExcludes] = []string{"true"}
}
if opt.IncludePatterns != nil {
opts[keyIncludePatterns] = opt.IncludePatterns
}
if opt.ExcludePatterns != nil {
opts[keyExcludePatterns] = opt.ExcludePatterns
}
if opt.FollowPaths != nil {
opts[keyFollowPaths] = opt.FollowPaths
}
opts[keyDirName] = []string{opt.Name}
ctx, cancel := context.WithCancel(ctx)
defer cancel()
client := NewFileSyncClient(c.Conn())
var stream grpc.ClientStream
ctx = metadata.NewOutgoingContext(ctx, opts)
switch pr.name {
case "tarstream":
cc, err := client.TarStream(ctx)
if err != nil {
return err
}
stream = cc
case "diffcopy":
cc, err := client.DiffCopy(ctx)
if err != nil {
return err
}
stream = cc
default:
panic(fmt.Sprintf("invalid protocol: %q", pr.name))
}
return pr.recvFn(stream, opt.DestDir, opt.CacheUpdater, opt.ProgressCb, opt.Filter)
} | go | func FSSync(ctx context.Context, c session.Caller, opt FSSendRequestOpt) error {
var pr *protocol
for _, p := range supportedProtocols {
if isProtoSupported(p.name) && c.Supports(session.MethodURL(_FileSync_serviceDesc.ServiceName, p.name)) {
pr = &p
break
}
}
if pr == nil {
return errors.New("no local sources enabled")
}
opts := make(map[string][]string)
if opt.OverrideExcludes {
opts[keyOverrideExcludes] = []string{"true"}
}
if opt.IncludePatterns != nil {
opts[keyIncludePatterns] = opt.IncludePatterns
}
if opt.ExcludePatterns != nil {
opts[keyExcludePatterns] = opt.ExcludePatterns
}
if opt.FollowPaths != nil {
opts[keyFollowPaths] = opt.FollowPaths
}
opts[keyDirName] = []string{opt.Name}
ctx, cancel := context.WithCancel(ctx)
defer cancel()
client := NewFileSyncClient(c.Conn())
var stream grpc.ClientStream
ctx = metadata.NewOutgoingContext(ctx, opts)
switch pr.name {
case "tarstream":
cc, err := client.TarStream(ctx)
if err != nil {
return err
}
stream = cc
case "diffcopy":
cc, err := client.DiffCopy(ctx)
if err != nil {
return err
}
stream = cc
default:
panic(fmt.Sprintf("invalid protocol: %q", pr.name))
}
return pr.recvFn(stream, opt.DestDir, opt.CacheUpdater, opt.ProgressCb, opt.Filter)
} | [
"func",
"FSSync",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"session",
".",
"Caller",
",",
"opt",
"FSSendRequestOpt",
")",
"error",
"{",
"var",
"pr",
"*",
"protocol",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"supportedProtocols",
"{",
"if",
"i... | // FSSync initializes a transfer of files | [
"FSSync",
"initializes",
"a",
"transfer",
"of",
"files"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/session/filesync/filesync.go#L172-L230 |
161,742 | moby/buildkit | session/filesync/filesync.go | NewFSSyncTargetDir | func NewFSSyncTargetDir(outdir string) session.Attachable {
p := &fsSyncTarget{
outdir: outdir,
}
return p
} | go | func NewFSSyncTargetDir(outdir string) session.Attachable {
p := &fsSyncTarget{
outdir: outdir,
}
return p
} | [
"func",
"NewFSSyncTargetDir",
"(",
"outdir",
"string",
")",
"session",
".",
"Attachable",
"{",
"p",
":=",
"&",
"fsSyncTarget",
"{",
"outdir",
":",
"outdir",
",",
"}",
"\n",
"return",
"p",
"\n",
"}"
] | // NewFSSyncTargetDir allows writing into a directory | [
"NewFSSyncTargetDir",
"allows",
"writing",
"into",
"a",
"directory"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/session/filesync/filesync.go#L233-L238 |
161,743 | moby/buildkit | session/filesync/filesync.go | NewFSSyncTarget | func NewFSSyncTarget(w io.WriteCloser) session.Attachable {
p := &fsSyncTarget{
outfile: w,
}
return p
} | go | func NewFSSyncTarget(w io.WriteCloser) session.Attachable {
p := &fsSyncTarget{
outfile: w,
}
return p
} | [
"func",
"NewFSSyncTarget",
"(",
"w",
"io",
".",
"WriteCloser",
")",
"session",
".",
"Attachable",
"{",
"p",
":=",
"&",
"fsSyncTarget",
"{",
"outfile",
":",
"w",
",",
"}",
"\n",
"return",
"p",
"\n",
"}"
] | // NewFSSyncTarget allows writing into an io.WriteCloser | [
"NewFSSyncTarget",
"allows",
"writing",
"into",
"an",
"io",
".",
"WriteCloser"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/session/filesync/filesync.go#L241-L246 |
161,744 | moby/buildkit | solver/index.go | enforceLinked | func (er *edgeIndex) enforceLinked(id string, k *CacheKey) {
main, ok := er.items[id]
if !ok {
main = &indexItem{
links: map[CacheInfoLink]map[string]struct{}{},
deps: map[string]struct{}{},
}
er.items[id] = main
}
deps := k.Deps()
for i, dd := range deps {
for _, d := range dd {
ck := d.CacheKey.CacheKey
er.enforceIndexID(ck)
ll := CacheInfoLink{Input: Index(i), Digest: k.Digest(), Output: k.Output(), Selector: d.Selector}
for _, ckID := range ck.indexIDs {
if item, ok := er.items[ckID]; ok {
links, ok := item.links[ll]
if !ok {
links = map[string]struct{}{}
item.links[ll] = links
}
links[id] = struct{}{}
main.deps[ckID] = struct{}{}
}
}
}
}
} | go | func (er *edgeIndex) enforceLinked(id string, k *CacheKey) {
main, ok := er.items[id]
if !ok {
main = &indexItem{
links: map[CacheInfoLink]map[string]struct{}{},
deps: map[string]struct{}{},
}
er.items[id] = main
}
deps := k.Deps()
for i, dd := range deps {
for _, d := range dd {
ck := d.CacheKey.CacheKey
er.enforceIndexID(ck)
ll := CacheInfoLink{Input: Index(i), Digest: k.Digest(), Output: k.Output(), Selector: d.Selector}
for _, ckID := range ck.indexIDs {
if item, ok := er.items[ckID]; ok {
links, ok := item.links[ll]
if !ok {
links = map[string]struct{}{}
item.links[ll] = links
}
links[id] = struct{}{}
main.deps[ckID] = struct{}{}
}
}
}
}
} | [
"func",
"(",
"er",
"*",
"edgeIndex",
")",
"enforceLinked",
"(",
"id",
"string",
",",
"k",
"*",
"CacheKey",
")",
"{",
"main",
",",
"ok",
":=",
"er",
".",
"items",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",
"{",
"main",
"=",
"&",
"indexItem",
"{",
"l... | // enforceLinked adds links from current ID to all dep keys | [
"enforceLinked",
"adds",
"links",
"from",
"current",
"ID",
"to",
"all",
"dep",
"keys"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/index.go#L124-L154 |
161,745 | moby/buildkit | client/connhelper/connhelper.go | GetConnectionHelper | func GetConnectionHelper(daemonURL string) (*ConnectionHelper, error) {
u, err := url.Parse(daemonURL)
if err != nil {
return nil, err
}
fn, ok := helpers[u.Scheme]
if !ok {
return nil, nil
}
return fn(u)
} | go | func GetConnectionHelper(daemonURL string) (*ConnectionHelper, error) {
u, err := url.Parse(daemonURL)
if err != nil {
return nil, err
}
fn, ok := helpers[u.Scheme]
if !ok {
return nil, nil
}
return fn(u)
} | [
"func",
"GetConnectionHelper",
"(",
"daemonURL",
"string",
")",
"(",
"*",
"ConnectionHelper",
",",
"error",
")",
"{",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"daemonURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
... | // GetConnectionHelper returns BuildKit-specific connection helper for the given URL.
// GetConnectionHelper returns nil without error when no helper is registered for the scheme. | [
"GetConnectionHelper",
"returns",
"BuildKit",
"-",
"specific",
"connection",
"helper",
"for",
"the",
"given",
"URL",
".",
"GetConnectionHelper",
"returns",
"nil",
"without",
"error",
"when",
"no",
"helper",
"is",
"registered",
"for",
"the",
"scheme",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/client/connhelper/connhelper.go#L20-L32 |
161,746 | moby/buildkit | client/connhelper/connhelper.go | Register | func Register(scheme string, fn func(*url.URL) (*ConnectionHelper, error)) {
helpers[scheme] = fn
} | go | func Register(scheme string, fn func(*url.URL) (*ConnectionHelper, error)) {
helpers[scheme] = fn
} | [
"func",
"Register",
"(",
"scheme",
"string",
",",
"fn",
"func",
"(",
"*",
"url",
".",
"URL",
")",
"(",
"*",
"ConnectionHelper",
",",
"error",
")",
")",
"{",
"helpers",
"[",
"scheme",
"]",
"=",
"fn",
"\n",
"}"
] | // Register registers new connectionhelper for scheme | [
"Register",
"registers",
"new",
"connectionhelper",
"for",
"scheme"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/client/connhelper/connhelper.go#L35-L37 |
161,747 | moby/buildkit | solver/cachekey.go | NewCacheKey | func NewCacheKey(dgst digest.Digest, output Index) *CacheKey {
return &CacheKey{
ID: rootKey(dgst, output).String(),
digest: dgst,
output: output,
ids: map[*cacheManager]string{},
}
} | go | func NewCacheKey(dgst digest.Digest, output Index) *CacheKey {
return &CacheKey{
ID: rootKey(dgst, output).String(),
digest: dgst,
output: output,
ids: map[*cacheManager]string{},
}
} | [
"func",
"NewCacheKey",
"(",
"dgst",
"digest",
".",
"Digest",
",",
"output",
"Index",
")",
"*",
"CacheKey",
"{",
"return",
"&",
"CacheKey",
"{",
"ID",
":",
"rootKey",
"(",
"dgst",
",",
"output",
")",
".",
"String",
"(",
")",
",",
"digest",
":",
"dgst"... | // NewCacheKey creates a new cache key for a specific output index | [
"NewCacheKey",
"creates",
"a",
"new",
"cache",
"key",
"for",
"a",
"specific",
"output",
"index"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/cachekey.go#L10-L17 |
161,748 | moby/buildkit | frontend/dockerfile/shell/equal_env_windows.go | EqualEnvKeys | func EqualEnvKeys(from, to string) bool {
return strings.ToUpper(from) == strings.ToUpper(to)
} | go | func EqualEnvKeys(from, to string) bool {
return strings.ToUpper(from) == strings.ToUpper(to)
} | [
"func",
"EqualEnvKeys",
"(",
"from",
",",
"to",
"string",
")",
"bool",
"{",
"return",
"strings",
".",
"ToUpper",
"(",
"from",
")",
"==",
"strings",
".",
"ToUpper",
"(",
"to",
")",
"\n",
"}"
] | // EqualEnvKeys compare two strings and returns true if they are equal.
// On Unix this comparison is case sensitive.
// On Windows this comparison is case insensitive. | [
"EqualEnvKeys",
"compare",
"two",
"strings",
"and",
"returns",
"true",
"if",
"they",
"are",
"equal",
".",
"On",
"Unix",
"this",
"comparison",
"is",
"case",
"sensitive",
".",
"On",
"Windows",
"this",
"comparison",
"is",
"case",
"insensitive",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/shell/equal_env_windows.go#L8-L10 |
161,749 | moby/buildkit | util/tracing/tracing.go | StartSpan | func StartSpan(ctx context.Context, operationName string, opts ...opentracing.StartSpanOption) (opentracing.Span, context.Context) {
parent := opentracing.SpanFromContext(ctx)
tracer := opentracing.Tracer(&opentracing.NoopTracer{})
if parent != nil {
tracer = parent.Tracer()
opts = append(opts, opentracing.ChildOf(parent.Context()))
}
span := tracer.StartSpan(operationName, opts...)
if parent != nil {
return span, opentracing.ContextWithSpan(ctx, span)
}
return span, ctx
} | go | func StartSpan(ctx context.Context, operationName string, opts ...opentracing.StartSpanOption) (opentracing.Span, context.Context) {
parent := opentracing.SpanFromContext(ctx)
tracer := opentracing.Tracer(&opentracing.NoopTracer{})
if parent != nil {
tracer = parent.Tracer()
opts = append(opts, opentracing.ChildOf(parent.Context()))
}
span := tracer.StartSpan(operationName, opts...)
if parent != nil {
return span, opentracing.ContextWithSpan(ctx, span)
}
return span, ctx
} | [
"func",
"StartSpan",
"(",
"ctx",
"context",
".",
"Context",
",",
"operationName",
"string",
",",
"opts",
"...",
"opentracing",
".",
"StartSpanOption",
")",
"(",
"opentracing",
".",
"Span",
",",
"context",
".",
"Context",
")",
"{",
"parent",
":=",
"opentracin... | // StartSpan starts a new span as a child of the span in context.
// If there is no span in context then this is a no-op.
// The difference from opentracing.StartSpanFromContext is that this method
// does not depend on global tracer. | [
"StartSpan",
"starts",
"a",
"new",
"span",
"as",
"a",
"child",
"of",
"the",
"span",
"in",
"context",
".",
"If",
"there",
"is",
"no",
"span",
"in",
"context",
"then",
"this",
"is",
"a",
"no",
"-",
"op",
".",
"The",
"difference",
"from",
"opentracing",
... | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/tracing/tracing.go#L19-L31 |
161,750 | moby/buildkit | util/tracing/tracing.go | FinishWithError | func FinishWithError(span opentracing.Span, err error) {
if err != nil {
fields := []log.Field{
log.String("event", "error"),
log.String("message", err.Error()),
}
if _, ok := err.(interface {
Cause() error
}); ok {
fields = append(fields, log.String("stack", fmt.Sprintf("%+v", err)))
}
span.LogFields(fields...)
ext.Error.Set(span, true)
}
span.Finish()
} | go | func FinishWithError(span opentracing.Span, err error) {
if err != nil {
fields := []log.Field{
log.String("event", "error"),
log.String("message", err.Error()),
}
if _, ok := err.(interface {
Cause() error
}); ok {
fields = append(fields, log.String("stack", fmt.Sprintf("%+v", err)))
}
span.LogFields(fields...)
ext.Error.Set(span, true)
}
span.Finish()
} | [
"func",
"FinishWithError",
"(",
"span",
"opentracing",
".",
"Span",
",",
"err",
"error",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"fields",
":=",
"[",
"]",
"log",
".",
"Field",
"{",
"log",
".",
"String",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
","... | // FinishWithError finalizes the span and sets the error if one is passed | [
"FinishWithError",
"finalizes",
"the",
"span",
"and",
"sets",
"the",
"error",
"if",
"one",
"is",
"passed"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/tracing/tracing.go#L34-L49 |
161,751 | moby/buildkit | executor/oci/user.go | ParseUIDGID | func ParseUIDGID(str string) (uid uint32, gid uint32, err error) {
if str == "" {
return 0, 0, nil
}
parts := strings.SplitN(str, ":", 2)
if len(parts) == 1 {
return 0, 0, errors.New("groups ID is not provided")
}
if uid, err = parseUID(parts[0]); err != nil {
return 0, 0, err
}
if gid, err = parseUID(parts[1]); err != nil {
return 0, 0, err
}
return
} | go | func ParseUIDGID(str string) (uid uint32, gid uint32, err error) {
if str == "" {
return 0, 0, nil
}
parts := strings.SplitN(str, ":", 2)
if len(parts) == 1 {
return 0, 0, errors.New("groups ID is not provided")
}
if uid, err = parseUID(parts[0]); err != nil {
return 0, 0, err
}
if gid, err = parseUID(parts[1]); err != nil {
return 0, 0, err
}
return
} | [
"func",
"ParseUIDGID",
"(",
"str",
"string",
")",
"(",
"uid",
"uint32",
",",
"gid",
"uint32",
",",
"err",
"error",
")",
"{",
"if",
"str",
"==",
"\"",
"\"",
"{",
"return",
"0",
",",
"0",
",",
"nil",
"\n",
"}",
"\n",
"parts",
":=",
"strings",
".",
... | // ParseUIDGID takes the fast path to parse UID and GID if and only if they are both provided | [
"ParseUIDGID",
"takes",
"the",
"fast",
"path",
"to",
"parse",
"UID",
"and",
"GID",
"if",
"and",
"only",
"if",
"they",
"are",
"both",
"provided"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/executor/oci/user.go#L52-L67 |
161,752 | moby/buildkit | cache/remotecache/v1/cachestorage.go | remoteID | func remoteID(r *solver.Remote) string {
dgstr := digest.Canonical.Digester()
for _, desc := range r.Descriptors {
dgstr.Hash().Write([]byte(desc.Digest))
}
return dgstr.Digest().String()
} | go | func remoteID(r *solver.Remote) string {
dgstr := digest.Canonical.Digester()
for _, desc := range r.Descriptors {
dgstr.Hash().Write([]byte(desc.Digest))
}
return dgstr.Digest().String()
} | [
"func",
"remoteID",
"(",
"r",
"*",
"solver",
".",
"Remote",
")",
"string",
"{",
"dgstr",
":=",
"digest",
".",
"Canonical",
".",
"Digester",
"(",
")",
"\n",
"for",
"_",
",",
"desc",
":=",
"range",
"r",
".",
"Descriptors",
"{",
"dgstr",
".",
"Hash",
... | // unique ID per remote. this ID is not stable. | [
"unique",
"ID",
"per",
"remote",
".",
"this",
"ID",
"is",
"not",
"stable",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/cache/remotecache/v1/cachestorage.go#L290-L296 |
161,753 | moby/buildkit | session/grpchijack/hijack.go | Hijack | func Hijack(stream controlapi.Control_SessionServer) (net.Conn, <-chan struct{}, map[string][]string) {
md, _ := metadata.FromIncomingContext(stream.Context())
c, closeCh := streamToConn(stream)
return c, closeCh, md
} | go | func Hijack(stream controlapi.Control_SessionServer) (net.Conn, <-chan struct{}, map[string][]string) {
md, _ := metadata.FromIncomingContext(stream.Context())
c, closeCh := streamToConn(stream)
return c, closeCh, md
} | [
"func",
"Hijack",
"(",
"stream",
"controlapi",
".",
"Control_SessionServer",
")",
"(",
"net",
".",
"Conn",
",",
"<-",
"chan",
"struct",
"{",
"}",
",",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"{",
"md",
",",
"_",
":=",
"metadata",
".",
"... | // Hijack hijacks session to a connection. | [
"Hijack",
"hijacks",
"session",
"to",
"a",
"connection",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/session/grpchijack/hijack.go#L11-L15 |
161,754 | moby/buildkit | solver/cachemanager.go | NewCacheManager | func NewCacheManager(id string, storage CacheKeyStorage, results CacheResultStorage) CacheManager {
cm := &cacheManager{
id: id,
backend: storage,
results: results,
}
if err := cm.ReleaseUnreferenced(); err != nil {
logrus.Errorf("failed to release unreferenced cache metadata: %+v", err)
}
return cm
} | go | func NewCacheManager(id string, storage CacheKeyStorage, results CacheResultStorage) CacheManager {
cm := &cacheManager{
id: id,
backend: storage,
results: results,
}
if err := cm.ReleaseUnreferenced(); err != nil {
logrus.Errorf("failed to release unreferenced cache metadata: %+v", err)
}
return cm
} | [
"func",
"NewCacheManager",
"(",
"id",
"string",
",",
"storage",
"CacheKeyStorage",
",",
"results",
"CacheResultStorage",
")",
"CacheManager",
"{",
"cm",
":=",
"&",
"cacheManager",
"{",
"id",
":",
"id",
",",
"backend",
":",
"storage",
",",
"results",
":",
"re... | // NewCacheManager creates a new cache manager with specific storage backend | [
"NewCacheManager",
"creates",
"a",
"new",
"cache",
"manager",
"with",
"specific",
"storage",
"backend"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/cachemanager.go#L21-L33 |
161,755 | moby/buildkit | util/apicaps/caps.go | Init | func (l *CapList) Init(cc ...Cap) {
if l.m == nil {
l.m = make(map[CapID]Cap, len(cc))
}
for _, c := range cc {
l.m[c.ID] = c
}
} | go | func (l *CapList) Init(cc ...Cap) {
if l.m == nil {
l.m = make(map[CapID]Cap, len(cc))
}
for _, c := range cc {
l.m[c.ID] = c
}
} | [
"func",
"(",
"l",
"*",
"CapList",
")",
"Init",
"(",
"cc",
"...",
"Cap",
")",
"{",
"if",
"l",
".",
"m",
"==",
"nil",
"{",
"l",
".",
"m",
"=",
"make",
"(",
"map",
"[",
"CapID",
"]",
"Cap",
",",
"len",
"(",
"cc",
")",
")",
"\n",
"}",
"\n",
... | // Init initializes definition for a new capability.
// Not safe to be called concurrently with other methods. | [
"Init",
"initializes",
"definition",
"for",
"a",
"new",
"capability",
".",
"Not",
"safe",
"to",
"be",
"called",
"concurrently",
"with",
"other",
"methods",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/apicaps/caps.go#L57-L64 |
161,756 | moby/buildkit | util/apicaps/caps.go | All | func (l *CapList) All() []pb.APICap {
out := make([]pb.APICap, 0, len(l.m))
for _, c := range l.m {
out = append(out, pb.APICap{
ID: string(c.ID),
Enabled: c.Enabled,
Deprecated: c.Deprecated,
DisabledReason: c.DisabledReason,
DisabledReasonMsg: c.DisabledReasonMsg,
DisabledAlternative: c.DisabledAlternative,
})
}
sort.Slice(out, func(i, j int) bool {
return out[i].ID < out[j].ID
})
return out
} | go | func (l *CapList) All() []pb.APICap {
out := make([]pb.APICap, 0, len(l.m))
for _, c := range l.m {
out = append(out, pb.APICap{
ID: string(c.ID),
Enabled: c.Enabled,
Deprecated: c.Deprecated,
DisabledReason: c.DisabledReason,
DisabledReasonMsg: c.DisabledReasonMsg,
DisabledAlternative: c.DisabledAlternative,
})
}
sort.Slice(out, func(i, j int) bool {
return out[i].ID < out[j].ID
})
return out
} | [
"func",
"(",
"l",
"*",
"CapList",
")",
"All",
"(",
")",
"[",
"]",
"pb",
".",
"APICap",
"{",
"out",
":=",
"make",
"(",
"[",
"]",
"pb",
".",
"APICap",
",",
"0",
",",
"len",
"(",
"l",
".",
"m",
")",
")",
"\n",
"for",
"_",
",",
"c",
":=",
"... | // All reports the configuration of all known capabilities | [
"All",
"reports",
"the",
"configuration",
"of",
"all",
"known",
"capabilities"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/apicaps/caps.go#L67-L83 |
161,757 | moby/buildkit | util/apicaps/caps.go | CapSet | func (l *CapList) CapSet(caps []pb.APICap) CapSet {
m := make(map[string]*pb.APICap, len(caps))
for _, c := range caps {
if c.ID != "" {
c := c // capture loop iterator
m[c.ID] = &c
}
}
return CapSet{
list: l,
set: m,
}
} | go | func (l *CapList) CapSet(caps []pb.APICap) CapSet {
m := make(map[string]*pb.APICap, len(caps))
for _, c := range caps {
if c.ID != "" {
c := c // capture loop iterator
m[c.ID] = &c
}
}
return CapSet{
list: l,
set: m,
}
} | [
"func",
"(",
"l",
"*",
"CapList",
")",
"CapSet",
"(",
"caps",
"[",
"]",
"pb",
".",
"APICap",
")",
"CapSet",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"pb",
".",
"APICap",
",",
"len",
"(",
"caps",
")",
")",
"\n",
"for",
"_",... | // CapSet returns a CapSet for an capability configuration | [
"CapSet",
"returns",
"a",
"CapSet",
"for",
"an",
"capability",
"configuration"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/apicaps/caps.go#L86-L98 |
161,758 | moby/buildkit | util/apicaps/caps.go | Supports | func (s *CapSet) Supports(id CapID) error {
err := &CapError{ID: id}
c, ok := s.list.m[id]
if !ok {
return errors.WithStack(err)
}
err.Definition = &c
state, ok := s.set[string(id)]
if !ok {
return errors.WithStack(err)
}
err.State = state
if !state.Enabled {
return errors.WithStack(err)
}
return nil
} | go | func (s *CapSet) Supports(id CapID) error {
err := &CapError{ID: id}
c, ok := s.list.m[id]
if !ok {
return errors.WithStack(err)
}
err.Definition = &c
state, ok := s.set[string(id)]
if !ok {
return errors.WithStack(err)
}
err.State = state
if !state.Enabled {
return errors.WithStack(err)
}
return nil
} | [
"func",
"(",
"s",
"*",
"CapSet",
")",
"Supports",
"(",
"id",
"CapID",
")",
"error",
"{",
"err",
":=",
"&",
"CapError",
"{",
"ID",
":",
"id",
"}",
"\n",
"c",
",",
"ok",
":=",
"s",
".",
"list",
".",
"m",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",... | // Supports returns an error if capability is not supported | [
"Supports",
"returns",
"an",
"error",
"if",
"capability",
"is",
"not",
"supported"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/apicaps/caps.go#L107-L123 |
161,759 | moby/buildkit | solver/llbsolver/vertex.go | loadLLB | func loadLLB(def *pb.Definition, fn func(digest.Digest, *pb.Op, func(digest.Digest) (solver.Vertex, error)) (solver.Vertex, error)) (solver.Edge, error) {
if len(def.Def) == 0 {
return solver.Edge{}, errors.New("invalid empty definition")
}
allOps := make(map[digest.Digest]*pb.Op)
var dgst digest.Digest
for _, dt := range def.Def {
var op pb.Op
if err := (&op).Unmarshal(dt); err != nil {
return solver.Edge{}, errors.Wrap(err, "failed to parse llb proto op")
}
dgst = digest.FromBytes(dt)
allOps[dgst] = &op
}
lastOp := allOps[dgst]
delete(allOps, dgst)
dgst = lastOp.Inputs[0].Digest
cache := make(map[digest.Digest]solver.Vertex)
var rec func(dgst digest.Digest) (solver.Vertex, error)
rec = func(dgst digest.Digest) (solver.Vertex, error) {
if v, ok := cache[dgst]; ok {
return v, nil
}
op, ok := allOps[dgst]
if !ok {
return nil, errors.Errorf("invalid missing input digest %s", dgst)
}
v, err := fn(dgst, op, rec)
if err != nil {
return nil, err
}
cache[dgst] = v
return v, nil
}
v, err := rec(dgst)
if err != nil {
return solver.Edge{}, err
}
return solver.Edge{Vertex: v, Index: solver.Index(lastOp.Inputs[0].Index)}, nil
} | go | func loadLLB(def *pb.Definition, fn func(digest.Digest, *pb.Op, func(digest.Digest) (solver.Vertex, error)) (solver.Vertex, error)) (solver.Edge, error) {
if len(def.Def) == 0 {
return solver.Edge{}, errors.New("invalid empty definition")
}
allOps := make(map[digest.Digest]*pb.Op)
var dgst digest.Digest
for _, dt := range def.Def {
var op pb.Op
if err := (&op).Unmarshal(dt); err != nil {
return solver.Edge{}, errors.Wrap(err, "failed to parse llb proto op")
}
dgst = digest.FromBytes(dt)
allOps[dgst] = &op
}
lastOp := allOps[dgst]
delete(allOps, dgst)
dgst = lastOp.Inputs[0].Digest
cache := make(map[digest.Digest]solver.Vertex)
var rec func(dgst digest.Digest) (solver.Vertex, error)
rec = func(dgst digest.Digest) (solver.Vertex, error) {
if v, ok := cache[dgst]; ok {
return v, nil
}
op, ok := allOps[dgst]
if !ok {
return nil, errors.Errorf("invalid missing input digest %s", dgst)
}
v, err := fn(dgst, op, rec)
if err != nil {
return nil, err
}
cache[dgst] = v
return v, nil
}
v, err := rec(dgst)
if err != nil {
return solver.Edge{}, err
}
return solver.Edge{Vertex: v, Index: solver.Index(lastOp.Inputs[0].Index)}, nil
} | [
"func",
"loadLLB",
"(",
"def",
"*",
"pb",
".",
"Definition",
",",
"fn",
"func",
"(",
"digest",
".",
"Digest",
",",
"*",
"pb",
".",
"Op",
",",
"func",
"(",
"digest",
".",
"Digest",
")",
"(",
"solver",
".",
"Vertex",
",",
"error",
")",
")",
"(",
... | // loadLLB loads LLB.
// fn is executed sequentially. | [
"loadLLB",
"loads",
"LLB",
".",
"fn",
"is",
"executed",
"sequentially",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/llbsolver/vertex.go#L173-L219 |
161,760 | moby/buildkit | solver/edge.go | release | func (e *edge) release() {
if e.releaserCount > 0 {
e.releaserCount--
return
}
e.index.Release(e)
if e.result != nil {
go e.result.Release(context.TODO())
}
} | go | func (e *edge) release() {
if e.releaserCount > 0 {
e.releaserCount--
return
}
e.index.Release(e)
if e.result != nil {
go e.result.Release(context.TODO())
}
} | [
"func",
"(",
"e",
"*",
"edge",
")",
"release",
"(",
")",
"{",
"if",
"e",
".",
"releaserCount",
">",
"0",
"{",
"e",
".",
"releaserCount",
"--",
"\n",
"return",
"\n",
"}",
"\n",
"e",
".",
"index",
".",
"Release",
"(",
"e",
")",
"\n",
"if",
"e",
... | // release releases the edge resources | [
"release",
"releases",
"the",
"edge",
"resources"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/edge.go#L123-L132 |
161,761 | moby/buildkit | solver/edge.go | commitOptions | func (e *edge) commitOptions() ([]*CacheKey, []CachedResult) {
k := NewCacheKey(e.cacheMap.Digest, e.edge.Index)
if len(e.deps) == 0 {
keys := make([]*CacheKey, 0, len(e.cacheMapDigests))
for _, dgst := range e.cacheMapDigests {
keys = append(keys, NewCacheKey(dgst, e.edge.Index))
}
return keys, nil
}
inputs := make([][]CacheKeyWithSelector, len(e.deps))
results := make([]CachedResult, len(e.deps))
for i, dep := range e.deps {
for _, k := range dep.result.CacheKeys() {
inputs[i] = append(inputs[i], CacheKeyWithSelector{CacheKey: k, Selector: e.cacheMap.Deps[i].Selector})
}
if dep.slowCacheKey != nil {
inputs[i] = append(inputs[i], CacheKeyWithSelector{CacheKey: *dep.slowCacheKey})
}
results[i] = dep.result
}
k.deps = inputs
return []*CacheKey{k}, results
} | go | func (e *edge) commitOptions() ([]*CacheKey, []CachedResult) {
k := NewCacheKey(e.cacheMap.Digest, e.edge.Index)
if len(e.deps) == 0 {
keys := make([]*CacheKey, 0, len(e.cacheMapDigests))
for _, dgst := range e.cacheMapDigests {
keys = append(keys, NewCacheKey(dgst, e.edge.Index))
}
return keys, nil
}
inputs := make([][]CacheKeyWithSelector, len(e.deps))
results := make([]CachedResult, len(e.deps))
for i, dep := range e.deps {
for _, k := range dep.result.CacheKeys() {
inputs[i] = append(inputs[i], CacheKeyWithSelector{CacheKey: k, Selector: e.cacheMap.Deps[i].Selector})
}
if dep.slowCacheKey != nil {
inputs[i] = append(inputs[i], CacheKeyWithSelector{CacheKey: *dep.slowCacheKey})
}
results[i] = dep.result
}
k.deps = inputs
return []*CacheKey{k}, results
} | [
"func",
"(",
"e",
"*",
"edge",
")",
"commitOptions",
"(",
")",
"(",
"[",
"]",
"*",
"CacheKey",
",",
"[",
"]",
"CachedResult",
")",
"{",
"k",
":=",
"NewCacheKey",
"(",
"e",
".",
"cacheMap",
".",
"Digest",
",",
"e",
".",
"edge",
".",
"Index",
")",
... | // commitOptions returns parameters for the op execution | [
"commitOptions",
"returns",
"parameters",
"for",
"the",
"op",
"execution"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/edge.go#L135-L159 |
161,762 | moby/buildkit | solver/edge.go | isComplete | func (e *edge) isComplete() bool {
return e.err != nil || e.result != nil
} | go | func (e *edge) isComplete() bool {
return e.err != nil || e.result != nil
} | [
"func",
"(",
"e",
"*",
"edge",
")",
"isComplete",
"(",
")",
"bool",
"{",
"return",
"e",
".",
"err",
"!=",
"nil",
"||",
"e",
".",
"result",
"!=",
"nil",
"\n",
"}"
] | // isComplete returns true if edge state is final and will never change | [
"isComplete",
"returns",
"true",
"if",
"edge",
"state",
"is",
"final",
"and",
"will",
"never",
"change"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/edge.go#L162-L164 |
161,763 | moby/buildkit | solver/edge.go | finishIncoming | func (e *edge) finishIncoming(req pipe.Sender) {
err := e.err
if req.Request().Canceled && err == nil {
err = context.Canceled
}
if debugScheduler {
logrus.Debugf("finishIncoming %s %v %#v desired=%s", e.edge.Vertex.Name(), err, e.edgeState, req.Request().Payload.(*edgeRequest).desiredState)
}
req.Finalize(&e.edgeState, err)
} | go | func (e *edge) finishIncoming(req pipe.Sender) {
err := e.err
if req.Request().Canceled && err == nil {
err = context.Canceled
}
if debugScheduler {
logrus.Debugf("finishIncoming %s %v %#v desired=%s", e.edge.Vertex.Name(), err, e.edgeState, req.Request().Payload.(*edgeRequest).desiredState)
}
req.Finalize(&e.edgeState, err)
} | [
"func",
"(",
"e",
"*",
"edge",
")",
"finishIncoming",
"(",
"req",
"pipe",
".",
"Sender",
")",
"{",
"err",
":=",
"e",
".",
"err",
"\n",
"if",
"req",
".",
"Request",
"(",
")",
".",
"Canceled",
"&&",
"err",
"==",
"nil",
"{",
"err",
"=",
"context",
... | // finishIncoming finalizes the incoming pipe request | [
"finishIncoming",
"finalizes",
"the",
"incoming",
"pipe",
"request"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/edge.go#L167-L176 |
161,764 | moby/buildkit | solver/edge.go | updateIncoming | func (e *edge) updateIncoming(req pipe.Sender) {
req.Update(&e.edgeState)
} | go | func (e *edge) updateIncoming(req pipe.Sender) {
req.Update(&e.edgeState)
} | [
"func",
"(",
"e",
"*",
"edge",
")",
"updateIncoming",
"(",
"req",
"pipe",
".",
"Sender",
")",
"{",
"req",
".",
"Update",
"(",
"&",
"e",
".",
"edgeState",
")",
"\n",
"}"
] | // updateIncoming updates the current value of incoming pipe request | [
"updateIncoming",
"updates",
"the",
"current",
"value",
"of",
"incoming",
"pipe",
"request"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/edge.go#L179-L181 |
161,765 | moby/buildkit | solver/edge.go | probeCache | func (e *edge) probeCache(d *dep, depKeys []CacheKeyWithSelector) bool {
if len(depKeys) == 0 {
return false
}
if e.op.IgnoreCache() {
return false
}
keys, err := e.op.Cache().Query(depKeys, d.index, e.cacheMap.Digest, e.edge.Index)
if err != nil {
e.err = errors.Wrap(err, "error on cache query")
}
found := false
for _, k := range keys {
if _, ok := d.keyMap[k.ID]; !ok {
d.keyMap[k.ID] = k
found = true
}
}
return found
} | go | func (e *edge) probeCache(d *dep, depKeys []CacheKeyWithSelector) bool {
if len(depKeys) == 0 {
return false
}
if e.op.IgnoreCache() {
return false
}
keys, err := e.op.Cache().Query(depKeys, d.index, e.cacheMap.Digest, e.edge.Index)
if err != nil {
e.err = errors.Wrap(err, "error on cache query")
}
found := false
for _, k := range keys {
if _, ok := d.keyMap[k.ID]; !ok {
d.keyMap[k.ID] = k
found = true
}
}
return found
} | [
"func",
"(",
"e",
"*",
"edge",
")",
"probeCache",
"(",
"d",
"*",
"dep",
",",
"depKeys",
"[",
"]",
"CacheKeyWithSelector",
")",
"bool",
"{",
"if",
"len",
"(",
"depKeys",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"e",
".",
"op"... | // probeCache is called with unprocessed cache keys for dependency
// if the key could match the edge, the cacheRecords for dependency are filled | [
"probeCache",
"is",
"called",
"with",
"unprocessed",
"cache",
"keys",
"for",
"dependency",
"if",
"the",
"key",
"could",
"match",
"the",
"edge",
"the",
"cacheRecords",
"for",
"dependency",
"are",
"filled"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/edge.go#L185-L204 |
161,766 | moby/buildkit | solver/edge.go | checkDepMatchPossible | func (e *edge) checkDepMatchPossible(dep *dep) {
depHasSlowCache := e.cacheMap.Deps[dep.index].ComputeDigestFunc != nil
if !e.noCacheMatchPossible && (((!dep.slowCacheFoundKey && dep.slowCacheComplete && depHasSlowCache) || (!depHasSlowCache && dep.state >= edgeStatusCacheSlow)) && len(dep.keyMap) == 0) {
e.noCacheMatchPossible = true
}
} | go | func (e *edge) checkDepMatchPossible(dep *dep) {
depHasSlowCache := e.cacheMap.Deps[dep.index].ComputeDigestFunc != nil
if !e.noCacheMatchPossible && (((!dep.slowCacheFoundKey && dep.slowCacheComplete && depHasSlowCache) || (!depHasSlowCache && dep.state >= edgeStatusCacheSlow)) && len(dep.keyMap) == 0) {
e.noCacheMatchPossible = true
}
} | [
"func",
"(",
"e",
"*",
"edge",
")",
"checkDepMatchPossible",
"(",
"dep",
"*",
"dep",
")",
"{",
"depHasSlowCache",
":=",
"e",
".",
"cacheMap",
".",
"Deps",
"[",
"dep",
".",
"index",
"]",
".",
"ComputeDigestFunc",
"!=",
"nil",
"\n",
"if",
"!",
"e",
"."... | // checkDepMatchPossible checks if any cache matches are possible past this point | [
"checkDepMatchPossible",
"checks",
"if",
"any",
"cache",
"matches",
"are",
"possible",
"past",
"this",
"point"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/edge.go#L207-L212 |
161,767 | moby/buildkit | solver/edge.go | slowCacheFunc | func (e *edge) slowCacheFunc(dep *dep) ResultBasedCacheFunc {
if e.cacheMap == nil {
return nil
}
return e.cacheMap.Deps[int(dep.index)].ComputeDigestFunc
} | go | func (e *edge) slowCacheFunc(dep *dep) ResultBasedCacheFunc {
if e.cacheMap == nil {
return nil
}
return e.cacheMap.Deps[int(dep.index)].ComputeDigestFunc
} | [
"func",
"(",
"e",
"*",
"edge",
")",
"slowCacheFunc",
"(",
"dep",
"*",
"dep",
")",
"ResultBasedCacheFunc",
"{",
"if",
"e",
".",
"cacheMap",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"e",
".",
"cacheMap",
".",
"Deps",
"[",
"int",
... | // slowCacheFunc returns the result based cache func for dependency if it exists | [
"slowCacheFunc",
"returns",
"the",
"result",
"based",
"cache",
"func",
"for",
"dependency",
"if",
"it",
"exists"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/edge.go#L215-L220 |
161,768 | moby/buildkit | solver/edge.go | allDepsHaveKeys | func (e *edge) allDepsHaveKeys(matching bool) bool {
if e.cacheMap == nil {
return false
}
for _, d := range e.deps {
cond := len(d.keys) == 0
if matching {
cond = len(d.keyMap) == 0
}
if cond && d.slowCacheKey == nil && d.result == nil {
return false
}
}
return true
} | go | func (e *edge) allDepsHaveKeys(matching bool) bool {
if e.cacheMap == nil {
return false
}
for _, d := range e.deps {
cond := len(d.keys) == 0
if matching {
cond = len(d.keyMap) == 0
}
if cond && d.slowCacheKey == nil && d.result == nil {
return false
}
}
return true
} | [
"func",
"(",
"e",
"*",
"edge",
")",
"allDepsHaveKeys",
"(",
"matching",
"bool",
")",
"bool",
"{",
"if",
"e",
".",
"cacheMap",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"_",
",",
"d",
":=",
"range",
"e",
".",
"deps",
"{",
"cond"... | // allDepsHaveKeys checks if all dependencies have at least one key. used for
// determining if there is enough data for combining cache key for edge | [
"allDepsHaveKeys",
"checks",
"if",
"all",
"dependencies",
"have",
"at",
"least",
"one",
"key",
".",
"used",
"for",
"determining",
"if",
"there",
"is",
"enough",
"data",
"for",
"combining",
"cache",
"key",
"for",
"edge"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/edge.go#L224-L238 |
161,769 | moby/buildkit | solver/edge.go | currentIndexKey | func (e *edge) currentIndexKey() *CacheKey {
if e.cacheMap == nil {
return nil
}
keys := make([][]CacheKeyWithSelector, len(e.deps))
for i, d := range e.deps {
if len(d.keys) == 0 && d.result == nil {
return nil
}
for _, k := range d.keys {
keys[i] = append(keys[i], CacheKeyWithSelector{Selector: e.cacheMap.Deps[i].Selector, CacheKey: k})
}
if d.result != nil {
for _, rk := range d.result.CacheKeys() {
keys[i] = append(keys[i], CacheKeyWithSelector{Selector: e.cacheMap.Deps[i].Selector, CacheKey: rk})
}
if d.slowCacheKey != nil {
keys[i] = append(keys[i], CacheKeyWithSelector{CacheKey: ExportableCacheKey{CacheKey: d.slowCacheKey.CacheKey, Exporter: &exporter{k: d.slowCacheKey.CacheKey}}})
}
}
}
k := NewCacheKey(e.cacheMap.Digest, e.edge.Index)
k.deps = keys
return k
} | go | func (e *edge) currentIndexKey() *CacheKey {
if e.cacheMap == nil {
return nil
}
keys := make([][]CacheKeyWithSelector, len(e.deps))
for i, d := range e.deps {
if len(d.keys) == 0 && d.result == nil {
return nil
}
for _, k := range d.keys {
keys[i] = append(keys[i], CacheKeyWithSelector{Selector: e.cacheMap.Deps[i].Selector, CacheKey: k})
}
if d.result != nil {
for _, rk := range d.result.CacheKeys() {
keys[i] = append(keys[i], CacheKeyWithSelector{Selector: e.cacheMap.Deps[i].Selector, CacheKey: rk})
}
if d.slowCacheKey != nil {
keys[i] = append(keys[i], CacheKeyWithSelector{CacheKey: ExportableCacheKey{CacheKey: d.slowCacheKey.CacheKey, Exporter: &exporter{k: d.slowCacheKey.CacheKey}}})
}
}
}
k := NewCacheKey(e.cacheMap.Digest, e.edge.Index)
k.deps = keys
return k
} | [
"func",
"(",
"e",
"*",
"edge",
")",
"currentIndexKey",
"(",
")",
"*",
"CacheKey",
"{",
"if",
"e",
".",
"cacheMap",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"keys",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"CacheKeyWithSelector",
",",
"le... | // depKeys returns all current dependency cache keys | [
"depKeys",
"returns",
"all",
"current",
"dependency",
"cache",
"keys"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/edge.go#L241-L268 |
161,770 | moby/buildkit | solver/edge.go | skipPhase2SlowCache | func (e *edge) skipPhase2SlowCache(dep *dep) bool {
isPhase1 := false
for _, dep := range e.deps {
if (!dep.slowCacheComplete && e.slowCacheFunc(dep) != nil || dep.state < edgeStatusCacheSlow) && len(dep.keyMap) == 0 {
isPhase1 = true
break
}
}
if isPhase1 && !dep.slowCacheComplete && e.slowCacheFunc(dep) != nil && len(dep.keyMap) > 0 {
return true
}
return false
} | go | func (e *edge) skipPhase2SlowCache(dep *dep) bool {
isPhase1 := false
for _, dep := range e.deps {
if (!dep.slowCacheComplete && e.slowCacheFunc(dep) != nil || dep.state < edgeStatusCacheSlow) && len(dep.keyMap) == 0 {
isPhase1 = true
break
}
}
if isPhase1 && !dep.slowCacheComplete && e.slowCacheFunc(dep) != nil && len(dep.keyMap) > 0 {
return true
}
return false
} | [
"func",
"(",
"e",
"*",
"edge",
")",
"skipPhase2SlowCache",
"(",
"dep",
"*",
"dep",
")",
"bool",
"{",
"isPhase1",
":=",
"false",
"\n",
"for",
"_",
",",
"dep",
":=",
"range",
"e",
".",
"deps",
"{",
"if",
"(",
"!",
"dep",
".",
"slowCacheComplete",
"&&... | // slow cache keys can be computed in 2 phases if there are multiple deps.
// first evaluate ones that didn't match any definition based keys | [
"slow",
"cache",
"keys",
"can",
"be",
"computed",
"in",
"2",
"phases",
"if",
"there",
"are",
"multiple",
"deps",
".",
"first",
"evaluate",
"ones",
"that",
"didn",
"t",
"match",
"any",
"definition",
"based",
"keys"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/edge.go#L272-L285 |
161,771 | moby/buildkit | solver/edge.go | execIfPossible | func (e *edge) execIfPossible(f *pipeFactory) bool {
if len(e.cacheRecords) > 0 {
if e.keysDidChange {
e.postpone(f)
return true
}
e.execReq = f.NewFuncRequest(e.loadCache)
for req := range e.depRequests {
req.Cancel()
}
return true
} else if e.allDepsCompleted {
if e.keysDidChange {
e.postpone(f)
return true
}
e.execReq = f.NewFuncRequest(e.execOp)
return true
}
return false
} | go | func (e *edge) execIfPossible(f *pipeFactory) bool {
if len(e.cacheRecords) > 0 {
if e.keysDidChange {
e.postpone(f)
return true
}
e.execReq = f.NewFuncRequest(e.loadCache)
for req := range e.depRequests {
req.Cancel()
}
return true
} else if e.allDepsCompleted {
if e.keysDidChange {
e.postpone(f)
return true
}
e.execReq = f.NewFuncRequest(e.execOp)
return true
}
return false
} | [
"func",
"(",
"e",
"*",
"edge",
")",
"execIfPossible",
"(",
"f",
"*",
"pipeFactory",
")",
"bool",
"{",
"if",
"len",
"(",
"e",
".",
"cacheRecords",
")",
">",
"0",
"{",
"if",
"e",
".",
"keysDidChange",
"{",
"e",
".",
"postpone",
"(",
"f",
")",
"\n",... | // execIfPossible creates a request for getting the edge result if there is
// enough state | [
"execIfPossible",
"creates",
"a",
"request",
"for",
"getting",
"the",
"edge",
"result",
"if",
"there",
"is",
"enough",
"state"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/edge.go#L812-L832 |
161,772 | moby/buildkit | solver/edge.go | postpone | func (e *edge) postpone(f *pipeFactory) {
f.NewFuncRequest(func(context.Context) (interface{}, error) {
return nil, nil
})
} | go | func (e *edge) postpone(f *pipeFactory) {
f.NewFuncRequest(func(context.Context) (interface{}, error) {
return nil, nil
})
} | [
"func",
"(",
"e",
"*",
"edge",
")",
"postpone",
"(",
"f",
"*",
"pipeFactory",
")",
"{",
"f",
".",
"NewFuncRequest",
"(",
"func",
"(",
"context",
".",
"Context",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"return",
"nil",
",",
"nil",
... | // postpone delays exec to next unpark invocation if we have unprocessed keys | [
"postpone",
"delays",
"exec",
"to",
"next",
"unpark",
"invocation",
"if",
"we",
"have",
"unprocessed",
"keys"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/edge.go#L835-L839 |
161,773 | moby/buildkit | solver/edge.go | loadCache | func (e *edge) loadCache(ctx context.Context) (interface{}, error) {
recs := make([]*CacheRecord, 0, len(e.cacheRecords))
for _, r := range e.cacheRecords {
recs = append(recs, r)
}
rec := getBestResult(recs)
logrus.Debugf("load cache for %s with %s", e.edge.Vertex.Name(), rec.ID)
res, err := e.op.LoadCache(ctx, rec)
if err != nil {
return nil, err
}
return NewCachedResult(res, []ExportableCacheKey{{CacheKey: rec.key, Exporter: &exporter{k: rec.key, record: rec, edge: e}}}), nil
} | go | func (e *edge) loadCache(ctx context.Context) (interface{}, error) {
recs := make([]*CacheRecord, 0, len(e.cacheRecords))
for _, r := range e.cacheRecords {
recs = append(recs, r)
}
rec := getBestResult(recs)
logrus.Debugf("load cache for %s with %s", e.edge.Vertex.Name(), rec.ID)
res, err := e.op.LoadCache(ctx, rec)
if err != nil {
return nil, err
}
return NewCachedResult(res, []ExportableCacheKey{{CacheKey: rec.key, Exporter: &exporter{k: rec.key, record: rec, edge: e}}}), nil
} | [
"func",
"(",
"e",
"*",
"edge",
")",
"loadCache",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"recs",
":=",
"make",
"(",
"[",
"]",
"*",
"CacheRecord",
",",
"0",
",",
"len",
"(",
"e",
".",
"cach... | // loadCache creates a request to load edge result from cache | [
"loadCache",
"creates",
"a",
"request",
"to",
"load",
"edge",
"result",
"from",
"cache"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/edge.go#L842-L857 |
161,774 | moby/buildkit | solver/edge.go | execOp | func (e *edge) execOp(ctx context.Context) (interface{}, error) {
cacheKeys, inputs := e.commitOptions()
results, subExporters, err := e.op.Exec(ctx, toResultSlice(inputs))
if err != nil {
return nil, err
}
index := e.edge.Index
if len(results) <= int(index) {
return nil, errors.Errorf("invalid response from exec need %d index but %d results received", index, len(results))
}
res := results[int(index)]
for i := range results {
if i != int(index) {
go results[i].Release(context.TODO())
}
}
var exporters []CacheExporter
for _, cacheKey := range cacheKeys {
ck, err := e.op.Cache().Save(cacheKey, res, time.Now())
if err != nil {
return nil, err
}
if exp, ok := ck.Exporter.(*exporter); ok {
exp.edge = e
}
exps := make([]CacheExporter, 0, len(subExporters))
for _, exp := range subExporters {
exps = append(exps, exp.Exporter)
}
exporters = append(exporters, ck.Exporter)
exporters = append(exporters, exps...)
}
ek := make([]ExportableCacheKey, 0, len(cacheKeys))
for _, ck := range cacheKeys {
ek = append(ek, ExportableCacheKey{
CacheKey: ck,
Exporter: &mergedExporter{exporters: exporters},
})
}
return NewCachedResult(res, ek), nil
} | go | func (e *edge) execOp(ctx context.Context) (interface{}, error) {
cacheKeys, inputs := e.commitOptions()
results, subExporters, err := e.op.Exec(ctx, toResultSlice(inputs))
if err != nil {
return nil, err
}
index := e.edge.Index
if len(results) <= int(index) {
return nil, errors.Errorf("invalid response from exec need %d index but %d results received", index, len(results))
}
res := results[int(index)]
for i := range results {
if i != int(index) {
go results[i].Release(context.TODO())
}
}
var exporters []CacheExporter
for _, cacheKey := range cacheKeys {
ck, err := e.op.Cache().Save(cacheKey, res, time.Now())
if err != nil {
return nil, err
}
if exp, ok := ck.Exporter.(*exporter); ok {
exp.edge = e
}
exps := make([]CacheExporter, 0, len(subExporters))
for _, exp := range subExporters {
exps = append(exps, exp.Exporter)
}
exporters = append(exporters, ck.Exporter)
exporters = append(exporters, exps...)
}
ek := make([]ExportableCacheKey, 0, len(cacheKeys))
for _, ck := range cacheKeys {
ek = append(ek, ExportableCacheKey{
CacheKey: ck,
Exporter: &mergedExporter{exporters: exporters},
})
}
return NewCachedResult(res, ek), nil
} | [
"func",
"(",
"e",
"*",
"edge",
")",
"execOp",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"cacheKeys",
",",
"inputs",
":=",
"e",
".",
"commitOptions",
"(",
")",
"\n",
"results",
",",
"subExporters",... | // execOp creates a request to execute the vertex operation | [
"execOp",
"creates",
"a",
"request",
"to",
"execute",
"the",
"vertex",
"operation"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/edge.go#L860-L910 |
161,775 | moby/buildkit | snapshot/snapshotter.go | NewContainerdSnapshotter | func NewContainerdSnapshotter(s Snapshotter) (snapshots.Snapshotter, func() error) {
cs := &containerdSnapshotter{Snapshotter: s}
return cs, cs.release
} | go | func NewContainerdSnapshotter(s Snapshotter) (snapshots.Snapshotter, func() error) {
cs := &containerdSnapshotter{Snapshotter: s}
return cs, cs.release
} | [
"func",
"NewContainerdSnapshotter",
"(",
"s",
"Snapshotter",
")",
"(",
"snapshots",
".",
"Snapshotter",
",",
"func",
"(",
")",
"error",
")",
"{",
"cs",
":=",
"&",
"containerdSnapshotter",
"{",
"Snapshotter",
":",
"s",
"}",
"\n",
"return",
"cs",
",",
"cs",
... | // NewContainerdSnapshotter converts snapshotter to containerd snapshotter | [
"NewContainerdSnapshotter",
"converts",
"snapshotter",
"to",
"containerd",
"snapshotter"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/snapshot/snapshotter.go#L101-L104 |
161,776 | moby/buildkit | cache/refs.go | remove | func (cr *cacheRecord) remove(ctx context.Context, removeSnapshot bool) error {
delete(cr.cm.records, cr.ID())
if cr.parent != nil {
if err := cr.parent.(*immutableRef).release(ctx); err != nil {
return err
}
}
if removeSnapshot {
if err := cr.cm.Snapshotter.Remove(ctx, cr.ID()); err != nil {
return err
}
}
if err := cr.cm.md.Clear(cr.ID()); err != nil {
return err
}
return nil
} | go | func (cr *cacheRecord) remove(ctx context.Context, removeSnapshot bool) error {
delete(cr.cm.records, cr.ID())
if cr.parent != nil {
if err := cr.parent.(*immutableRef).release(ctx); err != nil {
return err
}
}
if removeSnapshot {
if err := cr.cm.Snapshotter.Remove(ctx, cr.ID()); err != nil {
return err
}
}
if err := cr.cm.md.Clear(cr.ID()); err != nil {
return err
}
return nil
} | [
"func",
"(",
"cr",
"*",
"cacheRecord",
")",
"remove",
"(",
"ctx",
"context",
".",
"Context",
",",
"removeSnapshot",
"bool",
")",
"error",
"{",
"delete",
"(",
"cr",
".",
"cm",
".",
"records",
",",
"cr",
".",
"ID",
"(",
")",
")",
"\n",
"if",
"cr",
... | // call when holding the manager lock | [
"call",
"when",
"holding",
"the",
"manager",
"lock"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/cache/refs.go#L181-L197 |
161,777 | moby/buildkit | frontend/dockerfile/parser/split_command.go | splitCommand | func splitCommand(line string) (string, []string, string, error) {
var args string
var flags []string
// Make sure we get the same results irrespective of leading/trailing spaces
cmdline := tokenWhitespace.Split(strings.TrimSpace(line), 2)
cmd := strings.ToLower(cmdline[0])
if len(cmdline) == 2 {
var err error
args, flags, err = extractBuilderFlags(cmdline[1])
if err != nil {
return "", nil, "", err
}
}
return cmd, flags, strings.TrimSpace(args), nil
} | go | func splitCommand(line string) (string, []string, string, error) {
var args string
var flags []string
// Make sure we get the same results irrespective of leading/trailing spaces
cmdline := tokenWhitespace.Split(strings.TrimSpace(line), 2)
cmd := strings.ToLower(cmdline[0])
if len(cmdline) == 2 {
var err error
args, flags, err = extractBuilderFlags(cmdline[1])
if err != nil {
return "", nil, "", err
}
}
return cmd, flags, strings.TrimSpace(args), nil
} | [
"func",
"splitCommand",
"(",
"line",
"string",
")",
"(",
"string",
",",
"[",
"]",
"string",
",",
"string",
",",
"error",
")",
"{",
"var",
"args",
"string",
"\n",
"var",
"flags",
"[",
"]",
"string",
"\n\n",
"// Make sure we get the same results irrespective of ... | // splitCommand takes a single line of text and parses out the cmd and args,
// which are used for dispatching to more exact parsing functions. | [
"splitCommand",
"takes",
"a",
"single",
"line",
"of",
"text",
"and",
"parses",
"out",
"the",
"cmd",
"and",
"args",
"which",
"are",
"used",
"for",
"dispatching",
"to",
"more",
"exact",
"parsing",
"functions",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/parser/split_command.go#L10-L27 |
161,778 | moby/buildkit | cache/manager.go | init | func (cm *cacheManager) init(ctx context.Context) error {
items, err := cm.md.All()
if err != nil {
return err
}
for _, si := range items {
if _, err := cm.getRecord(ctx, si.ID(), false); err != nil {
logrus.Debugf("could not load snapshot %s: %v", si.ID(), err)
cm.md.Clear(si.ID())
// TODO: make sure content is deleted as well
}
}
return nil
} | go | func (cm *cacheManager) init(ctx context.Context) error {
items, err := cm.md.All()
if err != nil {
return err
}
for _, si := range items {
if _, err := cm.getRecord(ctx, si.ID(), false); err != nil {
logrus.Debugf("could not load snapshot %s: %v", si.ID(), err)
cm.md.Clear(si.ID())
// TODO: make sure content is deleted as well
}
}
return nil
} | [
"func",
"(",
"cm",
"*",
"cacheManager",
")",
"init",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"items",
",",
"err",
":=",
"cm",
".",
"md",
".",
"All",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\... | // init loads all snapshots from metadata state and tries to load the records
// from the snapshotter. If snaphot can't be found, metadata is deleted as well. | [
"init",
"loads",
"all",
"snapshots",
"from",
"metadata",
"state",
"and",
"tries",
"to",
"load",
"the",
"records",
"from",
"the",
"snapshotter",
".",
"If",
"snaphot",
"can",
"t",
"be",
"found",
"metadata",
"is",
"deleted",
"as",
"well",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/cache/manager.go#L85-L99 |
161,779 | moby/buildkit | cache/manager.go | get | func (cm *cacheManager) get(ctx context.Context, id string, fromSnapshotter bool, opts ...RefOption) (ImmutableRef, error) {
rec, err := cm.getRecord(ctx, id, fromSnapshotter, opts...)
if err != nil {
return nil, err
}
rec.mu.Lock()
defer rec.mu.Unlock()
triggerUpdate := true
for _, o := range opts {
if o == NoUpdateLastUsed {
triggerUpdate = false
}
}
if rec.mutable {
if len(rec.refs) != 0 {
return nil, errors.Wrapf(ErrLocked, "%s is locked", id)
}
if rec.equalImmutable != nil {
return rec.equalImmutable.ref(triggerUpdate), nil
}
return rec.mref(triggerUpdate).commit(ctx)
}
return rec.ref(triggerUpdate), nil
} | go | func (cm *cacheManager) get(ctx context.Context, id string, fromSnapshotter bool, opts ...RefOption) (ImmutableRef, error) {
rec, err := cm.getRecord(ctx, id, fromSnapshotter, opts...)
if err != nil {
return nil, err
}
rec.mu.Lock()
defer rec.mu.Unlock()
triggerUpdate := true
for _, o := range opts {
if o == NoUpdateLastUsed {
triggerUpdate = false
}
}
if rec.mutable {
if len(rec.refs) != 0 {
return nil, errors.Wrapf(ErrLocked, "%s is locked", id)
}
if rec.equalImmutable != nil {
return rec.equalImmutable.ref(triggerUpdate), nil
}
return rec.mref(triggerUpdate).commit(ctx)
}
return rec.ref(triggerUpdate), nil
} | [
"func",
"(",
"cm",
"*",
"cacheManager",
")",
"get",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
",",
"fromSnapshotter",
"bool",
",",
"opts",
"...",
"RefOption",
")",
"(",
"ImmutableRef",
",",
"error",
")",
"{",
"rec",
",",
"err",
":=",
... | // get requires manager lock to be taken | [
"get",
"requires",
"manager",
"lock",
"to",
"be",
"taken"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/cache/manager.go#L128-L154 |
161,780 | moby/buildkit | cache/manager.go | getRecord | func (cm *cacheManager) getRecord(ctx context.Context, id string, fromSnapshotter bool, opts ...RefOption) (cr *cacheRecord, retErr error) {
if rec, ok := cm.records[id]; ok {
if rec.isDead() {
return nil, errNotFound
}
return rec, nil
}
md, ok := cm.md.Get(id)
if !ok && !fromSnapshotter {
return nil, errNotFound
}
if mutableID := getEqualMutable(md); mutableID != "" {
mutable, err := cm.getRecord(ctx, mutableID, fromSnapshotter)
if err != nil {
// check loading mutable deleted record from disk
if errors.Cause(err) == errNotFound {
cm.md.Clear(id)
}
return nil, err
}
rec := &cacheRecord{
mu: &sync.Mutex{},
cm: cm,
refs: make(map[ref]struct{}),
parent: mutable.parentRef(false),
md: md,
equalMutable: &mutableRef{cacheRecord: mutable},
}
mutable.equalImmutable = &immutableRef{cacheRecord: rec}
cm.records[id] = rec
return rec, nil
}
info, err := cm.Snapshotter.Stat(ctx, id)
if err != nil {
return nil, errors.Wrap(errNotFound, err.Error())
}
var parent ImmutableRef
if info.Parent != "" {
parent, err = cm.get(ctx, info.Parent, fromSnapshotter, append(opts, NoUpdateLastUsed)...)
if err != nil {
return nil, err
}
defer func() {
if retErr != nil {
parent.Release(context.TODO())
}
}()
}
rec := &cacheRecord{
mu: &sync.Mutex{},
mutable: info.Kind != snapshots.KindCommitted,
cm: cm,
refs: make(map[ref]struct{}),
parent: parent,
md: md,
}
// the record was deleted but we crashed before data on disk was removed
if getDeleted(md) {
if err := rec.remove(ctx, true); err != nil {
return nil, err
}
return nil, errNotFound
}
if err := initializeMetadata(rec, opts...); err != nil {
if parent != nil {
parent.Release(context.TODO())
}
return nil, err
}
cm.records[id] = rec
return rec, nil
} | go | func (cm *cacheManager) getRecord(ctx context.Context, id string, fromSnapshotter bool, opts ...RefOption) (cr *cacheRecord, retErr error) {
if rec, ok := cm.records[id]; ok {
if rec.isDead() {
return nil, errNotFound
}
return rec, nil
}
md, ok := cm.md.Get(id)
if !ok && !fromSnapshotter {
return nil, errNotFound
}
if mutableID := getEqualMutable(md); mutableID != "" {
mutable, err := cm.getRecord(ctx, mutableID, fromSnapshotter)
if err != nil {
// check loading mutable deleted record from disk
if errors.Cause(err) == errNotFound {
cm.md.Clear(id)
}
return nil, err
}
rec := &cacheRecord{
mu: &sync.Mutex{},
cm: cm,
refs: make(map[ref]struct{}),
parent: mutable.parentRef(false),
md: md,
equalMutable: &mutableRef{cacheRecord: mutable},
}
mutable.equalImmutable = &immutableRef{cacheRecord: rec}
cm.records[id] = rec
return rec, nil
}
info, err := cm.Snapshotter.Stat(ctx, id)
if err != nil {
return nil, errors.Wrap(errNotFound, err.Error())
}
var parent ImmutableRef
if info.Parent != "" {
parent, err = cm.get(ctx, info.Parent, fromSnapshotter, append(opts, NoUpdateLastUsed)...)
if err != nil {
return nil, err
}
defer func() {
if retErr != nil {
parent.Release(context.TODO())
}
}()
}
rec := &cacheRecord{
mu: &sync.Mutex{},
mutable: info.Kind != snapshots.KindCommitted,
cm: cm,
refs: make(map[ref]struct{}),
parent: parent,
md: md,
}
// the record was deleted but we crashed before data on disk was removed
if getDeleted(md) {
if err := rec.remove(ctx, true); err != nil {
return nil, err
}
return nil, errNotFound
}
if err := initializeMetadata(rec, opts...); err != nil {
if parent != nil {
parent.Release(context.TODO())
}
return nil, err
}
cm.records[id] = rec
return rec, nil
} | [
"func",
"(",
"cm",
"*",
"cacheManager",
")",
"getRecord",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
",",
"fromSnapshotter",
"bool",
",",
"opts",
"...",
"RefOption",
")",
"(",
"cr",
"*",
"cacheRecord",
",",
"retErr",
"error",
")",
"{",
... | // getRecord returns record for id. Requires manager lock. | [
"getRecord",
"returns",
"record",
"for",
"id",
".",
"Requires",
"manager",
"lock",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/cache/manager.go#L157-L235 |
161,781 | moby/buildkit | worker/workercontroller.go | Add | func (c *Controller) Add(w Worker) error {
c.workers.Store(w.ID(), w)
if c.defaultID == "" {
c.defaultID = w.ID()
}
return nil
} | go | func (c *Controller) Add(w Worker) error {
c.workers.Store(w.ID(), w)
if c.defaultID == "" {
c.defaultID = w.ID()
}
return nil
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"Add",
"(",
"w",
"Worker",
")",
"error",
"{",
"c",
".",
"workers",
".",
"Store",
"(",
"w",
".",
"ID",
"(",
")",
",",
"w",
")",
"\n",
"if",
"c",
".",
"defaultID",
"==",
"\"",
"\"",
"{",
"c",
".",
"de... | // Add adds a local worker | [
"Add",
"adds",
"a",
"local",
"worker"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/worker/workercontroller.go#L20-L26 |
161,782 | moby/buildkit | worker/workercontroller.go | List | func (c *Controller) List(filterStrings ...string) ([]Worker, error) {
filter, err := filters.ParseAll(filterStrings...)
if err != nil {
return nil, err
}
var workers []Worker
c.workers.Range(func(k, v interface{}) bool {
w := v.(Worker)
if filter.Match(adaptWorker(w)) {
workers = append(workers, w)
}
return true
})
return workers, nil
} | go | func (c *Controller) List(filterStrings ...string) ([]Worker, error) {
filter, err := filters.ParseAll(filterStrings...)
if err != nil {
return nil, err
}
var workers []Worker
c.workers.Range(func(k, v interface{}) bool {
w := v.(Worker)
if filter.Match(adaptWorker(w)) {
workers = append(workers, w)
}
return true
})
return workers, nil
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"List",
"(",
"filterStrings",
"...",
"string",
")",
"(",
"[",
"]",
"Worker",
",",
"error",
")",
"{",
"filter",
",",
"err",
":=",
"filters",
".",
"ParseAll",
"(",
"filterStrings",
"...",
")",
"\n",
"if",
"err"... | // List lists workers | [
"List",
"lists",
"workers"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/worker/workercontroller.go#L29-L43 |
161,783 | moby/buildkit | worker/workercontroller.go | GetDefault | func (c *Controller) GetDefault() (Worker, error) {
if c.defaultID == "" {
return nil, errors.Errorf("no default worker")
}
return c.Get(c.defaultID)
} | go | func (c *Controller) GetDefault() (Worker, error) {
if c.defaultID == "" {
return nil, errors.Errorf("no default worker")
}
return c.Get(c.defaultID)
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"GetDefault",
"(",
")",
"(",
"Worker",
",",
"error",
")",
"{",
"if",
"c",
".",
"defaultID",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"... | // GetDefault returns the default local worker | [
"GetDefault",
"returns",
"the",
"default",
"local",
"worker"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/worker/workercontroller.go#L46-L51 |
161,784 | moby/buildkit | util/binfmt_misc/generate.go | main | func main() {
flag.Parse()
if len(flag.Args()) == 0 {
panic(fmt.Errorf("arch is required"))
}
for _, arch := range flag.Args() {
wd, err := os.Getwd()
if err != nil {
panic(err)
}
f, err := os.Open(filepath.Join(wd, arch))
if err != nil {
panic(err)
}
defer f.Close()
buf := &bytes.Buffer{}
gz, err := gzip.NewWriterLevel(newHexStringWriter(buf), gzip.BestCompression)
if err != nil {
panic(err)
}
if _, err = io.Copy(gz, f); err != nil {
panic(err)
}
if err := gz.Close(); err != nil {
panic(err)
}
fn := filepath.Join(wd, arch+"_binary.go")
dest, err := os.OpenFile(fn, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
panic(err)
}
if err := tmpl.Execute(dest, struct{ Arch, Package, Data string }{Arch: arch, Package: "binfmt_misc", Data: buf.String()}); err != nil {
panic(err)
}
dest.Close()
}
} | go | func main() {
flag.Parse()
if len(flag.Args()) == 0 {
panic(fmt.Errorf("arch is required"))
}
for _, arch := range flag.Args() {
wd, err := os.Getwd()
if err != nil {
panic(err)
}
f, err := os.Open(filepath.Join(wd, arch))
if err != nil {
panic(err)
}
defer f.Close()
buf := &bytes.Buffer{}
gz, err := gzip.NewWriterLevel(newHexStringWriter(buf), gzip.BestCompression)
if err != nil {
panic(err)
}
if _, err = io.Copy(gz, f); err != nil {
panic(err)
}
if err := gz.Close(); err != nil {
panic(err)
}
fn := filepath.Join(wd, arch+"_binary.go")
dest, err := os.OpenFile(fn, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
panic(err)
}
if err := tmpl.Execute(dest, struct{ Arch, Package, Data string }{Arch: arch, Package: "binfmt_misc", Data: buf.String()}); err != nil {
panic(err)
}
dest.Close()
}
} | [
"func",
"main",
"(",
")",
"{",
"flag",
".",
"Parse",
"(",
")",
"\n",
"if",
"len",
"(",
"flag",
".",
"Args",
"(",
")",
")",
"==",
"0",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
... | // saves baseimage binaries statically into go code | [
"saves",
"baseimage",
"binaries",
"statically",
"into",
"go",
"code"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/binfmt_misc/generate.go#L17-L57 |
161,785 | moby/buildkit | worker/base/worker.go | Labels | func Labels(executor, snapshotter string) map[string]string {
hostname, err := os.Hostname()
if err != nil {
hostname = "unknown"
}
labels := map[string]string{
worker.LabelExecutor: executor,
worker.LabelSnapshotter: snapshotter,
worker.LabelHostname: hostname,
}
return labels
} | go | func Labels(executor, snapshotter string) map[string]string {
hostname, err := os.Hostname()
if err != nil {
hostname = "unknown"
}
labels := map[string]string{
worker.LabelExecutor: executor,
worker.LabelSnapshotter: snapshotter,
worker.LabelHostname: hostname,
}
return labels
} | [
"func",
"Labels",
"(",
"executor",
",",
"snapshotter",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"hostname",
",",
"err",
":=",
"os",
".",
"Hostname",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"hostname",
"=",
"\"",
"\"",
"\n",
"... | // Labels returns default labels
// utility function. could be moved to the constructor logic? | [
"Labels",
"returns",
"default",
"labels",
"utility",
"function",
".",
"could",
"be",
"moved",
"to",
"the",
"constructor",
"logic?"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/worker/base/worker.go#L410-L421 |
161,786 | moby/buildkit | worker/base/worker.go | ID | func ID(root string) (string, error) {
f := filepath.Join(root, "workerid")
b, err := ioutil.ReadFile(f)
if err != nil {
if os.IsNotExist(err) {
id := identity.NewID()
err := ioutil.WriteFile(f, []byte(id), 0400)
return id, err
} else {
return "", err
}
}
return string(b), nil
} | go | func ID(root string) (string, error) {
f := filepath.Join(root, "workerid")
b, err := ioutil.ReadFile(f)
if err != nil {
if os.IsNotExist(err) {
id := identity.NewID()
err := ioutil.WriteFile(f, []byte(id), 0400)
return id, err
} else {
return "", err
}
}
return string(b), nil
} | [
"func",
"ID",
"(",
"root",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"f",
":=",
"filepath",
".",
"Join",
"(",
"root",
",",
"\"",
"\"",
")",
"\n",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"f",
")",
"\n",
"if",
"err",
... | // ID reads the worker id from the `workerid` file.
// If not exist, it creates a random one, | [
"ID",
"reads",
"the",
"worker",
"id",
"from",
"the",
"workerid",
"file",
".",
"If",
"not",
"exist",
"it",
"creates",
"a",
"random",
"one"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/worker/base/worker.go#L425-L438 |
161,787 | moby/buildkit | solver/jobs.go | deleteIfUnreferenced | func (jl *Solver) deleteIfUnreferenced(k digest.Digest, st *state) {
if len(st.jobs) == 0 && len(st.parents) == 0 {
for chKey := range st.childVtx {
chState := jl.actives[chKey]
delete(chState.parents, k)
jl.deleteIfUnreferenced(chKey, chState)
}
st.Release()
delete(jl.actives, k)
}
} | go | func (jl *Solver) deleteIfUnreferenced(k digest.Digest, st *state) {
if len(st.jobs) == 0 && len(st.parents) == 0 {
for chKey := range st.childVtx {
chState := jl.actives[chKey]
delete(chState.parents, k)
jl.deleteIfUnreferenced(chKey, chState)
}
st.Release()
delete(jl.actives, k)
}
} | [
"func",
"(",
"jl",
"*",
"Solver",
")",
"deleteIfUnreferenced",
"(",
"k",
"digest",
".",
"Digest",
",",
"st",
"*",
"state",
")",
"{",
"if",
"len",
"(",
"st",
".",
"jobs",
")",
"==",
"0",
"&&",
"len",
"(",
"st",
".",
"parents",
")",
"==",
"0",
"{... | // called with solver lock | [
"called",
"with",
"solver",
"lock"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/solver/jobs.go#L428-L438 |
161,788 | moby/buildkit | util/entitlements/security_linux.go | WithInsecureSpec | func WithInsecureSpec() oci.SpecOpts {
return func(_ context.Context, _ oci.Client, _ *containers.Container, s *specs.Spec) error {
addCaps := []string{
"CAP_FSETID",
"CAP_KILL",
"CAP_FOWNER",
"CAP_MKNOD",
"CAP_CHOWN",
"CAP_DAC_OVERRIDE",
"CAP_NET_RAW",
"CAP_SETGID",
"CAP_SETUID",
"CAP_SETPCAP",
"CAP_SETFCAP",
"CAP_NET_BIND_SERVICE",
"CAP_SYS_CHROOT",
"CAP_AUDIT_WRITE",
"CAP_MAC_ADMIN",
"CAP_MAC_OVERRIDE",
"CAP_DAC_READ_SEARCH",
"CAP_SYS_PTRACE",
"CAP_SYS_MODULE",
"CAP_SYSLOG",
"CAP_SYS_RAWIO",
"CAP_SYS_ADMIN",
"CAP_LINUX_IMMUTABLE",
"CAP_SYS_BOOT",
"CAP_SYS_NICE",
"CAP_SYS_PACCT",
"CAP_SYS_TTY_CONFIG",
"CAP_SYS_TIME",
"CAP_WAKE_ALARM",
"CAP_AUDIT_READ",
"CAP_AUDIT_CONTROL",
"CAP_SYS_RESOURCE",
"CAP_BLOCK_SUSPEND",
"CAP_IPC_LOCK",
"CAP_IPC_OWNER",
"CAP_LEASE",
"CAP_NET_ADMIN",
"CAP_NET_BROADCAST",
}
for _, cap := range addCaps {
s.Process.Capabilities.Bounding = append(s.Process.Capabilities.Bounding, cap)
s.Process.Capabilities.Ambient = append(s.Process.Capabilities.Ambient, cap)
s.Process.Capabilities.Effective = append(s.Process.Capabilities.Effective, cap)
s.Process.Capabilities.Inheritable = append(s.Process.Capabilities.Inheritable, cap)
s.Process.Capabilities.Permitted = append(s.Process.Capabilities.Permitted, cap)
}
s.Linux.ReadonlyPaths = []string{}
s.Linux.MaskedPaths = []string{}
s.Process.ApparmorProfile = ""
return nil
}
} | go | func WithInsecureSpec() oci.SpecOpts {
return func(_ context.Context, _ oci.Client, _ *containers.Container, s *specs.Spec) error {
addCaps := []string{
"CAP_FSETID",
"CAP_KILL",
"CAP_FOWNER",
"CAP_MKNOD",
"CAP_CHOWN",
"CAP_DAC_OVERRIDE",
"CAP_NET_RAW",
"CAP_SETGID",
"CAP_SETUID",
"CAP_SETPCAP",
"CAP_SETFCAP",
"CAP_NET_BIND_SERVICE",
"CAP_SYS_CHROOT",
"CAP_AUDIT_WRITE",
"CAP_MAC_ADMIN",
"CAP_MAC_OVERRIDE",
"CAP_DAC_READ_SEARCH",
"CAP_SYS_PTRACE",
"CAP_SYS_MODULE",
"CAP_SYSLOG",
"CAP_SYS_RAWIO",
"CAP_SYS_ADMIN",
"CAP_LINUX_IMMUTABLE",
"CAP_SYS_BOOT",
"CAP_SYS_NICE",
"CAP_SYS_PACCT",
"CAP_SYS_TTY_CONFIG",
"CAP_SYS_TIME",
"CAP_WAKE_ALARM",
"CAP_AUDIT_READ",
"CAP_AUDIT_CONTROL",
"CAP_SYS_RESOURCE",
"CAP_BLOCK_SUSPEND",
"CAP_IPC_LOCK",
"CAP_IPC_OWNER",
"CAP_LEASE",
"CAP_NET_ADMIN",
"CAP_NET_BROADCAST",
}
for _, cap := range addCaps {
s.Process.Capabilities.Bounding = append(s.Process.Capabilities.Bounding, cap)
s.Process.Capabilities.Ambient = append(s.Process.Capabilities.Ambient, cap)
s.Process.Capabilities.Effective = append(s.Process.Capabilities.Effective, cap)
s.Process.Capabilities.Inheritable = append(s.Process.Capabilities.Inheritable, cap)
s.Process.Capabilities.Permitted = append(s.Process.Capabilities.Permitted, cap)
}
s.Linux.ReadonlyPaths = []string{}
s.Linux.MaskedPaths = []string{}
s.Process.ApparmorProfile = ""
return nil
}
} | [
"func",
"WithInsecureSpec",
"(",
")",
"oci",
".",
"SpecOpts",
"{",
"return",
"func",
"(",
"_",
"context",
".",
"Context",
",",
"_",
"oci",
".",
"Client",
",",
"_",
"*",
"containers",
".",
"Container",
",",
"s",
"*",
"specs",
".",
"Spec",
")",
"error"... | // WithInsecureSpec sets spec with All capability. | [
"WithInsecureSpec",
"sets",
"spec",
"with",
"All",
"capability",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/entitlements/security_linux.go#L12-L67 |
161,789 | moby/buildkit | cmd/buildkitd/main.go | groupToGid | func groupToGid(group string) (int, error) {
if group == "" {
return os.Getgid(), nil
}
var (
err error
id int
)
// Try and parse as a number, if the error is ErrSyntax
// (i.e. its not a number) then we carry on and try it as a
// name.
if id, err = strconv.Atoi(group); err == nil {
return id, nil
} else if err.(*strconv.NumError).Err != strconv.ErrSyntax {
return 0, err
}
ginfo, err := user.LookupGroup(group)
if err != nil {
return 0, err
}
group = ginfo.Gid
if id, err = strconv.Atoi(group); err != nil {
return 0, err
}
return id, nil
} | go | func groupToGid(group string) (int, error) {
if group == "" {
return os.Getgid(), nil
}
var (
err error
id int
)
// Try and parse as a number, if the error is ErrSyntax
// (i.e. its not a number) then we carry on and try it as a
// name.
if id, err = strconv.Atoi(group); err == nil {
return id, nil
} else if err.(*strconv.NumError).Err != strconv.ErrSyntax {
return 0, err
}
ginfo, err := user.LookupGroup(group)
if err != nil {
return 0, err
}
group = ginfo.Gid
if id, err = strconv.Atoi(group); err != nil {
return 0, err
}
return id, nil
} | [
"func",
"groupToGid",
"(",
"group",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"group",
"==",
"\"",
"\"",
"{",
"return",
"os",
".",
"Getgid",
"(",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"var",
"(",
"err",
"error",
"\n",
"id",
"int",
... | // Convert a string containing either a group name or a stringified gid into a numeric id) | [
"Convert",
"a",
"string",
"containing",
"either",
"a",
"group",
"name",
"or",
"a",
"stringified",
"gid",
"into",
"a",
"numeric",
"id",
")"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/cmd/buildkitd/main.go#L419-L449 |
161,790 | moby/buildkit | session/content/attachable.go | NewAttachable | func NewAttachable(stores map[string]content.Store) session.Attachable {
store := &attachableContentStore{stores: stores}
service := contentserver.New(store)
a := attachable{
service: service,
}
return &a
} | go | func NewAttachable(stores map[string]content.Store) session.Attachable {
store := &attachableContentStore{stores: stores}
service := contentserver.New(store)
a := attachable{
service: service,
}
return &a
} | [
"func",
"NewAttachable",
"(",
"stores",
"map",
"[",
"string",
"]",
"content",
".",
"Store",
")",
"session",
".",
"Attachable",
"{",
"store",
":=",
"&",
"attachableContentStore",
"{",
"stores",
":",
"stores",
"}",
"\n",
"service",
":=",
"contentserver",
".",
... | // NewAttachable creates session.Attachable from aggregated stores.
// A key of the store map is an ID string that is used for choosing underlying store. | [
"NewAttachable",
"creates",
"session",
".",
"Attachable",
"from",
"aggregated",
"stores",
".",
"A",
"key",
"of",
"the",
"store",
"map",
"is",
"an",
"ID",
"string",
"that",
"is",
"used",
"for",
"choosing",
"underlying",
"store",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/session/content/attachable.go#L121-L128 |
161,791 | moby/buildkit | util/contentutil/multiprovider.go | NewMultiProvider | func NewMultiProvider(base content.Provider) *MultiProvider {
return &MultiProvider{
base: base,
sub: map[digest.Digest]content.Provider{},
}
} | go | func NewMultiProvider(base content.Provider) *MultiProvider {
return &MultiProvider{
base: base,
sub: map[digest.Digest]content.Provider{},
}
} | [
"func",
"NewMultiProvider",
"(",
"base",
"content",
".",
"Provider",
")",
"*",
"MultiProvider",
"{",
"return",
"&",
"MultiProvider",
"{",
"base",
":",
"base",
",",
"sub",
":",
"map",
"[",
"digest",
".",
"Digest",
"]",
"content",
".",
"Provider",
"{",
"}"... | // NewMultiProvider creates a new mutable provider with a base provider | [
"NewMultiProvider",
"creates",
"a",
"new",
"mutable",
"provider",
"with",
"a",
"base",
"provider"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/contentutil/multiprovider.go#L15-L20 |
161,792 | moby/buildkit | util/contentutil/multiprovider.go | ReaderAt | func (mp *MultiProvider) ReaderAt(ctx context.Context, desc ocispec.Descriptor) (content.ReaderAt, error) {
mp.mu.RLock()
if p, ok := mp.sub[desc.Digest]; ok {
mp.mu.RUnlock()
return p.ReaderAt(ctx, desc)
}
mp.mu.RUnlock()
if mp.base == nil {
return nil, errors.Wrapf(errdefs.ErrNotFound, "content %v", desc.Digest)
}
return mp.base.ReaderAt(ctx, desc)
} | go | func (mp *MultiProvider) ReaderAt(ctx context.Context, desc ocispec.Descriptor) (content.ReaderAt, error) {
mp.mu.RLock()
if p, ok := mp.sub[desc.Digest]; ok {
mp.mu.RUnlock()
return p.ReaderAt(ctx, desc)
}
mp.mu.RUnlock()
if mp.base == nil {
return nil, errors.Wrapf(errdefs.ErrNotFound, "content %v", desc.Digest)
}
return mp.base.ReaderAt(ctx, desc)
} | [
"func",
"(",
"mp",
"*",
"MultiProvider",
")",
"ReaderAt",
"(",
"ctx",
"context",
".",
"Context",
",",
"desc",
"ocispec",
".",
"Descriptor",
")",
"(",
"content",
".",
"ReaderAt",
",",
"error",
")",
"{",
"mp",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
... | // ReaderAt returns a content.ReaderAt | [
"ReaderAt",
"returns",
"a",
"content",
".",
"ReaderAt"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/contentutil/multiprovider.go#L30-L41 |
161,793 | moby/buildkit | util/contentutil/multiprovider.go | Add | func (mp *MultiProvider) Add(dgst digest.Digest, p content.Provider) {
mp.mu.Lock()
defer mp.mu.Unlock()
mp.sub[dgst] = p
} | go | func (mp *MultiProvider) Add(dgst digest.Digest, p content.Provider) {
mp.mu.Lock()
defer mp.mu.Unlock()
mp.sub[dgst] = p
} | [
"func",
"(",
"mp",
"*",
"MultiProvider",
")",
"Add",
"(",
"dgst",
"digest",
".",
"Digest",
",",
"p",
"content",
".",
"Provider",
")",
"{",
"mp",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mp",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"m... | // Add adds a new child provider for a specific digest | [
"Add",
"adds",
"a",
"new",
"child",
"provider",
"for",
"a",
"specific",
"digest"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/contentutil/multiprovider.go#L44-L48 |
161,794 | moby/buildkit | cache/remotecache/local/local.go | ResolveCacheExporterFunc | func ResolveCacheExporterFunc(sm *session.Manager) remotecache.ResolveCacheExporterFunc {
return func(ctx context.Context, attrs map[string]string) (remotecache.Exporter, error) {
store := attrs[attrDest]
if store == "" {
return nil, errors.New("local cache exporter requires dest")
}
csID := contentStoreIDPrefix + store
cs, err := getContentStore(ctx, sm, csID)
if err != nil {
return nil, err
}
return remotecache.NewExporter(cs), nil
}
} | go | func ResolveCacheExporterFunc(sm *session.Manager) remotecache.ResolveCacheExporterFunc {
return func(ctx context.Context, attrs map[string]string) (remotecache.Exporter, error) {
store := attrs[attrDest]
if store == "" {
return nil, errors.New("local cache exporter requires dest")
}
csID := contentStoreIDPrefix + store
cs, err := getContentStore(ctx, sm, csID)
if err != nil {
return nil, err
}
return remotecache.NewExporter(cs), nil
}
} | [
"func",
"ResolveCacheExporterFunc",
"(",
"sm",
"*",
"session",
".",
"Manager",
")",
"remotecache",
".",
"ResolveCacheExporterFunc",
"{",
"return",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"attrs",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"re... | // ResolveCacheExporterFunc for "local" cache exporter. | [
"ResolveCacheExporterFunc",
"for",
"local",
"cache",
"exporter",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/cache/remotecache/local/local.go#L24-L37 |
161,795 | moby/buildkit | cache/remotecache/local/local.go | ResolveCacheImporterFunc | func ResolveCacheImporterFunc(sm *session.Manager) remotecache.ResolveCacheImporterFunc {
return func(ctx context.Context, attrs map[string]string) (remotecache.Importer, specs.Descriptor, error) {
dgstStr := attrs[attrDigest]
if dgstStr == "" {
return nil, specs.Descriptor{}, errors.New("local cache importer requires explicit digest")
}
dgst := digest.Digest(dgstStr)
store := attrs[attrSrc]
if store == "" {
return nil, specs.Descriptor{}, errors.New("local cache importer requires src")
}
csID := contentStoreIDPrefix + store
cs, err := getContentStore(ctx, sm, csID)
if err != nil {
return nil, specs.Descriptor{}, err
}
info, err := cs.Info(ctx, dgst)
if err != nil {
return nil, specs.Descriptor{}, err
}
desc := specs.Descriptor{
// MediaType is typically MediaTypeDockerSchema2ManifestList,
// but we leave it empty until we get correct support for local index.json
Digest: dgst,
Size: info.Size,
}
return remotecache.NewImporter(cs), desc, nil
}
} | go | func ResolveCacheImporterFunc(sm *session.Manager) remotecache.ResolveCacheImporterFunc {
return func(ctx context.Context, attrs map[string]string) (remotecache.Importer, specs.Descriptor, error) {
dgstStr := attrs[attrDigest]
if dgstStr == "" {
return nil, specs.Descriptor{}, errors.New("local cache importer requires explicit digest")
}
dgst := digest.Digest(dgstStr)
store := attrs[attrSrc]
if store == "" {
return nil, specs.Descriptor{}, errors.New("local cache importer requires src")
}
csID := contentStoreIDPrefix + store
cs, err := getContentStore(ctx, sm, csID)
if err != nil {
return nil, specs.Descriptor{}, err
}
info, err := cs.Info(ctx, dgst)
if err != nil {
return nil, specs.Descriptor{}, err
}
desc := specs.Descriptor{
// MediaType is typically MediaTypeDockerSchema2ManifestList,
// but we leave it empty until we get correct support for local index.json
Digest: dgst,
Size: info.Size,
}
return remotecache.NewImporter(cs), desc, nil
}
} | [
"func",
"ResolveCacheImporterFunc",
"(",
"sm",
"*",
"session",
".",
"Manager",
")",
"remotecache",
".",
"ResolveCacheImporterFunc",
"{",
"return",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"attrs",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"re... | // ResolveCacheImporterFunc for "local" cache importer. | [
"ResolveCacheImporterFunc",
"for",
"local",
"cache",
"importer",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/cache/remotecache/local/local.go#L40-L68 |
161,796 | moby/buildkit | util/appcontext/appcontext.go | Context | func Context() context.Context {
appContextOnce.Do(func() {
signals := make(chan os.Signal, 2048)
signal.Notify(signals, terminationSignals...)
const exitLimit = 3
retries := 0
ctx, cancel := context.WithCancel(context.Background())
appContextCache = ctx
go func() {
for {
<-signals
cancel()
retries++
if retries >= exitLimit {
logrus.Errorf("got %d SIGTERM/SIGINTs, forcing shutdown", retries)
os.Exit(1)
}
}
}()
})
return appContextCache
} | go | func Context() context.Context {
appContextOnce.Do(func() {
signals := make(chan os.Signal, 2048)
signal.Notify(signals, terminationSignals...)
const exitLimit = 3
retries := 0
ctx, cancel := context.WithCancel(context.Background())
appContextCache = ctx
go func() {
for {
<-signals
cancel()
retries++
if retries >= exitLimit {
logrus.Errorf("got %d SIGTERM/SIGINTs, forcing shutdown", retries)
os.Exit(1)
}
}
}()
})
return appContextCache
} | [
"func",
"Context",
"(",
")",
"context",
".",
"Context",
"{",
"appContextOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"signals",
":=",
"make",
"(",
"chan",
"os",
".",
"Signal",
",",
"2048",
")",
"\n",
"signal",
".",
"Notify",
"(",
"signals",
",",
"... | // Context returns a static context that reacts to termination signals of the
// running process. Useful in CLI tools. | [
"Context",
"returns",
"a",
"static",
"context",
"that",
"reacts",
"to",
"termination",
"signals",
"of",
"the",
"running",
"process",
".",
"Useful",
"in",
"CLI",
"tools",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/util/appcontext/appcontext.go#L17-L41 |
161,797 | moby/buildkit | executor/containerdexecutor/executor.go | New | func New(client *containerd.Client, root, cgroup string, networkProviders map[pb.NetMode]network.Provider) executor.Executor {
// clean up old hosts/resolv.conf file. ignore errors
os.RemoveAll(filepath.Join(root, "hosts"))
os.RemoveAll(filepath.Join(root, "resolv.conf"))
return containerdExecutor{
client: client,
root: root,
networkProviders: networkProviders,
cgroupParent: cgroup,
}
} | go | func New(client *containerd.Client, root, cgroup string, networkProviders map[pb.NetMode]network.Provider) executor.Executor {
// clean up old hosts/resolv.conf file. ignore errors
os.RemoveAll(filepath.Join(root, "hosts"))
os.RemoveAll(filepath.Join(root, "resolv.conf"))
return containerdExecutor{
client: client,
root: root,
networkProviders: networkProviders,
cgroupParent: cgroup,
}
} | [
"func",
"New",
"(",
"client",
"*",
"containerd",
".",
"Client",
",",
"root",
",",
"cgroup",
"string",
",",
"networkProviders",
"map",
"[",
"pb",
".",
"NetMode",
"]",
"network",
".",
"Provider",
")",
"executor",
".",
"Executor",
"{",
"// clean up old hosts/re... | // New creates a new executor backed by connection to containerd API | [
"New",
"creates",
"a",
"new",
"executor",
"backed",
"by",
"connection",
"to",
"containerd",
"API"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/executor/containerdexecutor/executor.go#L34-L45 |
161,798 | moby/buildkit | frontend/dockerfile/shell/lex.go | ProcessWordWithMap | func (s *Lex) ProcessWordWithMap(word string, env map[string]string) (string, error) {
word, _, err := s.process(word, env)
return word, err
} | go | func (s *Lex) ProcessWordWithMap(word string, env map[string]string) (string, error) {
word, _, err := s.process(word, env)
return word, err
} | [
"func",
"(",
"s",
"*",
"Lex",
")",
"ProcessWordWithMap",
"(",
"word",
"string",
",",
"env",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"word",
",",
"_",
",",
"err",
":=",
"s",
".",
"process",
"(",
"word",
","... | // ProcessWordWithMap will use the 'env' list of environment variables,
// and replace any env var references in 'word'. | [
"ProcessWordWithMap",
"will",
"use",
"the",
"env",
"list",
"of",
"environment",
"variables",
"and",
"replace",
"any",
"env",
"var",
"references",
"in",
"word",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/shell/lex.go#L52-L55 |
161,799 | moby/buildkit | identity/randomid.go | NewID | func NewID() string {
var p [randomIDEntropyBytes]byte
if _, err := io.ReadFull(idReader, p[:]); err != nil {
panic(fmt.Errorf("failed to read random bytes: %v", err))
}
p[0] |= 0x80 // set high bit to avoid the need for padding
return (&big.Int{}).SetBytes(p[:]).Text(randomIDBase)[1 : maxRandomIDLength+1]
} | go | func NewID() string {
var p [randomIDEntropyBytes]byte
if _, err := io.ReadFull(idReader, p[:]); err != nil {
panic(fmt.Errorf("failed to read random bytes: %v", err))
}
p[0] |= 0x80 // set high bit to avoid the need for padding
return (&big.Int{}).SetBytes(p[:]).Text(randomIDBase)[1 : maxRandomIDLength+1]
} | [
"func",
"NewID",
"(",
")",
"string",
"{",
"var",
"p",
"[",
"randomIDEntropyBytes",
"]",
"byte",
"\n\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"idReader",
",",
"p",
"[",
":",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",... | // NewID generates a new identifier for use where random identifiers with low
// collision probability are required.
//
// With the parameters in this package, the generated identifier will provide
// ~129 bits of entropy encoded with base36. Leading padding is added if the
// string is less 25 bytes. We do not intend to maintain this interface, so
// identifiers should be treated opaquely. | [
"NewID",
"generates",
"a",
"new",
"identifier",
"for",
"use",
"where",
"random",
"identifiers",
"with",
"low",
"collision",
"probability",
"are",
"required",
".",
"With",
"the",
"parameters",
"in",
"this",
"package",
"the",
"generated",
"identifier",
"will",
"pr... | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/identity/randomid.go#L44-L53 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.