Skip to content

Instantly share code, notes, and snippets.

@GusAntoniassi
Last active July 3, 2024 16:35
Show Gist options
  • Save GusAntoniassi/5ad2046324d009a9aaf89b662a0ebf79 to your computer and use it in GitHub Desktop.
Save GusAntoniassi/5ad2046324d009a9aaf89b662a0ebf79 to your computer and use it in GitHub Desktop.
How to install Hashicorp Nomad on aarch64 Alpine Linux (Moto G6 / PostmarketOS)

How to install Hashicorp Nomad on aarch64 Alpine Linux (Moto G6 / PostmarketOS)

Since as of now there is no binary release for Hashicorp Nomad in aarch64, we'll have to compile it from scratch.

Install dependencies

sudo pkg add --update linux-headers bash binutils alpine-sdk

Install Golang

sudo pkg add go
echo 'if [ -d "$HOME/go" ] ; then
  export PATH="$PATH:$HOME/go"
  export GOPATH="$HOME/go"
fi' > /etc/profile.d/golang.sh
mkdir ~/go
source /etc/profile

Compile Nomad from source

mkdir -p $GOPATH/src/github.com/hashicorp && cd $_
git clone https://github.com/hashicorp/nomad.git
cd nomad
make bootstrap
make dev
sudo ln -s bin/nomad /usr/local/bin/

Network configuration

Follow the HashiCorp documentation for installing CNI plugins and configuring bridge network.

Running Nomad as a service

Since Alpine uses OpenRC to manage services, we'll have to create an /etc/init.d/nomad file with the following contents:

#!/sbin/openrc-run

name=$RC_SVCNAME
cfgfile="/etc/$RC_SVCNAME/$RC_SVCNAME.conf"
command="/usr/local/bin/nomad"
command_args="agent -config /etc/nomad/server.hcl -bind=$(/sbin/ifconfig wlan0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')"
command_user="root"

NOMAD_LOGFILE="${NOMAD_LOGFILE:-/var/log/${RC_SVCNAME}.log}"
NOMAD_ERRFILE="${NOMAD_ERRFILE:-${NOMAD_LOGFILE}}"
NOMAD_OUTFILE="${NOMAD_OUTFILE:-${NOMAD_LOGFILE}}"
if [ "$NOMAD_ERRFILE" = "$NOMAD_OUTFILE" ]; then
	LOGPROXY_OPTS="$LOGPROXY_OPTS -m"
fi
export \
	LOGPROXY_CHMOD="${LOGPROXY_CHMOD:-0644}" \
	LOGPROXY_LOG_DIRECTORY="${LOGPROXY_LOG_DIRECTORY:-/var/log}" \
	LOGPROXY_ROTATION_SIZE="${LOGPROXY_ROTATION_SIZE:-104857600}" \
	LOGPROXY_ROTATION_TIME="${LOGPROXY_ROTATION_TIME:-86400}" \
	LOGPROXY_ROTATION_SUFFIX="${LOGPROXY_ROTATION_SUFFIX:-.%Y%m%d%H%M%S}" \
	LOGPROXY_ROTATED_FILES="${LOGPROXY_ROTATE_FILES:-5}"

output_logger="log_proxy $LOGPROXY_OPTS $NOMAD_OUTFILE"
error_logger="log_proxy $LOGPROXY_OPTS $NOMAD_ERRFILE"

pidfile="/run/$RC_SVCNAME/$RC_SVCNAME.pid"
start_stop_daemon_args=""
command_background="yes"

depend() {
        need net
}

start_pre() {
        checkpath --directory --owner $command_user:$command_user --mode 0775 \
                /run/$RC_SVCNAME /var/log/$RC_SVCNAME
}

This init file is configured to look up a configuration file at /etc/nomad/server.hcl. This is the file contents:

log_level = "DEBUG"

# Setup data dir

data_dir = "/var/lib/nomad"

server {
  enabled = true
  bootstrap_expect = 1
}

You can also replace it with a client.hcl file if you'd like to run the device as a Nomad client.

Start the server with:

sudo rc-service nomad start

Check logs at /var/log/nomad.log for troubleshooting. If everything goes well, you should be able to access the Nomad UI at http://YOUR_SERVER_IP:4646

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