Skip to content

Commit c70e8e6

Browse files
authored
Merge pull request #6423 from jsternberg/v0.26.3-picks
[v0.26] cherry-picks for v0.26.3
2 parents be1f38e + 92d657f commit c70e8e6

8 files changed

Lines changed: 166 additions & 57 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ ARG NYDUS_VERSION
316316
ARG TARGETOS
317317
ARG TARGETARCH
318318
SHELL ["/bin/bash", "-c"]
319-
RUN wget https://github.com/dragonflyoss/image-service/releases/download/$NYDUS_VERSION/nydus-static-$NYDUS_VERSION-$TARGETOS-$TARGETARCH.tgz
319+
RUN wget https://github.com/dragonflyoss/nydus/releases/download/$NYDUS_VERSION/nydus-static-$NYDUS_VERSION-$TARGETOS-$TARGETARCH.tgz
320320
RUN mkdir -p /out/nydus-static && tar xzvf nydus-static-$NYDUS_VERSION-$TARGETOS-$TARGETARCH.tgz -C /out
321321

322322
FROM gobuild-base AS gotestsum

client/policy_test.go

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ func testSourcePolicyParallelSession(t *testing.T, sb integration.Sandbox) {
299299

300300
func testSourcePolicySignedCommit(t *testing.T, sb integration.Sandbox) {
301301
requiresLinux(t)
302-
c, err := New(sb.Context(), sb.Address())
302+
ctx := sb.Context()
303+
c, err := New(ctx, sb.Address())
303304
require.NoError(t, err)
304305
defer c.Close()
305306

@@ -532,4 +533,101 @@ func testSourcePolicySignedCommit(t *testing.T, sb integration.Sandbox) {
532533
require.ErrorContains(t, err, tt.expectedErr, "test case %q failed", tt.name)
533534
})
534535
}
536+
537+
// session policy based test cases
538+
539+
type tcase struct {
540+
name string
541+
state func() llb.State
542+
callbacks []policysession.PolicyCallback
543+
expectedError string
544+
}
545+
546+
tcases := []tcase{
547+
{
548+
name: "gitchecksum",
549+
state: func() llb.State { return llb.Git(server.URL+"/.git", "", llb.GitRef("v2.0")) },
550+
callbacks: []policysession.PolicyCallback{
551+
func(ctx context.Context, req *policysession.CheckPolicyRequest) (*policysession.DecisionResponse, *pb.ResolveSourceMetaRequest, error) {
552+
require.Equal(t, gitURL+"#v2.0", req.Source.Source.Identifier)
553+
require.Nil(t, req.Source.Git)
554+
return nil, &pb.ResolveSourceMetaRequest{
555+
Source: req.Source.Source,
556+
Platform: req.Platform,
557+
}, nil
558+
},
559+
func(ctx context.Context, req *policysession.CheckPolicyRequest) (*policysession.DecisionResponse, *pb.ResolveSourceMetaRequest, error) {
560+
require.Equal(t, gitURL+"#v2.0", req.Source.Source.Identifier)
561+
require.NotNil(t, req.Source.Git)
562+
require.Len(t, req.Source.Git.Checksum, 40)
563+
require.Len(t, req.Source.Git.CommitChecksum, 40)
564+
require.NotEqual(t, req.Source.Git.Checksum, req.Source.Git.CommitChecksum)
565+
require.Nil(t, req.Source.Git.CommitObject)
566+
return &policysession.DecisionResponse{
567+
Action: sourcepolicypb.PolicyAction_ALLOW,
568+
}, nil, nil
569+
},
570+
},
571+
},
572+
{
573+
name: "gitobjects",
574+
state: func() llb.State { return llb.Git(server.URL+"/.git", "", llb.GitRef("v2.0")) },
575+
callbacks: []policysession.PolicyCallback{
576+
func(ctx context.Context, req *policysession.CheckPolicyRequest) (*policysession.DecisionResponse, *pb.ResolveSourceMetaRequest, error) {
577+
require.Equal(t, gitURL+"#v2.0", req.Source.Source.Identifier)
578+
require.Nil(t, req.Source.Git)
579+
return nil, &pb.ResolveSourceMetaRequest{
580+
Source: req.Source.Source,
581+
Platform: req.Platform,
582+
Git: &pb.ResolveSourceGitRequest{
583+
ReturnObject: true,
584+
},
585+
}, nil
586+
},
587+
func(ctx context.Context, req *policysession.CheckPolicyRequest) (*policysession.DecisionResponse, *pb.ResolveSourceMetaRequest, error) {
588+
require.Equal(t, gitURL+"#v2.0", req.Source.Source.Identifier)
589+
require.NotNil(t, req.Source.Git)
590+
require.Len(t, req.Source.Git.Checksum, 40)
591+
require.Len(t, req.Source.Git.CommitChecksum, 40)
592+
require.NotEqual(t, req.Source.Git.Checksum, req.Source.Git.CommitChecksum)
593+
require.NotNil(t, req.Source.Git.CommitObject)
594+
require.Greater(t, len(req.Source.Git.CommitObject), 50)
595+
return &policysession.DecisionResponse{
596+
Action: sourcepolicypb.PolicyAction_ALLOW,
597+
}, nil, nil
598+
},
599+
},
600+
},
601+
}
602+
603+
for _, tc := range tcases {
604+
t.Run(tc.name, func(t *testing.T) {
605+
st := tc.state()
606+
def, err := st.Marshal(ctx)
607+
require.NoError(t, err)
608+
609+
callCounter := 0
610+
611+
p := policysession.NewPolicyProvider(func(ctx context.Context, req *policysession.CheckPolicyRequest) (*policysession.DecisionResponse, *pb.ResolveSourceMetaRequest, error) {
612+
if callCounter >= len(tc.callbacks) {
613+
return nil, nil, errors.Errorf("too many calls to policy callback %d", callCounter)
614+
}
615+
cb := tc.callbacks[callCounter]
616+
callCounter++
617+
return cb(ctx, req)
618+
})
619+
620+
_, err = c.Solve(ctx, def, SolveOpt{
621+
SourcePolicyProvider: p,
622+
}, nil)
623+
if tc.expectedError != "" {
624+
require.Error(t, err)
625+
require.Contains(t, err.Error(), tc.expectedError)
626+
return
627+
}
628+
require.NoError(t, err)
629+
630+
require.Equal(t, len(tc.callbacks), callCounter, "not all policy callbacks were called")
631+
})
632+
}
535633
}

docs/nydus.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Nydus image formats
22

3-
Nydus is an OCI/Docker-compatible accelerated image format provided by the Dragonfly [image-service](https://github.com/dragonflyoss/image-service) project, which offers the ability to pull image data on-demand, without waiting for the entire image pull to complete and then start the container. It has been put in production usage and shown vast improvements to significantly reduce the overhead costs on time, network, disk IO of pulling image or starting container.
3+
Nydus is an OCI/Docker-compatible accelerated image format provided by the Dragonfly [image-service](https://github.com/dragonflyoss/nydus) project, which offers the ability to pull image data on-demand, without waiting for the entire image pull to complete and then start the container. It has been put in production usage and shown vast improvements to significantly reduce the overhead costs on time, network, disk IO of pulling image or starting container.
44

55
Nydus image can be flexibly configured as a FUSE-based user-space filesystem or in-kernel [EROFS](https://www.kernel.org/doc/html/latest/filesystems/erofs.html) (from Linux kernel v5.16) with nydus daemon in user-space, integrating with VM-based container runtime like [KataContainers](https://katacontainers.io/) is much easier.
66

@@ -16,7 +16,7 @@ go build -tags=nydus -o ./bin/buildkitd ./cmd/buildkitd
1616

1717
### Building Nydus with BuildKit
1818

19-
Download `nydus-image` binary from [nydus release page](https://github.com/dragonflyoss/image-service/releases) (require v2.1.6 or higher), then put the `nydus-image` binary path into $PATH or specifying it on `NYDUS_BUILDER` environment variable for buildkitd:
19+
Download `nydus-image` binary from [nydus release page](https://github.com/dragonflyoss/nydus/releases) (require v2.1.6 or higher), then put the `nydus-image` binary path into $PATH or specifying it on `NYDUS_BUILDER` environment variable for buildkitd:
2020

2121
```
2222
env NYDUS_BUILDER=/path/to/nydus-image buildkitd ...
@@ -33,7 +33,7 @@ buildctl build ... \
3333

3434
### Known limitations
3535

36-
- The export of Nydus image and runtime (e.g. [docker](https://github.com/dragonflyoss/image-service/tree/master/contrib/docker-nydus-graphdriver), [containerd](https://github.com/containerd/nydus-snapshotter), etc.) is currently only supported on linux platform.
36+
- The export of Nydus image and runtime (e.g. [docker](https://github.com/nydusaccelerator/docker-nydus-graphdriver), [containerd](https://github.com/containerd/nydus-snapshotter), etc.) is currently only supported on linux platform.
3737
- Nydus image layers cannot be mixed with other compression types in the same image, so the `force-compression=true` option must be enabled when exporting both Nydus and other compression types.
3838
- Specifying a Nydus image as a base image in a Dockerfile is supported, but it does not currently support lazy pulling.
3939
- Since exported Nydus image will always have one more metadata layer than images in other compression types, Nydus image cannot be exported/imported as cache.
@@ -42,6 +42,6 @@ buildctl build ... \
4242

4343
Pre-converted nydus images are available at [`ghcr.io/dragonflyoss/image-service` repository](https://github.com/orgs/dragonflyoss/packages?ecosystem=container) (mainly for testing purpose).
4444

45-
[`Nydusify`](https://github.com/dragonflyoss/image-service/blob/master/docs/nydusify.md) The Nydusify CLI tool pulls & converts an OCIv1 image into a nydus image, and pushes nydus image to registry.
45+
[`Nydusify`](https://github.com/dragonflyoss/nydus/blob/master/docs/nydusify.md) The Nydusify CLI tool pulls & converts an OCIv1 image into a nydus image, and pushes nydus image to registry.
4646

47-
[`Harbor Acceld`](https://github.com/goharbor/acceleration-service) Harbor acceld provides a general service to convert OCIv1 image to acceleration image like [Nydus](https://github.com/dragonflyoss/image-service) and [eStargz](https://github.com/containerd/stargz-snapshotter) etc.
47+
[`Harbor Acceld`](https://github.com/goharbor/acceleration-service) Harbor acceld provides a general service to convert OCIv1 image to acceleration image like [Nydus](https://github.com/dragonflyoss/nydus) and [eStargz](https://github.com/containerd/stargz-snapshotter) etc.

frontend/gateway/gateway.go

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -653,43 +653,7 @@ func (lbf *llbBridgeForwarder) ResolveSourceMeta(ctx context.Context, req *pb.Re
653653
if err != nil {
654654
return nil, err
655655
}
656-
657-
r := &pb.ResolveSourceMetaResponse{
658-
Source: resp.Op,
659-
}
660-
661-
if resp.Image != nil {
662-
r.Image = &pb.ResolveSourceImageResponse{
663-
Digest: string(resp.Image.Digest),
664-
Config: resp.Image.Config,
665-
}
666-
if resp.Image.AttestationChain != nil {
667-
r.Image.AttestationChain = toPBAttestationChain(resp.Image.AttestationChain)
668-
}
669-
}
670-
if resp.Git != nil {
671-
r.Git = &pb.ResolveSourceGitResponse{
672-
Checksum: resp.Git.Checksum,
673-
Ref: resp.Git.Ref,
674-
CommitChecksum: resp.Git.CommitChecksum,
675-
CommitObject: resp.Git.CommitObject,
676-
TagObject: resp.Git.TagObject,
677-
}
678-
}
679-
if resp.HTTP != nil {
680-
var lastModified *timestamp.Timestamp
681-
if resp.HTTP.LastModified != nil {
682-
lastModified = &timestamp.Timestamp{
683-
Seconds: resp.HTTP.LastModified.Unix(),
684-
}
685-
}
686-
r.HTTP = &pb.ResolveSourceHTTPResponse{
687-
Checksum: resp.HTTP.Digest.String(),
688-
Filename: resp.HTTP.Filename,
689-
LastModified: lastModified,
690-
}
691-
}
692-
return r, nil
656+
return ToPBResolveSourceMetaResponse(resp), nil
693657
}
694658

695659
func (lbf *llbBridgeForwarder) ResolveImageConfig(ctx context.Context, req *pb.ResolveImageConfigRequest) (*pb.ResolveImageConfigResponse, error) {
@@ -1705,6 +1669,45 @@ func getCaps(label string) map[string]struct{} {
17051669
return out
17061670
}
17071671

1672+
func ToPBResolveSourceMetaResponse(in *sourceresolver.MetaResponse) *pb.ResolveSourceMetaResponse {
1673+
r := &pb.ResolveSourceMetaResponse{
1674+
Source: in.Op,
1675+
}
1676+
1677+
if in.Image != nil {
1678+
r.Image = &pb.ResolveSourceImageResponse{
1679+
Digest: string(in.Image.Digest),
1680+
Config: in.Image.Config,
1681+
}
1682+
if in.Image.AttestationChain != nil {
1683+
r.Image.AttestationChain = toPBAttestationChain(in.Image.AttestationChain)
1684+
}
1685+
}
1686+
if in.Git != nil {
1687+
r.Git = &pb.ResolveSourceGitResponse{
1688+
Checksum: in.Git.Checksum,
1689+
Ref: in.Git.Ref,
1690+
CommitChecksum: in.Git.CommitChecksum,
1691+
CommitObject: in.Git.CommitObject,
1692+
TagObject: in.Git.TagObject,
1693+
}
1694+
}
1695+
if in.HTTP != nil {
1696+
var lastModified *timestamp.Timestamp
1697+
if in.HTTP.LastModified != nil {
1698+
lastModified = &timestamp.Timestamp{
1699+
Seconds: in.HTTP.LastModified.Unix(),
1700+
}
1701+
}
1702+
r.HTTP = &pb.ResolveSourceHTTPResponse{
1703+
Checksum: in.HTTP.Digest.String(),
1704+
Filename: in.HTTP.Filename,
1705+
LastModified: lastModified,
1706+
}
1707+
}
1708+
return r
1709+
}
1710+
17081711
func toPBAttestationChain(ac *sourceresolver.AttestationChain) *pb.AttestationChain {
17091712
if ac == nil {
17101713
return nil

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require (
3232
github.com/containerd/stargz-snapshotter v0.17.0
3333
github.com/containerd/stargz-snapshotter/estargz v0.17.0
3434
github.com/containerd/typeurl/v2 v2.2.3
35-
github.com/containernetworking/plugins v1.8.0
35+
github.com/containernetworking/plugins v1.9.0
3636
github.com/coreos/go-systemd/v22 v22.6.0
3737
github.com/distribution/reference v0.6.0
3838
github.com/docker/cli v28.5.0+incompatible

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ github.com/containerd/typeurl/v2 v2.2.3 h1:yNA/94zxWdvYACdYO8zofhrTVuQY73fFU1y++
136136
github.com/containerd/typeurl/v2 v2.2.3/go.mod h1:95ljDnPfD3bAbDJRugOiShd/DlAAsxGtUBhJxIn7SCk=
137137
github.com/containernetworking/cni v1.3.0 h1:v6EpN8RznAZj9765HhXQrtXgX+ECGebEYEmnuFjskwo=
138138
github.com/containernetworking/cni v1.3.0/go.mod h1:Bs8glZjjFfGPHMw6hQu82RUgEPNGEaBb9KS5KtNMnJ4=
139-
github.com/containernetworking/plugins v1.8.0 h1:WjGbV/0UQyo8A4qBsAh6GaDAtu1hevxVxsEuqtBqUFk=
140-
github.com/containernetworking/plugins v1.8.0/go.mod h1:JG3BxoJifxxHBhG3hFyxyhid7JgRVBu/wtooGEvWf1c=
139+
github.com/containernetworking/plugins v1.9.0 h1:Mg3SXBdRGkdXyFC4lcwr6u2ZB2SDeL6LC3U+QrEANuQ=
140+
github.com/containernetworking/plugins v1.9.0/go.mod h1:JG3BxoJifxxHBhG3hFyxyhid7JgRVBu/wtooGEvWf1c=
141141
github.com/coreos/go-systemd/v22 v22.6.0 h1:aGVa/v8B7hpb0TKl0MWoAavPDmHvobFe5R5zn0bCJWo=
142142
github.com/coreos/go-systemd/v22 v22.6.0/go.mod h1:iG+pp635Fo7ZmV/j14KUcmEyWF+0X7Lua8rrTWzYgWU=
143143
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=

solver/llbsolver/policy.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66

77
"github.com/moby/buildkit/client/llb/sourceresolver"
8+
"github.com/moby/buildkit/frontend/gateway"
89
gatewaypb "github.com/moby/buildkit/frontend/gateway/pb"
910
"github.com/moby/buildkit/solver/pb"
1011
"github.com/moby/buildkit/sourcepolicy"
@@ -88,19 +89,26 @@ func (p *policyEvaluator) Evaluate(ctx context.Context, op *pb.Op) (bool, error)
8889
Platform: toOCIPlatform(metareq.Platform),
8990
}
9091
}
92+
93+
if metareq.Image != nil {
94+
if op.ImageOpt == nil {
95+
op.ImageOpt = &sourceresolver.ResolveImageOpt{}
96+
}
97+
op.ImageOpt.NoConfig = metareq.Image.NoConfig
98+
op.ImageOpt.AttestationChain = metareq.Image.AttestationChain
99+
}
100+
101+
if metareq.Git != nil {
102+
op.GitOpt = &sourceresolver.ResolveGitOpt{
103+
ReturnObject: metareq.Git.ReturnObject,
104+
}
105+
}
106+
91107
resp, err := p.resolveSourceMetadata(ctx, metareq.Source, op, false)
92108
if err != nil {
93109
return false, errors.Wrap(err, "error resolving source metadata from policy request")
94110
}
95-
req.Source = &gatewaypb.ResolveSourceMetaResponse{
96-
Source: resp.Op,
97-
}
98-
if resp.Image != nil {
99-
req.Source.Image = &gatewaypb.ResolveSourceImageResponse{
100-
Digest: resp.Image.Digest.String(),
101-
Config: resp.Image.Config,
102-
}
103-
}
111+
req.Source = gateway.ToPBResolveSourceMetaResponse(resp)
104112
continue
105113
}
106114

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ github.com/containernetworking/cni/pkg/types/create
502502
github.com/containernetworking/cni/pkg/types/internal
503503
github.com/containernetworking/cni/pkg/utils
504504
github.com/containernetworking/cni/pkg/version
505-
# github.com/containernetworking/plugins v1.8.0
505+
# github.com/containernetworking/plugins v1.9.0
506506
## explicit; go 1.24.2
507507
github.com/containernetworking/plugins/pkg/ns
508508
# github.com/coreos/go-systemd/v22 v22.6.0

0 commit comments

Comments
 (0)