Makefile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. DOCKER_BUILD_ARGS ?=
  16. MKDOCS_IMAGE ?= github.com/external-secrets-mkdocs:latest
  17. MKDOCS ?= mkdocs
  18. MIKE ?= mike
  19. DOCS_VERSION ?= main
  20. VERSION_NO_V ?= $(shell echo $(DOCS_VERSION) | cut -d'v' -f2)
  21. MAJOR_VERSION ?= $(shell echo $(VERSION_NO_V) | cut -d'.' -f1)
  22. MINOR_VERSION ?= $(shell echo $(VERSION_NO_V) | cut -d'.' -f2)
  23. DOCS_ALIAS ?= unstable
  24. GITHUB_TOKEN ?= invalid
  25. SERVE_BIND_ADDRESS ?= 127.0.0.1
  26. SHELL := /usr/bin/env bash
  27. # TOP is the current directory where this Makefile lives.
  28. TOP := $(dir $(firstword $(MAKEFILE_LIST)))
  29. # ROOT is the repository root.
  30. ROOT := $(abspath $(TOP))/../../
  31. SRCDIR := $(ROOT)/docs
  32. CFGFILE := $(ROOT)/hack/api-docs/mkdocs.yml
  33. # GENROOT is the root of the generated documentation.
  34. GENROOT := $(ROOT)/site
  35. GIT_DIR := $(shell cd $(ROOT) && git rev-parse --path-format=absolute --git-dir)
  36. GIT_COMMON_DIR := $(shell cd $(ROOT) && git rev-parse --path-format=absolute --git-common-dir)
  37. ifeq ($(shell test -f $(ROOT)/.git && echo true),true)
  38. GIT_METADATA_MOUNTS := \
  39. --mount type=bind,source=$(GIT_DIR),target=$(GIT_DIR) \
  40. --mount type=bind,source=$(GIT_COMMON_DIR),target=$(GIT_COMMON_DIR)
  41. endif
  42. # Grab the uid/gid to fix permissions due to running in a docker container.
  43. GID := $(shell id -g)
  44. UID := $(shell id -u)
  45. # SOURCES is a list of a source files used to generate the documentation.
  46. SOURCES := $(shell find $(SRCDIR) -name \*.md)
  47. SOURCES += mkdocs.yml Makefile
  48. # entrypoint
  49. all: build
  50. .PHONY: image
  51. image:
  52. $(DOCKER) build $(DOCKER_BUILD_ARGS) -t $(MKDOCS_IMAGE) -f Dockerfile .
  53. VERSION_TO_UPDATE ?= $(shell echo $(MAJOR_VERSION).$(MINOR_VERSION).x)
  54. .PHONY: stability-support.update
  55. stability-support.update:
  56. ROOT=$(ROOT) ./add_eso_version.sh $(VERSION_TO_UPDATE)
  57. .PHONY: build
  58. build: image generate $(SOURCES)
  59. mkdir -p $(GENROOT)
  60. $(DOCKER) run \
  61. --mount type=bind,source=$(ROOT),target=/repo \
  62. $(GIT_METADATA_MOUNTS) \
  63. --sig-proxy=true \
  64. --rm \
  65. --env "GIT_COMMITTER_NAME=$(shell git config user.name)" \
  66. --env "GIT_COMMITTER_EMAIL=$(shell git config user.email)" \
  67. --env "GITHUB_TOKEN=$(GITHUB_TOKEN)" \
  68. $(MKDOCS_IMAGE) \
  69. $(SHELL) -c "cd /repo && $(MIKE) deploy --ignore --update-aliases -F hack/api-docs/mkdocs.yml $(DOCS_VERSION) $(DOCS_ALIAS);"
  70. .PHONY: build.publish
  71. build.publish: image generate $(SOURCES)
  72. mkdir -p $(GENROOT)
  73. $(DOCKER) run \
  74. --mount type=bind,source=$(ROOT),target=/repo \
  75. $(GIT_METADATA_MOUNTS) \
  76. --sig-proxy=true \
  77. --rm \
  78. --user $(UID):$(GID) \
  79. --env "GIT_COMMITTER_NAME=$(shell git config user.name)" \
  80. --env "GIT_COMMITTER_EMAIL=$(shell git config user.email)" \
  81. --env "GITHUB_TOKEN=$(GITHUB_TOKEN)" \
  82. $(MKDOCS_IMAGE) \
  83. $(SHELL) -c "cd /repo && $(MIKE) deploy --update-aliases -p -F hack/api-docs/mkdocs.yml $(DOCS_VERSION) $(DOCS_ALIAS);"
  84. .PHONY: generate
  85. generate:
  86. ./generate.sh $(SRCDIR)/api/spec.md
  87. .PHONY: clean
  88. clean:
  89. rm -r $(GENROOT)/* || true
  90. # serve runs mkdocs as a local webserver for interactive development.
  91. # This will serve the live copy of the docs on 127.0.0.1:8000.
  92. .PHONY: serve
  93. serve: image generate
  94. $(DOCKER) run \
  95. -it \
  96. --sig-proxy=true \
  97. --mount type=bind,source=$(ROOT),target=/repo \
  98. $(GIT_METADATA_MOUNTS) \
  99. --user $(UID):$(GID) \
  100. -p $(SERVE_BIND_ADDRESS):8000:8000 \
  101. --rm \
  102. $(MKDOCS_IMAGE) \
  103. $(SHELL) -c "cd /repo && mkdocs serve -f hack/api-docs/mkdocs.yml -a 0.0.0.0:8000 --livereload"