diff --git a/docs/docs.mk b/docs/docs.mk index 9b0718ac9569..2611bbe80495 100644 --- a/docs/docs.mk +++ b/docs/docs.mk @@ -76,7 +76,7 @@ docs-rm: ## Remove the docs container. .PHONY: docs-pull docs-pull: ## Pull documentation base image. - $(PODMAN) pull $(DOCS_IMAGE) + $(PODMAN) pull -q $(DOCS_IMAGE) make-docs: ## Fetch the latest make-docs script. make-docs: diff --git a/docs/make-docs b/docs/make-docs index 74aa8704616c..63a26b150510 100755 --- a/docs/make-docs +++ b/docs/make-docs @@ -133,6 +133,21 @@ readonly WEBSITE_MOUNTS="${WEBSITE_MOUNTS:-}" PODMAN="$(if command -v podman >/dev/null 2>&1; then echo podman; else echo docker; fi)" +if ! command -v curl >/dev/null 2>&1; then + if ! command -v wget >/dev/null 2>&1; then + errr 'either `curl` or `wget` must be installed for this script to work.' + + exit 1 + fi +fi + +if ! command -v "${PODMAN}" >/dev/null 2>&1; then + errr 'either `podman` or `docker` must be installed for this script to work.' + + exit 1 +fi + + about() { cat <&2 - echo "NOTE: you must have a checkout of the project '${_repo}' at '${REPOS_PATH##:*}/${_repo}'." >&2 - echo "NOTE: if you have cloned the repository into a directory with a different name, consider changing it to ${_repo}." >&2 + errr "could not find project '${_repo}' in any of the paths in REPOS_PATH '${REPOS_PATH}'." + note "you must have a checkout of the project '${_repo}' at '${REPOS_PATH##:*}/${_repo}'." + note "if you have cloned the repository into a directory with a different name, consider changing it to ${_repo}." + unset _repo exit 1 } @@ -420,6 +436,50 @@ POSIX_HERESTRING unset _project _version _repo _path } +await_build() { + url="$1" + req="$(if command -v curl >/dev/null 2>&1; then echo 'curl -s -o /dev/null'; else echo 'wget -q'; fi)" + + sleep 2 + + if ${req} "${url}"; then + echo + echo "View documentation locally:" + for x in ${url_src_dst_vers}; do + IFS='^' read -r url _ _ <&2 + fi +} + +errr() { + echo "ERRR: $1" >&2 +} + +note() { + echo "NOTE: $1" >&2 +} + url_src_dst_vers="$(url_src_dst_vers "$@")" volumes="" @@ -445,13 +505,14 @@ POSIX_HERESTRING if [ "${_url}" != "arbitrary" ]; then if [ ! -f "${_src}/_index.md" ]; then - echo "ERRR: Index file '${_src}/_index.md' does not exist." >&2 - echo "Is '${_src}' the correct source directory?" >&2 + errr "Index file '${_src}/_index.md' does not exist." + note "Is '${_src}' the correct source directory?" exit 1 fi fi - echo "DEBG: Mounting '${_src}' at container path '${_dst}'" >&2 + debg "DEBG: Mounting '${_src}' at container path '${_dst}'" + if [ -z "${volumes}" ]; then volumes="--volume=${_src}:${_dst}" else @@ -477,35 +538,35 @@ case "${image}" in proj="$(new_proj "$1")" echo "${PODMAN}" run \ - --init \ - --interactive \ - --name "${DOCS_CONTAINER}" \ - --platform linux/amd64 \ - --rm \ - --tty \ - ${volumes} \ - "${DOCS_IMAGE}" \ - "--include=${DOC_VALIDATOR_INCLUDE}" \ - "--skip-checks=${DOC_VALIDATOR_SKIP_CHECKS}" \ - /hugo/content/docs \ - "$(proj_canonical "${proj}")" | sed "s#$(proj_dst "${proj}")#sources#" + --init \ + --interactive \ + --name "${DOCS_CONTAINER}" \ + --platform linux/amd64 \ + --rm \ + --tty \ + ${volumes} \ + "${DOCS_IMAGE}" \ + "--include=${DOC_VALIDATOR_INCLUDE}" \ + "--skip-checks=${DOC_VALIDATOR_SKIP_CHECKS}" \ + /hugo/content/docs \ + "$(proj_canonical "${proj}")" | sed "s#$(proj_dst "${proj}")#sources#" ;; 'grafana/vale') proj="$(new_proj "$1")" echo "${PODMAN}" run \ - --init \ - --interactive \ - --name "${DOCS_CONTAINER}" \ - --platform linux/amd64 \ - --rm \ - --tty \ - ${volumes} \ - "${DOCS_IMAGE}" \ - "--minAlertLevel=${VALE_MINALERTLEVEL}" \ - --config=/etc/vale/.vale.ini \ - --output=line \ - /hugo/content/docs | sed "s#$(proj_dst "${proj}")#sources#" + --init \ + --interactive \ + --name "${DOCS_CONTAINER}" \ + --platform linux/amd64 \ + --rm \ + --tty \ + ${volumes} \ + "${DOCS_IMAGE}" \ + "--minAlertLevel=${VALE_MINALERTLEVEL}" \ + --config=/etc/vale/.vale.ini \ + --output=line \ + /hugo/content/docs | sed "s#$(proj_dst "${proj}")#sources#" ;; *) tempfile="$(mktemp -t make-docs.XXX)" @@ -535,33 +596,38 @@ EOF volumes="${volumes} --volume=${tempfile}:/entrypoint" readonly volumes - echo - echo "Documentation will be served at the following URLs:" - for x in ${url_src_dst_vers}; do - IFS='^' read -r url _ _ <&1| sed \ + -e '/Web Server is available at http:\/\/localhost:3003\/ (bind address 0.0.0.0)/ d' \ + -e '/^hugo server/ d' \ + -e '/fatal: not a git repository (or any parent up to mount point \/)/ d' \ + -e '/Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)./ d' \ + -e "/Makefile:[0-9]*: warning: overriding recipe for target 'docs'/ d" \ + -e "/docs.mk:[0-9]*: warning: ignoring old recipe for target 'docs'/ d" \ + -e '/\/usr\/bin\/make -j 2 proxy hserver-docs HUGO_PORT=3003/ d' \ + -e '/website-proxy/ d' \ + -e '/rm -rf dist*/ d' \ + -e '/Press Ctrl+C to stop/ d' \ + -e '/make/ d' || echo + fi ;; esac