Makefile 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # Copyright 2019 The Kubernetes Authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. DOCKER ?= docker
  15. MKDOCS_IMAGE ?= eso-mkdocs:latest
  16. MKDOCS ?= mkdocs
  17. MIKE ?= mike
  18. DOCS_VERSION ?= main
  19. VERSION_NO_V ?= $(shell echo $(DOCS_VERSION) | cut -d'v' -f2)
  20. MAJOR_VERSION ?= $(shell echo $(VERSION_NO_V) | cut -d'.' -f1)
  21. MINOR_VERSION ?= $(shell echo $(VERSION_NO_V) | cut -d'.' -f2)
  22. DOCS_ALIAS ?= unstable
  23. GITHUB_TOKEN ?= invalid
  24. SERVE_BIND_ADDRESS ?= 127.0.0.1
  25. SHELL := /usr/bin/env bash
  26. # TOP is the current directory where this Makefile lives.
  27. TOP := $(dir $(firstword $(MAKEFILE_LIST)))
  28. # ROOT is the repository root.
  29. ROOT := $(abspath $(TOP))/../../
  30. SRCDIR := $(ROOT)/docs
  31. CFGFILE := $(ROOT)/hack/api-docs/mkdocs.yml
  32. # GENROOT is the root of the generated documentation.
  33. GENROOT := $(ROOT)/site
  34. GEN_CRD_API_REFERENCE_DOCS ?= $(ROOT)/bin/gen-crd-api-reference-docs
  35. # Grab the uid/gid to fix permissions due to running in a docker container.
  36. GID := $(shell id -g)
  37. UID := $(shell id -u)
  38. GIT_DIR := $(shell git rev-parse --path-format=absolute --git-dir)
  39. GIT_COMMON_DIR := $(shell git rev-parse --path-format=absolute --git-common-dir)
  40. GIT_MOUNT := $(if $(filter $(GIT_DIR),$(GIT_COMMON_DIR)),,--mount type=bind,source=$(GIT_COMMON_DIR),target=$(GIT_COMMON_DIR))
  41. # SOURCES is a list of a source files used to generate the documentation.
  42. SOURCES := $(shell find $(SRCDIR) -name \*.md)
  43. SOURCES += mkdocs.yml Makefile
  44. # entrypoint
  45. all: build
  46. .PHONY: image
  47. image:
  48. $(DOCKER) buildx build --load -t $(MKDOCS_IMAGE) -f Dockerfile .
  49. VERSION_TO_UPDATE ?= $(shell echo $(MAJOR_VERSION).$(MINOR_VERSION).x)
  50. .PHONY: stability-support.update
  51. stability-support.update:
  52. ROOT=$(ROOT) ./add_eso_version.sh $(VERSION_TO_UPDATE)
  53. .PHONY: build
  54. build: image generate $(SOURCES)
  55. mkdir -p $(GENROOT)
  56. $(DOCKER) run \
  57. --mount type=bind,source=$(ROOT),target=/repo \
  58. $(GIT_MOUNT) \
  59. --sig-proxy=true \
  60. --rm \
  61. --user $(UID):$(GID) \
  62. --env "GIT_COMMITTER_NAME=$(shell git config user.name)" \
  63. --env "GIT_COMMITTER_EMAIL=$(shell git config user.email)" \
  64. --env "GITHUB_TOKEN=$(GITHUB_TOKEN)" \
  65. $(MKDOCS_IMAGE) \
  66. $(SHELL) -c "cd /repo && $(MIKE) deploy --ignore-remote-status --update-aliases -F hack/api-docs/mkdocs.yml $(DOCS_VERSION) $(DOCS_ALIAS);"
  67. .PHONY: build.publish
  68. build.publish: image generate $(SOURCES)
  69. mkdir -p $(GENROOT)
  70. $(DOCKER) run \
  71. --mount type=bind,source=$(ROOT),target=/repo \
  72. $(GIT_MOUNT) \
  73. --sig-proxy=true \
  74. --rm \
  75. --user $(UID):$(GID) \
  76. --env "GIT_COMMITTER_NAME=$(shell git config user.name)" \
  77. --env "GIT_COMMITTER_EMAIL=$(shell git config user.email)" \
  78. --env "GITHUB_TOKEN=$(GITHUB_TOKEN)" \
  79. $(MKDOCS_IMAGE) \
  80. $(SHELL) -c "cd /repo && $(MIKE) deploy --update-aliases -p -F hack/api-docs/mkdocs.yml $(DOCS_VERSION) $(DOCS_ALIAS);"
  81. .PHONY: generate
  82. generate: $(GEN_CRD_API_REFERENCE_DOCS)
  83. GEN_CRD_API_REFERENCE_DOCS=$(GEN_CRD_API_REFERENCE_DOCS) ./generate.sh $(SRCDIR)/api/spec.md
  84. $(GEN_CRD_API_REFERENCE_DOCS): $(ROOT)/hack/tools/gen-crd-api-reference-docs/go.mod $(ROOT)/hack/tools/gen-crd-api-reference-docs/go.sum $(ROOT)/Makefile
  85. $(MAKE) -C $(ROOT) GEN_CRD_API_REFERENCE_DOCS=$(GEN_CRD_API_REFERENCE_DOCS) gen-crd-api-reference-docs
  86. .PHONY: clean
  87. clean:
  88. rm -r $(GENROOT)/* || true
  89. # serve runs mkdocs as a local webserver for interactive development.
  90. # This will serve the live copy of the docs on 127.0.0.1:8000.
  91. .PHONY: serve
  92. serve: image generate
  93. $(DOCKER) run \
  94. -it \
  95. --sig-proxy=true \
  96. --mount type=bind,source=$(ROOT),target=/repo \
  97. --user $(UID):$(GID) \
  98. -p $(SERVE_BIND_ADDRESS):8000:8000 \
  99. --rm \
  100. $(MKDOCS_IMAGE) \
  101. $(SHELL) -c "cd /repo && mkdocs serve -f hack/api-docs/mkdocs.yml -a 0.0.0.0:8000 --livereload"