Makefile 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 ?= github.com/external-secrets-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. VERSION_TO_CHECK ?= $(shell echo $(MAJOR_VERSION).$(MINOR_VERSION))
  23. DOCS_ALIAS ?= unstable
  24. SERVE_BIND_ADDRESS ?= 127.0.0.1
  25. # TOP is the current directory where this Makefile lives.
  26. TOP := $(dir $(firstword $(MAKEFILE_LIST)))
  27. # ROOT is the repository root.
  28. ROOT := $(abspath $(TOP))/../../
  29. SRCDIR := $(ROOT)/docs
  30. CFGFILE := $(ROOT)/hack/api-docs/mkdocs.yml
  31. # GENROOT is the root of the generated documentation.
  32. GENROOT := $(ROOT)/site
  33. # Grab the uid/gid to fix permissions due to running in a docker container.
  34. GID := $(shell id -g)
  35. UID := $(shell id -u)
  36. # SOURCES is a list of a source files used to generate the documentation.
  37. SOURCES := $(shell find $(SRCDIR) -name \*.md)
  38. SOURCES += mkdocs.yml Makefile
  39. # entrypoint
  40. all: build
  41. .PHONY: image
  42. image:
  43. $(DOCKER) build -t $(MKDOCS_IMAGE) -f Dockerfile .
  44. VERSION_TO_UPDATE ?= $(shell echo $(MAJOR_VERSION).$(MINOR_VERSION).x)
  45. .PHONY: stability-support.update
  46. stability-support.update:
  47. ROOT=$(ROOT) ./add_eso_version.sh $(VERSION_TO_UPDATE)
  48. .PHONY: check
  49. check:
  50. @echo "Checking for version: $(VERSION_TO_CHECK)"
  51. cat $(ROOT)/docs/introduction/stability-support.md | grep "$(VERSION_TO_CHECK)"
  52. .PHONY: build
  53. build: image generate $(SOURCES)
  54. mkdir -p $(GENROOT)
  55. $(DOCKER) run \
  56. --mount type=bind,source=$(ROOT),target=/repo \
  57. --sig-proxy=true \
  58. --rm \
  59. --user $(UID):$(GID) \
  60. --env "GIT_COMMITTER_NAME=$(shell git config user.name)" \
  61. --env "GIT_COMMITTER_EMAIL=$(shell git config user.email)" \
  62. $(MKDOCS_IMAGE) \
  63. /bin/bash -c "cd /repo && $(MIKE) deploy --ignore --update-aliases -F hack/api-docs/mkdocs.yml $(DOCS_VERSION) $(DOCS_ALIAS);"
  64. .PHONY: build.publish
  65. build.publish: image generate $(SOURCES)
  66. mkdir -p $(GENROOT)
  67. $(DOCKER) run \
  68. --mount type=bind,source=$(ROOT),target=/repo \
  69. --sig-proxy=true \
  70. --rm \
  71. --user $(UID):$(GID) \
  72. $(MKDOCS_IMAGE) \
  73. /bin/bash -c "cd /repo && $(MIKE) deploy --update-aliases -p -F hack/api-docs/mkdocs.yml $(DOCS_VERSION) $(DOCS_ALIAS);"
  74. .PHONY: generate
  75. generate:
  76. ./generate.sh $(SRCDIR)/api/spec.md
  77. .PHONY: clean
  78. clean:
  79. rm -r $(GENROOT)/* || true
  80. # serve runs mkdocs as a local webserver for interactive development.
  81. # This will serve the live copy of the docs on 127.0.0.1:8000.
  82. .PHONY: serve
  83. serve: build
  84. $(DOCKER) run \
  85. -it \
  86. --sig-proxy=true \
  87. --mount type=bind,source=$(ROOT),target=/repo \
  88. --user $(UID):$(GID) \
  89. -p $(SERVE_BIND_ADDRESS):8000:8000 \
  90. --rm \
  91. $(MKDOCS_IMAGE) \
  92. /bin/bash -c "cd /repo && mkdocs serve -f hack/api-docs/mkdocs.yml -a 0.0.0.0:8000"