Makefile 2.7 KB

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