Makefile 3.4 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. 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. # Grab the uid/gid to fix permissions due to running in a docker container.
  36. GID := $(shell id -g)
  37. UID := $(shell id -u)
  38. # SOURCES is a list of a source files used to generate the documentation.
  39. SOURCES := $(shell find $(SRCDIR) -name \*.md)
  40. SOURCES += mkdocs.yml Makefile
  41. # entrypoint
  42. all: build
  43. .PHONY: image
  44. image:
  45. $(DOCKER) build $(DOCKER_BUILD_ARGS) -t $(MKDOCS_IMAGE) -f Dockerfile .
  46. VERSION_TO_UPDATE ?= $(shell echo $(MAJOR_VERSION).$(MINOR_VERSION).x)
  47. .PHONY: stability-support.update
  48. stability-support.update:
  49. ROOT=$(ROOT) ./add_eso_version.sh $(VERSION_TO_UPDATE)
  50. .PHONY: build
  51. build: 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. --env "GIT_COMMITTER_NAME=$(shell git config user.name)" \
  58. --env "GIT_COMMITTER_EMAIL=$(shell git config user.email)" \
  59. --env "GITHUB_TOKEN=$(GITHUB_TOKEN)" \
  60. $(MKDOCS_IMAGE) \
  61. $(SHELL) -c "cd /repo && $(MIKE) deploy --ignore --update-aliases -F hack/api-docs/mkdocs.yml $(DOCS_VERSION) $(DOCS_ALIAS);"
  62. .PHONY: build.publish
  63. build.publish: image generate $(SOURCES)
  64. mkdir -p $(GENROOT)
  65. $(DOCKER) run \
  66. --mount type=bind,source=$(ROOT),target=/repo \
  67. --sig-proxy=true \
  68. --rm \
  69. --user $(UID):$(GID) \
  70. --env "GIT_COMMITTER_NAME=$(shell git config user.name)" \
  71. --env "GIT_COMMITTER_EMAIL=$(shell git config user.email)" \
  72. --env "GITHUB_TOKEN=$(GITHUB_TOKEN)" \
  73. $(MKDOCS_IMAGE) \
  74. $(SHELL) -c "cd /repo && $(MIKE) deploy --update-aliases -p -F hack/api-docs/mkdocs.yml $(DOCS_VERSION) $(DOCS_ALIAS);"
  75. .PHONY: generate
  76. generate:
  77. ./generate.sh $(SRCDIR)/api/spec.md
  78. .PHONY: clean
  79. clean:
  80. rm -r $(GENROOT)/* || true
  81. # serve runs mkdocs as a local webserver for interactive development.
  82. # This will serve the live copy of the docs on 127.0.0.1:8000.
  83. .PHONY: serve
  84. serve: image generate
  85. $(DOCKER) run \
  86. -it \
  87. --sig-proxy=true \
  88. --mount type=bind,source=$(ROOT),target=/repo \
  89. --user $(UID):$(GID) \
  90. -p $(SERVE_BIND_ADDRESS):8000:8000 \
  91. --rm \
  92. $(MKDOCS_IMAGE) \
  93. $(SHELL) -c "cd /repo && mkdocs serve -f hack/api-docs/mkdocs.yml -a 0.0.0.0:8000 --livereload"