diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..823587b --- /dev/null +++ b/Containerfile @@ -0,0 +1,8 @@ +FROM docker.io/peaceiris/mdbook:v0.4.15 + +RUN apk update && apk add hugo + +# We must give it a bind address, otherwise it will listen to connections from +# 127.0.0.1. Since we connect to the server from "outside" the container, this +# doesn't work. +ENTRYPOINT mdbook watch docs/ -d ../static/documentation & hugo server --bind 0.0.0.0; diff --git a/watch-serve.sh b/watch-serve.sh index 9310ae5..1b2cf64 100755 --- a/watch-serve.sh +++ b/watch-serve.sh @@ -1,3 +1,54 @@ #!/usr/bin/env bash -{ mdbook watch docs/ -d ../static/documentation & hugo server; } +# Return 0 if command $1 exists, 1 otherwise. +function _exists { + command -v "$1" >/dev/null +} + +if $(_exists mdbook) && $(_exists hugo); then + { mdbook watch docs/ -d ../static/documentation & hugo server; } + exit 0 +fi + +# Some pre-requisites are missing, try to use containers +CRT="" +CONTAINER_NAME="zellij-docs:latest" + +if $(_exists nix); then + echo "Trying 'nix develop' to execute script" + + nix develop --command "$0" + + if [[ $? -ne 0 ]] && $(_exists nix-shell); then + echo "Using 'nix-shell' to execute script instead" + + nix-shell --command "$0" + fi + +elif $(_exists podman); then + CRT="$(which podman)" + echo "Using '$CRT' as container runtime" + + $CRT build --tag "$CONTAINER_NAME" -f Containerfile + $CRT run --rm -it --userns keep-id --user "$(id -u):$(id -g)" -v "$PWD:$PWD:z" -w "$PWD" -p 1313:1313 $CONTAINER_NAME + +elif $(_exists docker); then + CRT="$(which docker)" + echo "Using '$CRT' as container runtime" + + $CRT build --tag "$CONTAINER_NAME"