Makefile 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. .PHONY: check
  45. check:
  46. @echo "Checking for version: $(VERSION_TO_CHECK)"
  47. cat $(ROOT)/docs/introduction/stability-support.md | grep "$(VERSION_TO_CHECK)"
  48. .PHONY: build
  49. build: image generate $(SOURCES)
  50. mkdir -p $(GENROOT)
  51. $(DOCKER) run \
  52. --mount type=bind,source=$(ROOT),target=/repo \
  53. --sig-proxy=true \
  54. --rm \
  55. --user $(UID):$(GID) \
  56. --env "GIT_COMMITTER_NAME=$(shell git config user.name)" \
  57. --env "GIT_COMMITTER_EMAIL=$(shell git config user.email)" \
  58. $(MKDOCS_IMAGE) \
  59. /bin/bash -c "cd /repo && $(MIKE) deploy --ignore --update-aliases -F hack/api-docs/mkdocs.yml $(DOCS_VERSION) $(DOCS_ALIAS);"
  60. .PHONY: build.publish
  61. build.publish: image generate $(SOURCES)
  62. mkdir -p $(GENROOT)
  63. $(DOCKER) run \
  64. --mount type=bind,source=$(ROOT),target=/repo \
  65. --sig-proxy=true \
  66. --rm \
  67. --user $(UID):$(GID) \
  68. $(MKDOCS_IMAGE) \
  69. /bin/bash -c "cd /repo && $(MIKE) deploy --update-aliases -p -F hack/api-docs/mkdocs.yml $(DOCS_VERSION) $(DOCS_ALIAS);"
  70. .PHONY: generate
  71. generate:
  72. ./generate.sh $(SRCDIR)/api/spec.md
  73. .PHONY: clean
  74. clean:
  75. rm -r $(GENROOT)/* || true
  76. # serve runs mkdocs as a local webserver for interactive development.
  77. # This will serve the live copy of the docs on 127.0.0.1:8000.
  78. .PHONY: serve
  79. serve: build
  80. $(DOCKER) run \
  81. -it \
  82. --sig-proxy=true \
  83. --mount type=bind,source=$(ROOT),target=/repo \
  84. --user $(UID):$(GID) \
  85. -p $(SERVE_BIND_ADDRESS):8000:8000 \
  86. --rm \
  87. $(MKDOCS_IMAGE) \
  88. /bin/bash -c "cd /repo && mkdocs serve -f hack/api-docs/mkdocs.yml -a 0.0.0.0:8000"