Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipfs: fix IPFS_PATH isn't recognized #1082

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/containerd-stargz-grpc/ipfs/resolvehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"crypto/sha256"
"fmt"
"io"
"os"

"github.com/containerd/stargz-snapshotter/fs/remote"
"github.com/containerd/stargz-snapshotter/ipfs"
Expand All @@ -35,8 +36,12 @@ func (r *ResolveHandler) Handle(ctx context.Context, desc ocispec.Descriptor) (r
if err != nil {
return nil, 0, err
}
var ipath string
if idir := os.Getenv("IPFS_PATH"); idir != "" {
ipath = idir
}
// HTTP is only supported as of now. We can add https support here if needed (e.g. for connecting to it via proxy, etc)
iurl, err := ipfsclient.GetIPFSAPIAddress("", "http")
iurl, err := ipfsclient.GetIPFSAPIAddress(ipath, "http")
if err != nil {
return nil, 0, err
}
Expand Down
4 changes: 4 additions & 0 deletions ipfs/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"fmt"
"strings"
"os"

"github.com/containerd/containerd"
"github.com/containerd/containerd/content"
Expand All @@ -47,6 +48,9 @@ func PushWithIPFSPath(ctx context.Context, client *containerd.Client, ref string
return "", err
}
var ipath string
if idir := os.Getenv("IPFS_PATH"); idir != "" {
ipath = idir
}
if ipfsPath != nil {
ipath = *ipfsPath
}
Expand Down
10 changes: 9 additions & 1 deletion ipfs/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"io"
"path"
"os"

"github.com/containerd/containerd/remotes"
ipfsclient "github.com/containerd/stargz-snapshotter/ipfs/client"
Expand All @@ -46,8 +47,15 @@ func NewResolver(options ResolverOptions) (remotes.Resolver, error) {
if s != "ipfs" && s != "ipns" {
return nil, fmt.Errorf("unsupported scheme %q", s)
}
var ipath string
if idir := os.Getenv("IPFS_PATH"); idir != "" {
ipath = idir
}
if options.IPFSPath != "" {
ipath = options.IPFSPath
}
// HTTP is only supported as of now. We can add https support here if needed (e.g. for connecting to it via proxy, etc)
iurl, err := ipfsclient.GetIPFSAPIAddress(options.IPFSPath, "http")
iurl, err := ipfsclient.GetIPFSAPIAddress(ipath, "http")
if err != nil {
return nil, fmt.Errorf("failed to get IPFS URL from ipfs path")
}
Expand Down
3 changes: 3 additions & 0 deletions script/integration/containerd/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ if [ "${BUILTIN_SNAPSHOTTER}" != "true" ] ; then
# Tests with IPFS if standalone snapshotter
echo "Testing with IPFS..."

export IPFS_PATH="/tmp/ipfs"
mkdir -p "${IPFS_PATH}"

ipfs init
ipfs daemon --offline &
retry curl -X POST localhost:5001/api/v0/version >/dev/null 2>&1 # wait for up
Expand Down