Skip to content

Commit 8a06614

Browse files
authored
Merge pull request containerd#3490 from apostasie/bug-3489-ipfs-missing-layer
Fix IPFS missing layer issue
2 parents 7f053cd + 703bd58 commit 8a06614

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

cmd/nerdctl/issues/issues_linux_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ package issues
2020

2121
import (
2222
"fmt"
23+
"os"
24+
"path/filepath"
2325
"testing"
2426

27+
"gotest.tools/v3/assert"
28+
29+
"github.com/containerd/nerdctl/v2/pkg/rootlessutil"
2530
"github.com/containerd/nerdctl/v2/pkg/testutil"
2631
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
2732
"github.com/containerd/nerdctl/v2/pkg/testutil/test"
@@ -37,6 +42,16 @@ func TestIssue3425(t *testing.T) {
3742

3843
var registry *testregistry.RegistryServer
3944

45+
var ipfsPath string
46+
if rootlessutil.IsRootless() {
47+
var err error
48+
ipfsPath, err = rootlessutil.XDGDataHome()
49+
ipfsPath = filepath.Join(ipfsPath, "ipfs")
50+
assert.NilError(t, err)
51+
} else {
52+
ipfsPath = filepath.Join(os.Getenv("HOME"), ".ipfs")
53+
}
54+
4055
testCase := &test.Case{
4156
Description: "TestIssue3425",
4257
Setup: func(data test.Data, helpers test.Helpers) {
@@ -126,6 +141,32 @@ func TestIssue3425(t *testing.T) {
126141
},
127142
Expected: test.Expects(0, nil, nil),
128143
},
144+
{
145+
Description: "with ipfs",
146+
Require: test.Require(
147+
nerdtest.Private,
148+
test.Not(test.Windows),
149+
test.Not(nerdtest.Docker),
150+
test.Binary("ipfs"),
151+
),
152+
Env: map[string]string{
153+
"IPFS_PATH": ipfsPath,
154+
},
155+
Setup: func(data test.Data, helpers test.Helpers) {
156+
helpers.Ensure("image", "pull", testutil.CommonImage)
157+
helpers.Ensure("run", "-d", "--name", data.Identifier(), testutil.CommonImage)
158+
helpers.Ensure("image", "rm", "-f", testutil.CommonImage)
159+
helpers.Ensure("image", "pull", testutil.CommonImage)
160+
},
161+
Cleanup: func(data test.Data, helpers test.Helpers) {
162+
helpers.Anyhow("rm", "-f", data.Identifier())
163+
helpers.Anyhow("rmi", "-f", data.Identifier())
164+
},
165+
Command: func(data test.Data, helpers test.Helpers) test.Command {
166+
return helpers.Command("image", "push", "ipfs://"+testutil.CommonImage)
167+
},
168+
Expected: test.Expects(0, nil, nil),
169+
},
129170
},
130171
}
131172

pkg/cmd/image/ensure.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package image
1919
import (
2020
"context"
2121
"errors"
22-
"fmt"
2322
"net/http"
2423
"os"
2524

@@ -43,7 +42,6 @@ func EnsureAllContent(ctx context.Context, client *containerd.Client, srcName st
4342
imageService := client.ImageService()
4443
img, err := imageService.Get(ctx, srcName)
4544
if err != nil {
46-
fmt.Println("Failed getting imageservice")
4745
return err
4846
}
4947

pkg/cmd/image/push.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ func Push(ctx context.Context, client *containerd.Client, rawRef string, options
6161
}
6262
log.G(ctx).Infof("pushing image %q to IPFS", ref)
6363

64+
parsedRef, err := distributionref.ParseDockerRef(ref)
65+
if err != nil {
66+
return err
67+
}
68+
69+
// Ensure all the layers are here: https://github.com/containerd/nerdctl/issues/3489
70+
err = EnsureAllContent(ctx, client, parsedRef.String(), options.GOptions)
71+
if err != nil {
72+
return err
73+
}
74+
6475
var ipfsPath string
6576
if options.IpfsAddress != "" {
6677
dir, err := os.MkdirTemp("", "apidirtmp")
@@ -78,7 +89,7 @@ func Push(ctx context.Context, client *containerd.Client, rawRef string, options
7889
if options.Estargz {
7990
layerConvert = eStargzConvertFunc()
8091
}
81-
c, err := ipfs.Push(ctx, client, ref, layerConvert, options.AllPlatforms, options.Platforms, options.IpfsEnsureImage, ipfsPath)
92+
c, err := ipfs.Push(ctx, client, parsedRef.String(), layerConvert, options.AllPlatforms, options.Platforms, options.IpfsEnsureImage, ipfsPath)
8293
if err != nil {
8394
log.G(ctx).WithError(err).Warnf("ipfs push failed")
8495
return err

pkg/ipfs/image.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
"github.com/containerd/nerdctl/v2/pkg/idutil/imagewalker"
3838
"github.com/containerd/nerdctl/v2/pkg/imgutil"
3939
"github.com/containerd/nerdctl/v2/pkg/platformutil"
40-
"github.com/containerd/nerdctl/v2/pkg/referenceutil"
4140
)
4241

4342
const ipfsPathEnv = "IPFS_PATH"
@@ -93,11 +92,7 @@ func Push(ctx context.Context, client *containerd.Client, rawRef string, layerCo
9392
log.G(ctx).WithError(err).Warnf("failed to ensure the existence of image %q", rawRef)
9493
}
9594
}
96-
ref, err := referenceutil.ParseAny(rawRef)
97-
if err != nil {
98-
return "", err
99-
}
100-
return ipfs.PushWithIPFSPath(ctx, client, ref.String(), layerConvert, platMC, &ipath)
95+
return ipfs.PushWithIPFSPath(ctx, client, rawRef, layerConvert, platMC, &ipath)
10196
}
10297

10398
// ensureContentsOfIPFSImage ensures that the entire contents of an existing IPFS image are fully downloaded to containerd.

0 commit comments

Comments
 (0)