Makefile 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. --env GIT_COMMITTER_NAME=$(shell git config user.name) \
  49. --env GIT_COMMITTER_EMAIL=$(shell git config user.email) \
  50. $(MKDOCS_IMAGE) \
  51. /bin/bash -c "cd /repo && $(MIKE) deploy --ignore --update-aliases -F hack/api-docs/mkdocs.yml $(DOCS_VERSION) $(DOCS_ALIAS);"
  52. .PHONY: build.publish
  53. build.publish: 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. $(MKDOCS_IMAGE) \
  61. /bin/bash -c "cd /repo && $(MIKE) deploy --update-aliases -p -F hack/api-docs/mkdocs.yml $(DOCS_VERSION) $(DOCS_ALIAS);"
  62. .PHONY: generate
  63. generate:
  64. ./generate.sh $(SRCDIR)/api/spec.md
  65. .PHONY: clean
  66. clean:
  67. rm -r $(GENROOT)/* || true
  68. # serve runs mkdocs as a local webserver for interactive development.
  69. # This will serve the live copy of the docs on 127.0.0.1:8000.
  70. .PHONY: serve
  71. serve:
  72. $(DOCKER) run \
  73. -it \
  74. --sig-proxy=true \
  75. --mount type=bind,source=$(ROOT),target=/repo \
  76. --user $(UID):$(GID) \
  77. -p $(SERVE_BIND_ADDRESS):8000:8000 \
  78. --rm \
  79. $(MKDOCS_IMAGE) \
  80. /bin/bash -c "cd /repo && mkdocs serve -f hack/api-docs/mkdocs.yml -a 0.0.0.0:8000"