Skip to content

Commit

Permalink
mac HinD basically working; just a nomad run cpu constraint remains
Browse files Browse the repository at this point in the history
  • Loading branch information
traceypooh committed Mar 30, 2024
1 parent 2341fdb commit ff65503
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 23 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ net.core.wmem_max=134217728' |sudo tee /etc/sysctl.d/90-tcp-memory.conf

# Miscellaneous
- client IP addresses will be in request header 'X-Forwarded-For' (per `caddy`)
- pop inside the HinD container:
```
sudo podman exec -it hind zsh
```
- get list of `consul` services:
```
wget -qO- 'localhost:8500/v1/catalog/services?tags=1' | jq .
Expand Down
16 changes: 13 additions & 3 deletions bin/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,19 @@ else
pkill -SIGQUIT nomad
sleep 5

consul keygen |tr -d '^\n' | podman secret create HIND_C -
nomad operator gossip keyring generate |tr -d '^\n' | podman secret create HIND_N -
grep -F 'Secret ID' /tmp/bootstrap |cut -f2- -d= |tr -d ' ' | podman secret create NOMAD_TOKEN -

if [ "$HOST_UNAME" = Darwin ]; then
apt-get install -yqq fuse-overlayfs
echo; echo
echo -n 'echo -n '
grep -F 'Secret ID' /tmp/bootstrap |cut -f2- -d= |tr -d ' \n'
echo ' | podman secret create NOMAD_TOKEN -'
echo; echo
else
consul keygen |tr -d '^\n' | podman secret create HIND_C -
nomad operator gossip keyring generate |tr -d '^\n' | podman secret create HIND_N -
grep -F 'Secret ID' /tmp/bootstrap |cut -f2- -d= |tr -d ' ' | podman secret create NOMAD_TOKEN -
fi

rm -f /tmp/*

Expand Down
60 changes: 40 additions & 20 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ export FQDN=$(hostname -f)
podman -v > /dev/null || echo 'please install the podman package first'
podman -v > /dev/null || exit 1

if [ "$HOST_UNAME" = Darwin ]; then
ARGS_INIT=''
ARGS_RUN='-p 8000:80 -p 4000:443 --secret NOMAD_TOKEN,type=env'
# previously had also added above: '-v /sys/fs/cgroup:/sys/fs/cgroup:rw'

PV=$HOME/pv
# export FQDN=http://localhost
export FQDN=http://$FQDN
else
# In rare case this is a symlink, ensure we mount the proper source.
# NOTE: we map in /var/lib/containers here so `podman secret create` inside the `podman run`
# container will effect us, the outside/VM.
VLC=$(realpath /var/lib/containers 2>/dev/null || echo /var/lib/containers)
SOCK=$(podman info |grep -F podman.sock |rev |cut -f1 -d ' ' |rev)
ARGS_INIT="--net=host -v ${VLC}:/var/lib/containers"
ARGS_RUN="--net=host --cgroupns=host -v /opt/nomad/data/alloc:/opt/nomad/data/alloc -v $SOCK:$SOCK"
PV=/pv
fi

(
# clear any prior run (likely fail?)
Expand All @@ -40,45 +58,46 @@ podman -v > /dev/null || exit 1
# bootstrap the general image to a customized image for your cluster, leveraging podman secrets
IMG=ghcr.io/internetarchive/hind:main

# In rare case this is a symlink, ensure we mount the proper source.
# NOTE: we map in /var/lib/containers here so `podman secret create` inside the `podman run`
# container will effect us, the outside/VM.
VLC=$(realpath /var/lib/containers 2>/dev/null || echo /var/lib/containers)

set -x
# We need to shared these 2 directories "inside" the running `hind` container, and "outside" on
# the VM itself. We want to persist HTTPS cert files, and any `data/alloc` directories setup
# on the "inside" (eg: `nomad run`) need to be available to nomad jobs running on the outside/VM.
mkdir -p -m777 /pv/CERTS
mkdir -p -m777 $PV/CERTS
mkdir -p -m777 /opt/nomad/data/alloc

podman pull $QUIET $IMG > $OUT
podman run --net=host --privileged --cgroupns=host \
-v ${VLC}:/var/lib/containers \
podman run --privileged --cgroupns=host \
$ARGS_INIT \
-e FQDN -e HOST_UNAME \
--name hind-init $QUIET "$@" $IMG
podman commit $QUIET hind-init localhost/hind > $OUT 2>&1
podman rm -v hind-init > $OUT 2>&1
)


if [ "$HOST_UNAME" = Darwin ]; then
echo VEhJUy1HRVRTLVJFUExBQ0VELUlULURPRVMtUklMTFk= |tr -d '\n' | podman secret create HIND_C -
echo VEhJUy1HRVRTLVJFUExBQ0VELUlULURPRVMtUklMTFk= |tr -d '\n' | podman secret create HIND_N -

set +x
echo '
COPY/PASTE THE NOMAD_TOKEN secret create ABOVE NOW
'
read cont
fi


# Now run the new docker image in the background.
# NOTE: we switch `-v /var/lib/containers` to volume mounting the `podman.sock`, since we want HinD
# container to `podman run` nomad jobs on the outside/VM, not inside itself
(
SOCK=$(podman info |grep -F podman.sock |rev |cut -f1 -d ' ' |rev)
if [ "$HOST_UNAME" = Darwin ]; then
ARGS='-p 6000:4646 -p 8000:80 -p 4000:443 -v /sys/fs/cgroup:/sys/fs/cgroup:rw'
else
ARGS='--net=host'
fi

set -x
podman run --privileged --cgroupns=host \
$ARGS \
-v $SOCK:$SOCK \
-v /opt/nomad/data/alloc:/opt/nomad/data/alloc \
-v /pv:/pv \
podman run --privileged \
$ARGS_RUN \
-v $PV:/pv \
--secret HIND_C,type=env --secret HIND_N,type=env \
--restart=always --name hind -d $QUIET "$@" localhost/hind > $OUT 2>&1
)
Expand All @@ -93,6 +112,7 @@ SUCCESS!
exit 0
fi

set +x

echo '
Congratulations!
Expand All @@ -106,7 +126,7 @@ anywhere you have downloaded a `nomad` binary):
'

if [ $HOST_UNAME = Darwin ]; then
echo "export NOMAD_ADDR=http://$FQDN:6000"
echo "export NOMAD_ADDR=$FQDN:8000"
else
echo "export NOMAD_ADDR=https://$FQDN"
fi
Expand Down

0 comments on commit ff65503

Please sign in to comment.