diff --git a/cmd/containerd-stargz-grpc/ipfs/resolvehandler.go b/cmd/containerd-stargz-grpc/ipfs/resolvehandler.go index 22073bcae..b747ab230 100644 --- a/cmd/containerd-stargz-grpc/ipfs/resolvehandler.go +++ b/cmd/containerd-stargz-grpc/ipfs/resolvehandler.go @@ -21,6 +21,7 @@ import ( "crypto/sha256" "fmt" "io" + "os" "github.com/containerd/stargz-snapshotter/fs/remote" "github.com/containerd/stargz-snapshotter/ipfs" @@ -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 } diff --git a/ipfs/converter.go b/ipfs/converter.go index e8e9e8788..f3033e340 100644 --- a/ipfs/converter.go +++ b/ipfs/converter.go @@ -22,6 +22,7 @@ import ( "encoding/json" "fmt" "strings" + "os" "github.com/containerd/containerd" "github.com/containerd/containerd/content" @@ -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 } diff --git a/ipfs/resolver.go b/ipfs/resolver.go index b84793156..9a8b8be8f 100644 --- a/ipfs/resolver.go +++ b/ipfs/resolver.go @@ -22,6 +22,7 @@ import ( "fmt" "io" "path" + "os" "github.com/containerd/containerd/remotes" ipfsclient "github.com/containerd/stargz-snapshotter/ipfs/client" @@ -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") } diff --git a/script/integration/containerd/entrypoint.sh b/script/integration/containerd/entrypoint.sh index 3ccf1ef30..fd618990e 100755 --- a/script/integration/containerd/entrypoint.sh +++ b/script/integration/containerd/entrypoint.sh @@ -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