Skip to content

Commit

Permalink
watch-serve.sh: Add container support
Browse files Browse the repository at this point in the history
for people that have a container runtime available and prefer not to
install the dependencies locally. If the dependencies are installed
locally, it will call these directly instead of using the container.
Otherwise it will check if podman is installed and use that, or docker
otherwise, build the container from the `Containerfile` and run it with
the project directory mounted.

If neither the dependencies nor a suitable container runtime can be
found, a messages is printed to stdout that tells the user what is
needed to use the script.
  • Loading branch information
har7an committed Mar 1, 2022
1 parent 5f05cb2 commit 41f5594
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion watch-serve.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
#!/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 podman); then
CRT="$(which podman)"
echo "Using '$CRT' as container runtime"

$CRT build --tag "$CONTAINER_NAME" -f Containerfile
$CRT run --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" <Containerfile
$CRT run --user "$(id -u):$(id -g)" -v "$PWD:$PWD" -w "$PWD" -p 1313:1313 $CONTAINER_NAME

else
echo "You must have installed either of:"
echo ""
echo " - docker"
echo " - podman"
echo " - mdbook AND hugo"
echo ""
echo "To compile and preview the docs locally."
exit 1
fi

exit 0

0 comments on commit 41f5594

Please sign in to comment.