Skip to content

Commit

Permalink
Merge pull request #1082 from ktock/ipfspathenv
Browse files Browse the repository at this point in the history
ipfs: fix IPFS_PATH isn't recognized
  • Loading branch information
ktock authored Jan 26, 2023
2 parents 60ef5c4 + b33b66b commit c391ff5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
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

0 comments on commit c391ff5

Please sign in to comment.