@@ -5,30 +5,34 @@ export SHELLOPTS := pipefail:errexit
5
5
MAKEFLAGS += --warn-undefined-variables
6
6
MAKEFLAGS += --no-builtin-rule
7
7
8
+ .DEFAULT_GOAL : help
9
+
10
+ # Adapted from https://www.thapaliya.com/en/writings/well-documented-makefiles/
11
+ .PHONY : help
12
+ help : # # Display this help.
13
+ help :
14
+ @awk ' BEGIN {FS = ": ##"; printf "Usage:\n make <target>\n\nTargets:\n"} /^[a-zA-Z0-9_\.\-\/%]+: ##/ { printf " %-45s %s\n", $$1, $$2 }' $(MAKEFILE_LIST )
15
+
8
16
GIT_ROOT := $(shell git rev-parse --show-toplevel)
9
- # Support podman over Docker if it is available.
10
- PODMAN := $(shell if command -v podman >/dev/null 2>&1; then echo podman; else echo docker; fi)
11
17
12
- # This allows ports and base URL to be overridden, so services like ngrok.io can
13
- # be used to share a local running docs instances.
14
- DOCS_HOST_PORT := 3002
15
- DOCS_LISTEN_PORT := 3002
16
- DOCS_BASE_URL := "localhost: $( DOCS_HOST_PORT ) "
18
+ # List of projects to provide to the make-docs script.
19
+ PROJECTS := grafana-cloud/k6
20
+
21
+ # Name for the container.
22
+ export DOCS_CONTAINER := $( firstword $( subst /,-, $( PROJECTS ) ) -docs)
17
23
18
- PROJECT := k6
19
- PROJECT_VERSION :=
20
- ifeq ($(PROJECT_VERSION ) ,)
21
- PROJECT_URL := http://$(DOCS_BASE_URL ) /docs/$(PROJECT ) /
22
- PROJECT_CONTENT_DIR := /hugo/content/docs/$(PROJECT )
23
- else
24
- PROJECT_URL := http://$(DOCS_BASE_URL ) /docs/$(PROJECT ) /$(PROJECT_VERSION )
25
- PROJECT_CONTENT_DIR := /hugo/content/docs/$(PROJECT ) /$(PROJECT_VERSION )
26
- endif
24
+ # Host port to publish container port to.
25
+ export DOCS_HOST_PORT := 3002
27
26
28
- DOCS_IMAGE := grafana/docs-base:latest
29
- DOCS_CONTAINER := $( PROJECT ) - docs
27
+ # Container image used to perform Hugo build.
28
+ export DOCS_IMAGE := grafana/ docs-base:latest
30
29
31
- HUGO_REFLINKSERRORLEVEL ?= WARNING
30
+ # PATH-like list of directories within which to find projects.
31
+ # If all projects are checked out into the same directory, ~/repos/ for example, then the default should work.
32
+ export REPOS_PATH := $(realpath $(GIT_ROOT ) /..)
33
+
34
+ # How to treat Hugo relref errors.
35
+ export HUGO_REFLINKSERRORLEVEL := WARNING
32
36
33
37
.PHONY : docs-rm
34
38
docs-rm : # # Remove the docs container.
@@ -38,6 +42,26 @@ docs-rm: ## Remove the docs container.
38
42
docs-pull : # # Pull documentation base image.
39
43
$(PODMAN ) pull $(DOCS_IMAGE )
40
44
45
+ make-docs : # # Fetch the latest make-docs script.
46
+ make-docs :
47
+ curl -s -LO https://raw.githubusercontent.com/grafana/writers-toolkit/main/scripts/make-docs
48
+ chmod +x make-docs
49
+
50
+ .PHONY : docs
51
+ docs : # # Serve documentation locally.
52
+ docs : make-docs
53
+ $(PWD ) /make-docs $(PROJECTS )
54
+
55
+ .PHONY : docs/lint
56
+ docs/lint : # # Run docs-validator on the entire docs folder.
57
+ $(PODMAN ) run --rm -ti \
58
+ --platform linux/amd64 \
59
+ --volume " $( GIT_ROOT) /docs/sources:/docs/sources" \
60
+ grafana/doc-validator:latest \
61
+ --skip-image-validation \
62
+ /docs/sources \
63
+ /docs/k6
64
+
41
65
.PHONY : docs/lint
42
66
docs/lint : # # Run docs-validator on the entire docs folder.
43
67
docker run --rm -ti \
@@ -47,21 +71,3 @@ docs/lint: ## Run docs-validator on the entire docs folder.
47
71
--skip-image-validation \
48
72
/docs/sources \
49
73
/docs/k6
50
-
51
- .PHONY : docs
52
- docs : # # Serve documentation locally.
53
- docs : docs-pull
54
- @echo " Documentation will be served at:"
55
- echo $(PROJECT_URL )
56
- echo " "
57
- if [[ -z $$ {NON_INTERACTIVE} ]]; then \
58
- read -p " Press enter to continue" ; \
59
- fi
60
- $(PODMAN ) run -ti \
61
- --init \
62
- -v $(GIT_ROOT ) /docs/sources:$(PROJECT_CONTENT_DIR ) :ro,z \
63
- -e HUGO_REFLINKSERRORLEVEL=$(HUGO_REFLINKSERRORLEVEL ) \
64
- -p $(DOCS_HOST_PORT ) :$(DOCS_LISTEN_PORT ) \
65
- --name $(DOCS_CONTAINER ) \
66
- --rm \
67
- $(DOCS_IMAGE ) make server
0 commit comments