2023-04-24 16:23:33 +01:00
#!/bin/sh
# The source of this file is https://raw.githubusercontent.com/grafana/writers-toolkit/main/docs/make-docs.
2023-07-18 09:52:11 +01:00
# # `make-docs` procedure changelog
#
# Updates should conform to the guidelines in https://keepachangelog.com/en/1.1.0/.
# [Semantic versioning](https://semver.org/) is used to help the reader identify the significance of changes.
# Changes are relevant to this script and the support docs.mk GNU Make interface.
2023-11-07 09:48:34 +00:00
#
2023-11-30 08:50:38 +00:00
# ## 5.1.2 (2023-11-08)
#
# ### Added
#
# - Hide manual_mount warning messages from non-debug output.
# Set the DEBUG environment variable to see all hidden messages.
#
2023-11-07 09:48:34 +00:00
# ## 5.1.1 (2023-10-30)
#
# ### Added
#
# - Support for Datadog and Oracle data source plugins repositories.
#
# ## 5.1.0 (2023-10-20)
#
# ### Added
#
# - Support for the plugins monorepo.
#
# ## 5.0.0 (2023-10-18)
#
# ### Added
#
# - Improved support for website repository.
#
# Mount more content and provide some feedback to users that the build can take time.
#
# - Ability to enter the `grafana/docs-base` container with a shell using the `ENTER` environment variable.
#
# ### Fixed
#
# - Correct key combination for interrupting the process.
#
# Keyboards use capital letters so this more accurately reflects the exact key combination users are expected to press.
#
# ### Removed
#
# - Imperfect implementation of container name.
#
# Facilitates running `make vale` and `make docs` at once.
# Container names are convenient for recognition in `docker ps` but the current implementation has more downsides than upsides.
#
# - Forced platform specification now that multiple architecture images exist.
#
# Significantly speeds up build times on larger repositories.
#
2023-10-06 09:47:55 +01:00
# ## 4.2.2 (2023-10-05)
# - Added support for Jira data source and MongoDB data source plugins repositories.
2023-11-07 09:48:34 +00:00
#
2023-09-18 10:49:39 +01:00
# ## 4.2.1 (2023-09-13)
# ## Fixed
2023-11-07 09:48:34 +00:00
#
2023-09-18 10:49:39 +01:00
# - Improved consistency of the webserver request loop by polling the Hugo port rather than the proxy port.
2023-11-07 09:48:34 +00:00
#
2023-09-04 13:27:06 +01:00
# ## 4.2.0 (2023-09-01)
2023-11-07 09:48:34 +00:00
#
2023-09-04 13:27:06 +01:00
# ### Added
2023-11-07 09:48:34 +00:00
#
2023-09-04 13:27:06 +01:00
# - Retry the initial webserver request up to ten times to allow for the process to start.
# If it is still failing after ten seconds, an error message is logged.
2023-11-07 09:48:34 +00:00
#
2023-07-24 09:19:37 +01:00
# ## 4.1.1 (2023-07-20)
2023-11-07 09:48:34 +00:00
#
2023-07-24 09:19:37 +01:00
# ### Fixed
2023-11-07 09:48:34 +00:00
#
2023-07-24 09:19:37 +01:00
# - Replaced use of `realpath` with POSIX compatible alternative to determine default value for REPOS_PATH.
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ## 4.1.0 (2023-06-16)
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ### Added
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# - Mounts of `layouts` and `config` directories for the `website` project.
# Ensures that local changes to mounts or shortcodes are reflected in the development server.
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ### Fixed
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# - Version inference for versioned docs pages.
# Pages in versioned projects now have the `versioned: true` front matter set to ensure that "version" in $.Page.Scratch is set on builds.
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ## 4.0.0 (2023-06-06)
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ### Removed
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# - `doc-validator/%` target.
# The behavior of the target was not as described.
# Instead, to limit `doc-validator` to only specific files, refer to https://grafana.com/docs/writers-toolkit/writing-guide/tooling-and-workflows/validate-technical-documentation/#run-on-specific-files.
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ## 3.0.0 (2023-05-18)
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ### Fixed
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# - Compatibility with the updated Make targets in the `website` repository.
# `docs` now runs this script itself, `server-docs` builds the site with the `docs` Hugo environment.
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ## 2.0.0 (2023-05-18)
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ### Added
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# - Support for the grafana-cloud/frontend-observability/faro-web-sdk project.
# - Use of `doc-validator` v2.0.x which includes breaking changes to command line options.
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ### Fixed
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# - Source grafana-cloud project from website repository.
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ### Added
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# - Support for running the Vale linter with `make vale`.
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ## 1.2.1 (2023-05-05)
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ### Fixed
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# - Use `latest` tag of `grafana/vale` image by default instead of hardcoded older version.
# - Fix mounting multiple projects broken by the changes in 1.0.1
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ## 1.2.0 (2023-05-05)
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ### Added
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# - Support for running the Vale linter with `make vale`.
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ### Fixed
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ## 1.1.0 (2023-05-05)
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ### Added
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# - Rewrite error output so it can be followed by text editors.
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ### Fixed
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# - Fix `docs-debug` container process port.
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ## 1.0.1 (2023-05-04)
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ### Fixed
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# - Ensure complete section hierarchy so that all projects have a visible menu.
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ## 1.0.0 (2023-05-04)
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# ### Added
2023-11-07 09:48:34 +00:00
#
2023-07-18 09:52:11 +01:00
# - Build multiple projects simultaneously if all projects are checked out locally.
# - Run [`doc-validator`](https://github.com/grafana/technical-documentation/tree/main/tools/cmd/doc-validator) over projects.
# - Redirect project root to mounted version.
# For example redirect `/docs/grafana/` to `/docs/grafana/latest/`.
# - Support for Podman or Docker containers with `PODMAN` environment variable.
# - Support for projects:
# - agent
# - enterprise-logs
# - enterprise-metrics
# - enterprise-traces
# - grafana
# - grafana-cloud
# - grafana-cloud/machine-learning
# - helm-charts/mimir-distributed
# - helm-charts/tempo-distributed
# - incident
# - loki
# - mimir
# - oncall
# - opentelemetry
# - phlare
# - plugins
# - slo
# - tempo
# - writers-toolkit
2023-04-24 16:23:33 +01:00
set -ef
readonly DOCS_HOST_PORT = " ${ DOCS_HOST_PORT :- 3002 } "
readonly DOCS_IMAGE = " ${ DOCS_IMAGE :- grafana /docs-base: latest } "
readonly DOC_VALIDATOR_INCLUDE = " ${ DOC_VALIDATOR_INCLUDE :- .+ \. md $} "
2023-05-18 15:50:20 +01:00
readonly DOC_VALIDATOR_SKIP_CHECKS = " ${ DOC_VALIDATOR_SKIP_CHECKS :- ^image- } "
2023-04-24 16:23:33 +01:00
readonly HUGO_REFLINKSERRORLEVEL = " ${ HUGO_REFLINKSERRORLEVEL :- WARNING } "
2023-05-18 15:50:20 +01:00
readonly VALE_MINALERTLEVEL = " ${ VALE_MINALERTLEVEL :- error } "
2023-06-16 18:45:44 +01:00
readonly WEBSITE_EXEC = " ${ WEBSITE_EXEC :- make server-docs } "
2023-04-24 16:23:33 +01:00
# If set, the docs-base image will run a prebuild script that sets up Hugo mounts.
readonly WEBSITE_MOUNTS = " ${ WEBSITE_MOUNTS :- } "
PODMAN = " $(if command -v podman >/dev/null 2>& 1; then echo podman; else echo docker; fi) "
2023-08-21 08:56:54 +01:00
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
2023-04-24 16:23:33 +01:00
about() {
cat <<EOF
Test documentation locally with multiple source repositories.
The REPOS_PATH environment variable is a colon (:) separated list of paths in which to look for project repositories.
EOF
}
usage() {
cat <<EOF
Usage:
REPOS_PATH=<PATH[:<PATH>...]> $0 [<PROJECT>[:<VERSION>[:<REPO>[:<DIR>]]]...]
Examples:
REPOS_PATH=~/ext/grafana/ $0 writers-toolkit tempo:latest helm-charts/mimir-distributed:latest:mimir:docs/sources/mimir-distributed
EOF
}
if [ $# -lt 1 ] ; then
cat <<EOF >&2
ERRR: arguments required but not supplied.
$(about)
$(usage)
EOF
exit 1
fi
2023-07-24 09:19:37 +01:00
readonly REPOS_PATH = " ${ REPOS_PATH :-$( cd " $( git rev-parse --show-toplevel) /.." && echo " ${ PWD } " ) } "
2023-04-24 16:23:33 +01:00
if [ -z " ${ REPOS_PATH } " ] ; then
cat <<EOF >&2
ERRR: REPOS_PATH environment variable is required but has not been provided.
$(usage)
EOF
exit 1
fi
SOURCES_as_code = 'as-code-docs'
SOURCES_enterprise_metrics = 'backend-enterprise'
SOURCES_enterprise_metrics_ = 'backend-enterprise'
2023-05-18 15:50:20 +01:00
SOURCES_grafana_cloud = 'website'
2023-07-13 18:24:23 +01:00
SOURCES_grafana_cloud_alerting_and_irm_machine_learning = 'machine-learning'
SOURCES_grafana_cloud_alerting_and_irm_slo = 'slo'
2023-04-24 16:23:33 +01:00
SOURCES_grafana_cloud_k6 = 'k6-docs'
2023-05-18 15:50:20 +01:00
SOURCES_grafana_cloud_data_configuration_integrations = 'cloud-onboarding'
SOURCES_grafana_cloud_frontend_observability_faro_web_sdk = 'faro-web-sdk'
2023-04-24 16:23:33 +01:00
SOURCES_helm_charts_mimir_distributed = 'mimir'
SOURCES_helm_charts_tempo_distributed = 'tempo'
SOURCES_opentelemetry = 'opentelemetry-docs'
2023-11-07 09:48:34 +00:00
SOURCES_plugins_grafana_datadog_datasource = 'datadog-datasource'
2023-10-06 09:47:55 +01:00
SOURCES_plugins_grafana_jira_datasource = 'jira-datasource'
SOURCES_plugins_grafana_mongodb_datasource = 'mongodb-datasource'
2023-11-07 09:48:34 +00:00
SOURCES_plugins_grafana_oracle_datasource = 'oracle-datasource'
2023-07-13 18:24:23 +01:00
SOURCES_plugins_grafana_splunk_datasource = 'splunk-datasource'
2023-04-24 16:23:33 +01:00
VERSIONS_as_code = 'UNVERSIONED'
VERSIONS_grafana_cloud = 'UNVERSIONED'
2023-07-13 18:24:23 +01:00
VERSIONS_grafana_cloud_alerting_and_irm_machine_learning = 'UNVERSIONED'
VERSIONS_grafana_cloud_alerting_and_irm_slo = 'UNVERSIONED'
2023-04-24 16:23:33 +01:00
VERSIONS_grafana_cloud_k6 = 'UNVERSIONED'
2023-05-18 15:50:20 +01:00
VERSIONS_grafana_cloud_data_configuration_integrations = 'UNVERSIONED'
VERSIONS_grafana_cloud_frontend_observability_faro_web_sdk = 'UNVERSIONED'
2023-04-24 16:23:33 +01:00
VERSIONS_opentelemetry = 'UNVERSIONED'
2023-11-07 09:48:34 +00:00
VERSIONS_plugins_grafana_datadog_datasource = 'latest'
VERSIONS_plugins_grafana_jira_datasource = 'latest'
VERSIONS_plugins_grafana_mongodb_datasource = 'latest'
VERSIONS_plugins_grafana_oracle_datasource = 'latest'
VERSIONS_plugins_grafana_splunk_datasource = 'latest'
2023-04-24 16:23:33 +01:00
VERSIONS_technical_documentation = 'UNVERSIONED'
2023-05-18 15:50:20 +01:00
VERSIONS_website = 'UNVERSIONED'
2023-04-24 16:23:33 +01:00
VERSIONS_writers_toolkit = 'UNVERSIONED'
2023-05-18 15:50:20 +01:00
PATHS_grafana_cloud = 'content/docs/grafana-cloud'
2023-04-24 16:23:33 +01:00
PATHS_helm_charts_mimir_distributed = 'docs/sources/helm-charts/mimir-distributed'
PATHS_helm_charts_tempo_distributed = 'docs/sources/helm-charts/tempo-distributed'
PATHS_mimir = 'docs/sources/mimir'
2023-11-07 09:48:34 +00:00
PATHS_plugins_grafana_datadog_datasource = 'docs/sources'
PATHS_plugins_grafana_jira_datasource = 'docs/sources'
PATHS_plugins_grafana_mongodb_datasource = 'docs/sources'
PATHS_plugins_grafana_oracle_datasource = 'docs/sources'
PATHS_plugins_grafana_splunk_datasource = 'docs/sources'
2023-04-24 16:23:33 +01:00
PATHS_tempo = 'docs/sources/tempo'
2023-11-07 09:48:34 +00:00
PATHS_website = 'content'
2023-04-24 16:23:33 +01:00
# identifier STR
# Replace characters that are not valid in an identifier with underscores.
identifier() {
echo " $1 " | tr -C '[:alnum:]_\n' '_'
}
# aget ARRAY KEY
# Get the value of KEY from associative array ARRAY.
# Characters that are not valid in an identifier are replaced with underscores.
aget() {
eval echo '$' " $( identifier " $1 " ) _ $( identifier " $2 " ) "
}
2023-11-07 09:48:34 +00:00
# src returns the project source repository name for a project.
src() {
_project = " $1 "
case " ${ _project } " in
plugins/*)
if [ -z " $( aget SOURCES " ${ _project } " ) " ] ; then
echo plugins-private
else
aget SOURCES " ${ _project } "
fi
;;
*)
if [ -z " $( aget SOURCES " ${ _project } " ) " ] ; then
echo " ${ _project } "
else
aget SOURCES " ${ _project } "
fi
;;
esac
unset _project
}
# path returns the relative path within the repository that contain the docs for a project.
path() {
_project = " $1 "
case " ${ _project } " in
plugins/*)
if [ -z " $( aget PATHS " ${ _project } " ) " ] ; then
echo " ${ _project } /docs/sources"
else
aget PATHS " ${ _project } "
fi
;;
*)
if [ -z " $( aget PATHS " ${ _project } " ) " ] ; then
echo "docs/sources"
else
aget PATHS " ${ _project } "
fi
esac
unset _project
}
# version returns the version for a project. Unversioned projects return the special value 'UNVERSIONED'.
version() {
_project = " $1 "
case " ${ _project } " in
plugins/*)
if [ -z " $( aget VERSIONS " ${ _project } " ) " ] ; then
echo "UNVERSIONED"
else
aget VERSIONS " ${ _project } "
fi
;;
*)
if [ -z " $( aget VERSIONS " ${ _project } " ) " ] ; then
echo latest
else
aget VERSIONS " ${ _project } "
fi
esac
unset _project
}
2023-04-24 16:23:33 +01:00
# new_proj populates a new project structure.
new_proj() {
_project = " $1 "
_version = " $2 "
_repo = " $3 "
_path = " $4 "
# If version is not set, use the script mapping of project to default versions if it exists.
# Fallback to 'latest'.
if [ -z " ${ _version } " ] ; then
2023-11-07 09:48:34 +00:00
_version = " $( version " ${ _project } " ) "
2023-04-24 16:23:33 +01:00
fi
# If repo is not set, use the script mapping of project to repo name if it exists.
# Fallback to using the project name.
if [ -z " ${ _repo } " ] ; then
2023-11-07 09:48:34 +00:00
_repo = " $( src " ${ _project } " ) "
2023-04-24 16:23:33 +01:00
fi
# If path is not set, use the script mapping of project to docs sources path if it exists.
# Fallback to using 'docs/sources'.
if [ -z " ${ _path } " ] ; then
2023-11-07 09:48:34 +00:00
_path = " $( path " ${ _project } " ) "
2023-04-24 16:23:33 +01:00
fi
echo " ${ _project } : ${ _version } : ${ _repo } : ${ _path } "
unset _project _version _repo _path
}
# proj_url returns the webserver URL for a project.
# It expects a complete project structure as input.
proj_url() {
IFS = : read -r _project _version _ _ <<POSIX_HERESTRING
$1
POSIX_HERESTRING
2023-05-18 15:50:20 +01:00
if [ " ${ _project } " = 'website' ] ; then
echo "http://localhost: ${ DOCS_HOST_PORT } /docs/"
unset _project _version
return
fi
2023-04-24 16:23:33 +01:00
if [ -z " ${ _version } " ] || [ " ${ _version } " = 'UNVERSIONED' ] ; then
echo "http://localhost: ${ DOCS_HOST_PORT } /docs/ ${ _project } /"
else
echo "http://localhost: ${ DOCS_HOST_PORT } /docs/ ${ _project } / ${ _version } /"
fi
unset _project _version
}
# proj_ver returns the version for a project.
# It expects a complete project structure as input.
proj_ver() {
IFS = : read -r _ _ver _ _ <<POSIX_HERESTRING
$1
POSIX_HERESTRING
echo " ${ _ver } "
unset _ver
}
# proj_dst returns the container path to content source for a project.
# It expects a complete project structure as input.
proj_dst() {
IFS = : read -r _project _version _ _ <<POSIX_HERESTRING
$1
POSIX_HERESTRING
2023-05-18 15:50:20 +01:00
if [ " ${ _project } " = 'website' ] ; then
2023-11-07 09:48:34 +00:00
echo '/hugo/content'
2023-05-18 15:50:20 +01:00
unset _project _version
return
fi
2023-04-24 16:23:33 +01:00
if [ -z " ${ _version } " ] || [ " ${ _version } " = 'UNVERSIONED' ] ; then
echo "/hugo/content/docs/ ${ _project } "
else
echo "/hugo/content/docs/ ${ _project } / ${ _version } "
fi
2023-05-18 15:50:20 +01:00
2023-04-24 16:23:33 +01:00
unset _project _version
}
2023-06-16 18:45:44 +01:00
# repo_path returns the host path to the project repository.
2023-04-24 16:23:33 +01:00
# It looks for the provided repository name in each of the paths specified in the REPOS_PATH environment variable.
2023-06-16 18:45:44 +01:00
repo_path() {
_repo = " $1 "
2023-04-24 16:23:33 +01:00
IFS = :
for lookup in ${ REPOS_PATH } ; do
if [ -d " ${ lookup } / ${ _repo } " ] ; then
2023-06-16 18:45:44 +01:00
echo " ${ lookup } / ${ _repo } "
2023-04-24 16:23:33 +01:00
unset _path _repo
return
fi
done
unset IFS
2023-08-21 08:56:54 +01:00
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 } ."
2023-06-16 18:45:44 +01:00
unset _repo
2023-04-24 16:23:33 +01:00
exit 1
}
2023-06-16 18:45:44 +01:00
# proj_src returns the host path to content source for a project.
# It expects a complete project structure as input.
# It looks for the provided repository name in each of the paths specified in the REPOS_PATH environment variable.
proj_src() {
IFS = : read -r _ _ _repo _path <<POSIX_HERESTRING
$1
POSIX_HERESTRING
_repo = " $( repo_path " ${ _repo } " ) "
echo " ${ _repo } / ${ _path } "
unset _path _repo
}
2023-04-24 16:23:33 +01:00
# proj_canonical returns the canonical absolute path partial URI for a project.
# It expects a complete project structure as input.
proj_canonical() {
IFS = : read -r _project _version _ _ <<POSIX_HERESTRING
$1
POSIX_HERESTRING
2023-05-18 15:50:20 +01:00
if [ " ${ _project } " = 'website' ] ; then
echo '/docs'
unset _project _version
return
fi
2023-04-24 16:23:33 +01:00
if [ -z " ${ _version } " ] || [ " ${ _version } " = 'UNVERSIONED' ] ; then
echo "/docs/ ${ _project } "
else
echo "/docs/ ${ _project } / ${ _version } "
fi
2023-05-18 15:50:20 +01:00
2023-04-24 16:23:33 +01:00
unset _project _version
}
proj_to_url_src_dst_ver() {
_url = " $( proj_url " $1 " ) "
_src = " $( proj_src " $1 " ) "
_dst = " $( proj_dst " $1 " ) "
_ver = " $( proj_ver " $1 " ) "
echo " ${ _url } ^ ${ _src } ^ ${ _dst } ^ ${ _ver } "
unset _url _src _dst _ver
}
url_src_dst_vers() {
for arg in " $@ " ; do
IFS = : read -r _project _version _repo _path <<POSIX_HERESTRING
$arg
POSIX_HERESTRING
case " ${ _project } " in
# Workaround for arbitrary mounts where the version field is expected to be the local directory
# and the repo field is expected to be the container directory.
arbitrary)
echo " ${ _project } ^ ${ _version } ^ ${ _repo } ^" # TODO
;;
logs)
proj_to_url_src_dst_ver " $( new_proj loki " ${ _version } " ) "
proj_to_url_src_dst_ver " $( new_proj enterprise-logs " ${ _version } " ) "
;;
metrics)
proj_to_url_src_dst_ver " $( new_proj mimir " ${ _version } " ) "
proj_to_url_src_dst_ver " $( new_proj helm-charts/mimir-distributed " ${ _version } " ) "
proj_to_url_src_dst_ver " $( new_proj enterprise-metrics " ${ _version } " ) "
;;
traces)
proj_to_url_src_dst_ver " $( new_proj tempo " ${ _version } " ) "
proj_to_url_src_dst_ver " $( new_proj enterprise-traces " ${ _version } " ) "
;;
*)
proj_to_url_src_dst_ver " $( new_proj " ${ _project } " " ${ _version } " " ${ _repo } " " ${ _path } " ) "
;;
esac
done
unset _project _version _repo _path
}
2023-08-21 08:56:54 +01:00
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) "
2023-09-04 13:27:06 +01:00
i = 1
max = 10
while [ " ${ i } " -ne " ${ max } " ]
do
sleep 1
debg "Retrying request to webserver assuming the process is still starting up."
i = $(( i + 1 ))
if ${ req } " ${ url } " ; then
echo
echo "View documentation locally:"
for x in ${ url_src_dst_vers } ; do
IFS = '^' read -r url _ _ <<POSIX_HERESTRING
2023-08-21 08:56:54 +01:00
$x
POSIX_HERESTRING
2023-09-04 13:27:06 +01:00
if [ -n " ${ url } " ] ; then
if [ " ${ _url } " != "arbitrary" ] ; then
echo " ${ url } "
fi
2023-08-21 08:56:54 +01:00
fi
2023-09-04 13:27:06 +01:00
done
echo
2023-11-07 09:48:34 +00:00
echo 'Press Ctrl+C to stop the server'
2023-09-04 13:27:06 +01:00
unset i max req url
return
fi
done
2023-08-21 08:56:54 +01:00
2023-09-04 13:27:06 +01:00
echo
errr 'The build was interrupted or a build error occurred, check the previous logs for possible causes.'
2023-11-07 09:48:34 +00:00
note 'You might need to use Ctrl+C to end the process.'
2023-09-18 10:49:39 +01:00
2023-09-04 13:27:06 +01:00
unset i max req url
2023-08-21 08:56:54 +01:00
}
debg() {
if [ -n " ${ DEBUG } " ] ; then
echo "DEBG: $1 " >& 2
fi
}
errr() {
echo "ERRR: $1 " >& 2
}
note() {
echo "NOTE: $1 " >& 2
}
2023-04-24 16:23:33 +01:00
url_src_dst_vers = " $( url_src_dst_vers " $@ " ) "
volumes = ""
redirects = ""
2023-06-16 18:45:44 +01:00
for arg in " $@ " ; do
IFS = : read -r _project _ _repo _ <<POSIX_HERESTRING
${arg}
POSIX_HERESTRING
if [ " ${ _project } " = website ] ; then
2023-11-07 09:48:34 +00:00
note "Please be patient, building the website can take some time."
2023-06-16 18:45:44 +01:00
_repo = " $( repo_path website) "
volumes = "--volume= ${ _repo } /config:/hugo/config"
2023-11-07 09:48:34 +00:00
volumes = " ${ volumes } --volume= ${ _repo } /layouts:/hugo/layouts"
volumes = " ${ volumes } --volume= ${ _repo } /scripts:/hugo/scripts"
2023-06-16 18:45:44 +01:00
fi
unset _project _repo
done
2023-04-24 16:23:33 +01:00
for x in ${ url_src_dst_vers } ; do
IFS = '^' read -r _url _src _dst _ver <<POSIX_HERESTRING
$x
POSIX_HERESTRING
if [ " ${ _url } " != "arbitrary" ] ; then
if [ ! -f " ${ _src } /_index.md" ] ; then
2023-08-21 08:56:54 +01:00
errr "Index file ' ${ _src } /_index.md' does not exist."
note "Is ' ${ _src } ' the correct source directory?"
2023-04-24 16:23:33 +01:00
exit 1
fi
fi
2023-11-07 09:48:34 +00:00
debg "Mounting ' ${ _src } ' at container path ' ${ _dst } '"
2023-08-21 08:56:54 +01:00
2023-04-24 16:23:33 +01:00
if [ -z " ${ volumes } " ] ; then
volumes = "--volume= ${ _src } : ${ _dst } "
else
volumes = " ${ volumes } --volume= ${ _src } : ${ _dst } "
fi
if [ -n " ${ _ver } " ] && [ " ${ _ver } " != 'UNVERSIONED' ] ; then
if [ -z " ${ redirects } " ] ; then
redirects = " ${ _dst } ^ ${ _ver } "
else
redirects = " ${ redirects } ${ _dst } ^ ${ _ver } "
fi
fi
unset _url _src _dst _ver
done
IFS = ':' read -r image _ <<POSIX_HERESTRING
${DOCS_IMAGE}
POSIX_HERESTRING
2023-05-18 15:50:20 +01:00
case " ${ image } " in
'grafana/doc-validator' )
proj = " $( new_proj " $1 " ) "
echo
" ${ PODMAN } " run \
2023-08-21 08:56:54 +01:00
--init \
--interactive \
--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#"
2023-05-18 15:50:20 +01:00
;;
'grafana/vale' )
proj = " $( new_proj " $1 " ) "
echo
" ${ PODMAN } " run \
2023-08-21 08:56:54 +01:00
--init \
--interactive \
--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#"
2023-05-18 15:50:20 +01:00
;;
*)
tempfile = " $( mktemp -t make-docs.XXX) "
cat <<EOF >"${tempfile}"
2023-04-24 16:23:33 +01:00
#!/usr/bin/env bash
2023-11-07 09:48:34 +00:00
tc() {
set \${*,,}
echo \${*^}
}
2023-04-24 16:23:33 +01:00
for redirect in ${redirects}; do
IFS='^' read -r path ver <<<"\${redirect}"
2023-06-16 18:45:44 +01:00
echo -e "---\\nredirectURL: \"\${path/\/hugo\/content/}\"\\ntype: redirect\\nversioned: true\\n---\\n" > "\${path/\${ver}/_index.md}"
2023-05-18 15:50:20 +01:00
done
2023-04-24 16:23:33 +01:00
2023-05-18 15:50:20 +01:00
for x in "${url_src_dst_vers}"; do
IFS='^' read -r _ _ dst _ <<<"\${x}"
2023-11-07 09:48:34 +00:00
title="\${dst%/*}"
title="\$(tc \${title##*/})"
2023-05-18 15:50:20 +01:00
while [[ -n "\${dst}" ]]; do
2023-11-07 09:48:34 +00:00
if [[ ! -f "\${dst}/_index.md" ]]; then
echo -e "---title: \${title}\\n---\\n\\n# \${title}\\n\\n{{< section >}}" > "\${dst}/_index.md"
fi
2023-05-18 15:50:20 +01:00
dst="\${dst%/*}"
done
2023-04-24 16:23:33 +01:00
done
2023-05-18 15:50:20 +01:00
if [[ -n "${WEBSITE_MOUNTS}" ]]; then
unset WEBSITE_SKIP_MOUNTS
fi
2023-04-24 16:23:33 +01:00
${WEBSITE_EXEC}
EOF
2023-05-18 15:50:20 +01:00
chmod +x " ${ tempfile } "
2023-07-24 09:19:37 +01:00
volumes = " ${ volumes } --volume= ${ tempfile } :/entrypoint"
2023-05-18 15:50:20 +01:00
readonly volumes
2023-08-21 08:56:54 +01:00
IFS = '' read -r cmd <<EOF
${PODMAN} run \
--env=HUGO_REFLINKSERRORLEVEL=${HUGO_REFLINKSERRORLEVEL} \
--init \
--interactive \
--publish=${DOCS_HOST_PORT}:3002 \
--publish=3003:3003 \
--rm \
--tty \
${volumes} \
2023-11-07 09:48:34 +00:00
${DOCS_IMAGE}
2023-08-21 08:56:54 +01:00
EOF
2023-05-18 15:50:20 +01:00
2023-11-07 09:48:34 +00:00
if [ -n " ${ ENTER } " ] ; then
${ cmd } /bin/bash
elif [ -n " ${ DEBUG } " ] ; then
await_build http://localhost:3003 &
debg " ${ cmd } /entrypoint"
${ cmd } /entrypoint
2023-08-21 08:56:54 +01:00
else
2023-11-07 09:48:34 +00:00
await_build http://localhost:3003 &
${ cmd } /entrypoint 2>& 1\
| sed -u \
-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' \
2023-11-30 08:50:38 +00:00
-e '/make/ d' \
-e '/WARNING: The manual_mount source directory/ d'
2023-08-21 08:56:54 +01:00
fi
2023-05-18 15:50:20 +01:00
;;
esac