Skip to content

Instantly share code, notes, and snippets.

@mainiak
Last active June 29, 2023 03:27
Show Gist options
  • Save mainiak/03f202480405affca3fd80dd8f6a7008 to your computer and use it in GitHub Desktop.
Save mainiak/03f202480405affca3fd80dd8f6a7008 to your computer and use it in GitHub Desktop.
IPFS, IPNS, DNSLink, and Git demo

IPFS & Co. demo

Publish Git repository on IPFS

Get Git repository to IPFS

mkdir test
cd test

## https://gist.github.com/mainiak/5419663
git clone --mirror git@gist.github.com:5419663.git

cd 5419663.git
git update-server-info
mv objects/pack/*.pack ./

git unpack-objects < *.pack
rm -f *.pack objects/pack/*

Add Git repository to IPFS

## in 5419663.git
cd ..

#ipfs add --progress --pin=true --cid-version 1 --recursive 5419663.git
initial_cid=$(ipfs add -q --pin=true --cid-version 1 -r 5419663.git | tail -n 1 | tr -s ':blank:')
echo "# Initial CID: ${initial_cid}"

## Just to be sure
ipfs pin add -r --progress /ipfs/${initial_cid}

## Make pinned files visible in IPFS Desktop
#ipfs files cp /ipfs/bafybeigdbwtuaq4pycwqvwfdh3qmrup7omw57iggudri3ptmcmre4yt574 "/5419663.git"
ipfs files cp /ipfs/${initial_cid} "/5419663v2.git"

## Cleanup
#rm -rf 5419663.git

Outcome CID: bafybeigdbwtuaq4pycwqvwfdh3qmrup7omw57iggudri3ptmcmre4yt574

CID Info: base32 - cidv1 - dag-pb - sha2-256~256~C30DA740438FC0AD0AD8A33EE0C8D1FF732DDFA0C6A0E28DBE6C13224E627DFF (UnixFS)

Publish with IPNS (over DHT ... by default)

## Create new Peer/Node ID/key
ipfs key gen 5419663-git
peer_id=$(ipfs key  list -l | fgrep 5419663-git | cut -f1 -d' ')
echo "# Peer ID: ${peer_id}"

#> ipfs name publish --key=5419663-git /ipfs/bafybeigdbwtuaq4pycwqvwfdh3qmrup7omw57iggudri3ptmcmre4yt574
> ipfs name publish --key=5419663-git /ipfs/${initial_cid}
Published to k51qzi5uqu5dgc3bchx1ns43pwuj9mhq2d1h1dhc1wni0hc4y9yz28fkajt8xj: /ipfs/bafybeigdbwtuaq4pycwqvwfdh3qmrup7omw57iggudri3ptmcmre4yt574

libp2p-key CID Info

Notes:

  • I assume this might disappear with my IPFS node shut down (??)
    • It seems that with DHT, IPFS (Kubo) re-uploads IPNS records every 4 hours. Otherwise they would expire after 24 hours
  • ... takes a while (??)

DNSLink

Setup with your DNS provider

## 5419663-git.example.com
#5419663-git.example.com CNAME ipfs.cloudflare.com. # paid??
#5419663-git.example.com CNAME ipfs.io. # supported??
#_dnslink.5419663-git.example.com TXT "dnslink=/ipfs/bafybeigdbwtuaq4pycwqvwfdh3qmrup7omw57iggudri3ptmcmre4yt574"
_dnslink.5419663-git.example.com TXT "dnslink=/ipns/<__PEER_ID__>"

Note:

  • Should result in IPFS URL like 5419663--git-example-com.ipns.<IPFS GW> and /ipns/5419663-git.example.com.
  • You can test by putting 5419663-git.example.com into Durin app.
  • You can also try directly ifps://bafybeigdbwtuaq4pycwqvwfdh3qmrup7omw57iggudri3ptmcmre4yt574 in your browser and it should open IPFS Desktop.
  • You can also try directly ipns://k51qzi5uqu5dgc3bchx1ns43pwuj9mhq2d1h1dhc1wni0hc4y9yz28fkajt8xj in your browser and it should open IPFS Desktop.
  • You can also try directly ipns://5419663-git.example.com in your browser and it should open IPFS Desktop.

Testing Git clone from IPFS

## Doesn't work
#git clone http://5419663-git.example.com 5419663

## Ensure we have Git remote helper (IPLD)
go install github.com/ipfs-shipyard/git-remote-ipld/cmd/git-remote-ipld@latest
which git-remote-ipld

## Git clone (w/ IPLD helper) ... doesn't really work (?!)
git clone ipld://bafybeigdbwtuaq4pycwqvwfdh3qmrup7omw57iggudri3ptmcmre4yt574 5419663_ipld

## Ensure we have Git remote helper (IPFS)
go install github.com/cryptix/git-remote-ipfs@latest
which git-remote-ipfs

## Git clone (w/ IPFS helper)
git clone ipfs://ipfs/bafybeigdbwtuaq4pycwqvwfdh3qmrup7omw57iggudri3ptmcmre4yt574 5419663_ipfs

## Will NOT work
#git clone ipns://5419663-git.example.com 5419663_ipns
#git clone ipfs://ipns/5419663-git.example.com

and ultimate test ...

# edit vimrc.md
git commit -am 'changes'
#git push #nope

new_cid=$(cat 5419663_ipfs/.git/config | fgrep ipfs | cut -f5 -d '/')
echo "# New CID: ${new_cid}"

## Just to be sure
ipfs pin add -r --progress /ipfs/${new_cid}

## Update
ipfs name publish --key=5419663-git /ipfs/${new_cid}

... which worked, except DNSLink is hardcoded to specific CID, so shows old version instead of new one bafybeidj5kp6qzc4m2u7aq44nmvg46gtbsfz6alilaispjjvh2ssnw7iaa.

Not sure if we can solve that with DNSLink pointing to IPNS and then we just "git-push overwrite" the thing ??

Debug

## Show Peer IDs (used by IPNS)
ipfs key list -l

## Confirm local pins
ipfs pin ls --type=all

## Confirm DNSLink entry
dig +noall +answer TXT \_dnslink.5419663-git.example.com

## Remove CID v0 objects
ipfs pin rm --recursive QmZwbbuwPWNh9DFveTEFGnvQAz1oxkizX3J5TSta5f8k3F

Notes

  • Rewrite above steps to Go lang app/tool (??)
  • IGiS as application igis.io and as demo repository, doesn't seem to work.

See also

Docs

DNSLink

Git remote helpers

OLD school

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment