Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Containerize dependencies #92

Merged
merged 5 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM docker.io/peaceiris/mdbook:v0.4.15

RUN apk update && apk add hugo
a-kenji marked this conversation as resolved.
Show resolved Hide resolved

# 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;
53 changes: 52 additions & 1 deletion watch-serve.sh
Original file line number Diff line number Diff line change
@@ -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" <Containerfile
$CRT run --rm -it --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 " - nix"
echo " - docker"
echo " - podman"
echo " - mdbook AND hugo"
echo ""
echo "To compile and preview the docs locally."
exit 1
fi

exit 0