Skip to content

Instantly share code, notes, and snippets.

@KEINOS
Last active October 27, 2022 23:32
Show Gist options
  • Select an option

  • Save KEINOS/fc5ebb0b3f2bae6281f1286ae6d3a6ba to your computer and use it in GitHub Desktop.

Select an option

Save KEINOS/fc5ebb0b3f2bae6281f1286ae6d3a6ba to your computer and use it in GitHub Desktop.
[IPFS] Installing IPFS (Kubo/go-ipfs) on Alpine Linux (not on Docker container)

Follow the steps in this document if you get "No such file or directory" or "not found" error by downloding from the pre-compiled official releses.

Install IPFS (Kubo) on Alpine Linux (NOT on Docker)

This document describes how to install and update IPFS (Kubo, fka go-ipfs) on Alpine Linux and not on Docker container image.

We have found that it is more stable to build from source and update with the gup command.

  • Tested on: Alpine 3.16

TL; DR

# Setup
cd ~
mkdir -p /usr/local/go/bin
mkdir -p ~/go
ln -s /usr/local/go/bin ~/go/bin
echo 'export GOPATH="$(go env GOPATH)"' >> /etc/profile
echo 'export PATH="${PATH}:/usr/local/go/bin"' >> /etc/profile
echo 'export PATH="${PATH}:${GOPATH}/bin"' >> /etc/profile
apk add --no-cache alpine-sdk build-base go
reboot
# Install updater written in Go
go install github.com/nao1215/gup@latest

# Install kubo (the ipfs command written in Go)
go install github.com/ipfs/kubo/cmd/ipfs@latest

# [Optional](Requires Go 1.19)
go install github.com/ipfs-cluster/ipfs-cluster/cmd/ipfs-cluster-service@latest
go install github.com/ipfs-cluster/ipfs-cluster/cmd/ipfs-cluster-ctl@latest
# Check updates of the packages installed by `go install`
gup check

# Update/upgrade all packages installed by `go install`
gup update
# WIP
#!/bin/sh
USER_IPFS='ipfs'
PATH_DIR_IPFS="${HOME}/ipfs"
PATH_DIR_IPNS="${HOME}/ipns"
# Create service user
useradd -d /srv/ipfs -m -r $USER_IPFS
su - $USER_IPFS
# Initialize IPFS
ipfs init
# Create dirs
mkdir -m 2770 $PATH_DIR_IPFS
mkdir -m 2770 $PATH_DIR_IPNS
# Configure
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
ipfs config Mounts.IPFS $PATH_DIR_IPFS
ipfs config Mounts.IPNS $PATH_DIR_IPNS
# Create OpenRC init script
cat << 'EOF' > /etc/init.d/ipfs
#!/sbin/openrc-run
# Distributed under the terms of the GNU General Public License v2
command=/srv/ipfs/.go/bin/ipfs
name="ipfs"
description="InterPlanetary FileSystem"
pidfile=${pidfile:-/run/ipfs.pid}
user=${user:-ipfs}
group=${group:-ipfs}
app_path='/srv/ipfs'
depend() {
need net
use logger
}
start() {
ebegin "Starting ipfs"
start-stop-daemon -S -b -u $user:$group -d $app_path -p $pidfile -m -n $name -x $command -- daemon --migrate &>> /var/log/ipfs.log
eend $?
}
stop() {
ebegin "Stopping ipfs"
start-stop-daemon -K -u $user:$group -d $app_path -p $pidfile -n $name -x $command -- shutdown &>> /var/log/ipfs.log
eend $?
}
EOF
### enable and start
rc-update add ipfs
rc-service start ipfs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment