memory-bank/components/ipfs.md
The IPFS (InterPlanetary File System) component in Gitpod consists of two main parts: Kubo and IPFS Cluster. Kubo is the core IPFS implementation in Go, while IPFS Cluster provides pinset orchestration for IPFS. This component is primarily used by the registry-facade component to cache container image layers, improving performance and reliability of workspace image distribution.
The primary purposes of the IPFS component are:
The IPFS component consists of two main parts:
Kubo: The core IPFS implementation in Go
IPFS Cluster: A pinset orchestration layer for IPFS
Both components are packaged as Docker images that wrap the official IPFS images with additional tools like jq and, in the case of IPFS Cluster, kubectl for Kubernetes integration.
The IPFS component integrates with:
The primary use of IPFS in Gitpod is for caching container image layers:
The registry-facade component interacts with IPFS through its HTTP API:
// Store a blob in IPFS
func (store *IPFSBlobCache) Store(ctx context.Context, dgst digest.Digest, r io.ReadCloser, mediaType string) error {
// Create a file from the reader
file := files.NewReaderFile(r)
// Add the file to IPFS
path, err := store.IPFS.Unixfs().Add(ctx, file)
if err != nil {
return err
}
// Store the mapping from digest to CID in Redis
err = store.Redis.Set(ctx, dgst.String(), path.Cid().String(), 0).Err()
if err != nil {
return err
}
return nil
}
// Get a blob from IPFS
func (store *IPFSBlobCache) Get(ctx context.Context, dgst digest.Digest) (ipfsURL string, err error) {
// Get the CID from Redis
ipfsCID, err := store.Redis.Get(ctx, dgst.String()).Result()
if err != nil {
return "", err
}
return "ipfs://" + ipfsCID, nil
}
The IPFS component is configured through environment variables and configuration files:
ipfsKuboVersion variableipfsClusterVersion variableThe registry-facade component is configured to use IPFS through its configuration:
{
"ipfs": {
"enabled": true,
"ipfsAddr": "/ip4/127.0.0.1/tcp/5001"
}
}
None explicitly specified in the available code.
docker.io/ipfs/kubo: The official Kubo Docker imagedocker.io/ipfs/ipfs-cluster: The official IPFS Cluster Docker imagegithub.com/ipfs/boxo: IPFS librariesgithub.com/ipfs/kubo: Kubo IPFS implementationgithub.com/ipfs/go-cid: Content identifier librarygithub.com/multiformats/go-multiaddr: Multiaddress libraryWhen using IPFS, several security considerations should be kept in mind:
The Kubo Docker image is built from the official IPFS Kubo image with the addition of the jq tool:
FROM docker.io/ipfs/kubo:${VERSION}
COPY --from=dependencies /jq /usr/bin/jq
The IPFS Cluster Docker image is built from the official IPFS Cluster image with the addition of jq and kubectl:
FROM docker.io/ipfs/ipfs-cluster:${VERSION}
COPY --from=dependencies /jq /usr/bin/jq
COPY --from=dependencies /kubectl /usr/bin/kubectl
The registry-facade component integrates with IPFS through the IPFSBlobCache struct, which provides methods for storing and retrieving blobs from IPFS. It uses Redis to map content digests to IPFS CIDs.