From 2fd1b7e9f5f19f0ce6185ec95d18c99d4e689877 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Tue, 21 Dec 2021 16:39:51 +0100 Subject: [PATCH] ci: handle no-tty mode --- .github/workflows/build-and-publish.yml | 24 +++++++++-- Makefile | 22 ++++++++-- docker/entrypoint.sh | 6 +++ scripts/gx-teaching | 56 ++++++++++++++++++++++--- 4 files changed, 96 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index addb28c..58bdb88 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -79,16 +79,32 @@ jobs: docker image ls -a - name: Build HTML for docs - run: ./scripts/gx-teaching . build-docs-html + run: | + ./scripts/gx-teaching \ + --no-tty \ + --data-dir . \ + --action build-docs-html - name: Build PDF for docs - run: ./scripts/gx-teaching . build-slides-pdf + run: | + ./scripts/gx-teaching \ + --no-tty \ + --data-dir . \ + --action build-slides-pdf - name: Build HTML for slides - run: ./scripts/gx-teaching . build-slides-html + run: | + ./scripts/gx-teaching \ + --no-tty \ + --data-dir . \ + --action build-slides-html - name: Build PDF for slides - run: ./scripts/gx-teaching . build-slides-pdf + run: | + ./scripts/gx-teaching \ + --no-tty \ + --data-dir . \ + --action build-slides-pdf push-docker-image: name: "Push docker image to registry" diff --git a/Makefile b/Makefile index 95734e0..495f6fb 100755 --- a/Makefile +++ b/Makefile @@ -174,13 +174,29 @@ $(BUILD_SLIDES_DIR): ## docs => static web site ## -build: build-docs build-slides ## build all documents +build: build-pdf build-html ## build all documents as PDF and HTML files -build-slides: $(SLIDES_PDF_ALL) $(SLIDES_MD_ALL) ## build PDF slides only +build-pdf: build-docs-pdf build-slides-pdf ## build all documents as PDF files + +build-html: build-docs-html build-slides-html ## build all documents as HTML files + + +build-slides-pdf: $(SLIDES_PDF_ALL) $(SLIDES_MD_ALL) ## build PDF slides only merge-slides: $(SLIDES_MDPP_MD) $(SLIDES_MD_ALL) -build-docs: ## build static docs site only +build-docs-pdf: + mkdir -p $(BUILD_DOCS_DIR) + rm -f $(BUILD_DOCS_DIR)/combined.pdf + PYTHONUTF8=1 \ + ENABLE_PDF_EXPORT=1 \ + pipenv run mkdocs build \ + --site-dir $(BUILD_DOCS_DIR) + pdftk \ + $$(find $(BUILD_DOCS_DIR) -name *.pdf -not -name index.pdf |sort ) \ + cat output $(BUILD_DOCS_DIR)/combined.pdf + +build-docs-html: ## build static docs site only mkdir -p $(BUILD_DOCS_DIR) pipenv run mkdocs build \ --site-dir $(BUILD_DOCS_DIR) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 19d1dca..2f403b8 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -9,6 +9,11 @@ echo "Arguments: $ARGS" EXT_UID=${EXT_UID:-999} EXT_GID=${EXT_GID:-999} +# Create missing directories +mkdir -p _cache +mkdir -p _build +mkdir -p .marp + # Create user with given ID if needed if ! grep -q "^[^:]*:[^:]*:$EXT_UID:" /etc/group ; then groupadd -g "$EXT_GID" appuser @@ -20,6 +25,7 @@ if ! grep -q "^[^:]*:[^:]*:$EXT_UID:" /etc/passwd ; then fi if [ -d "_build" ]; then + chown -R "$EXT_UID:$EXT_GID" _cache chown -R "$EXT_UID:$EXT_GID" _build chown -R "$EXT_UID:$EXT_GID" .marp fi diff --git a/scripts/gx-teaching b/scripts/gx-teaching index 69762aa..ac4b39e 100755 --- a/scripts/gx-teaching +++ b/scripts/gx-teaching @@ -1,12 +1,58 @@ #!/bin/sh # vim: set ft=sh: -BASEDIR="${1:-.}" -BASEDIR="$(cd "$BASEDIR" && pwd)" - -ACTION="${2:-watch}" +BASEDIR="." +ACTION="watch" DOCKER_IMAGE=glenux/teaching-boilerplate:latest +DOCKER_OPT_TTY="-t" + +# Parse arguments +while [ $# -gt 0 ]; do + ARG="${1:-}" + OPT="${2:-}" + shift + + echo "ARG=$ARG OPT=$OPT" + + case "$ARG" in + -d|--data-dir) + shift # argument requires a parameter + if [ -z "$OPT" ]; then + >&2 echo "ERROR: missing argument for --data-dir" + exit 1 + fi + if [ ! -d "$OPT" ]; then + >&2 echo "ERROR: argument for --data-dir must be a directory" + exit 1 + fi + BASEDIR="$(cd "$OPT" && pwd)" + ;; + -a|--action) + shift # argument requires a parameter + if [ -z "$OPT" ]; then + >&2 echo "ERROR: missing argument for --action" + exit 1 + fi + ACTION="$OPT" + ;; + -T|--no-tty) + DOCKER_OPT_TTY="" + ;; + -h|--help) + echo "Usage: $0 [options]" + echo "" + echo "-d, --data-dir DIR Content directory" + echo "-a, --action ACTION Action (watch, build, shell, etc.)" + echo "-t, --tty Enable TTY mode (needed for shell)" + echo "-h, --help Show this help" + ;; + *) + >&2 echo "ERROR: unknown option '$ARG'" + exit 1 + ;; + esac +done echo "basedir = $BASEDIR" echo "docker_image = $DOCKER_IMAGE" @@ -34,7 +80,7 @@ if [ -d "$BASEDIR/docs" ]; then DOCKER_OPT_MKDOCS_PORT="-p 5100:5100" fi -docker run -it \ +docker run -i $DOCKER_OPT_TTY \ --shm-size=1gb \ -e "EXT_UID=$(id -u)" \ -e "EXT_GID=$(id -g)" \