Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify docs generation & serve #113

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add deploy command & remove unnecessary commands
  • Loading branch information
M00nF1sh committed Mar 5, 2020
commit 2f162f4d382e96cc253d4b41ece601f035b06556
19 changes: 8 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.

all: controller docs
all: controller

# Kubebuilder driven custom resource definitions.
.PHONY: controller
controller:
make -f kubebuilder.mk

# Build the documentation.
.PHONY: docs
docs:
make -f docs.mk

# Serve the docs site locally at http://localhost:8000.
.PHONY: serve
serve:
.PHONY: docs-serve
docs-serve:
make -f docs.mk serve

.PHONY: clean
clean:
make -f docs.mk clean
# deploy will publish generated docs into gh-pages branch.
# ```GITHUB_USER=<> GITHUB_TOKEN=<> make docs-deploy```
.PHONY: docs-deploy
docs-deploy:
make -f docs.mk deploy

# Install the CRD's and example resources to a pre-existing cluster.
.PHONY: install
Expand Down
57 changes: 18 additions & 39 deletions docs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,66 +25,34 @@ SERVE_BIND_ADDRESS ?= 127.0.0.1
TOP := $(dir $(firstword $(MAKEFILE_LIST)))
# DOCROOT is the root of the mkdocs tree.
DOCROOT := $(abspath $(TOP))
# GENROOT is the root of the generated documentation.
GENROOT := $(DOCROOT)/docs

# Grab the uid/gid to fix permissions due to running in a docker container.
GID := $(shell id -g)
UID := $(shell id -u)

# SOURCES is a list of a source files used to generate the documentation.
SOURCES := $(shell find $(DOCROOT)/docs-src -name \*.md)
SOURCES += mkdocs.yml docs.mk

# entrypoint
all: .mkdocs.timestamp

# Support docker images.
.PHONY: images
images: .mkdocs.dockerfile.timestamp

# build the image for mkdocs
.mkdocs.dockerfile.timestamp: mkdocs.dockerfile
.mkdocs.dockerfile.timestamp: mkdocs.dockerfile mkdocs.requirements.txt
docker build -t $(MKDOCS_IMAGE) -f mkdocs.dockerfile .
date > $@

# generate the `docs` from SOURCES
.mkdocs.timestamp: images $(SOURCES)
$(DOCKER) run \
--mount type=bind,source=$(DOCROOT),target=/d \
--sig-proxy=true \
--rm \
$(MKDOCS_IMAGE) \
/bin/bash -c "cd /d && $(MKDOCS) build; find /d/docs -exec chown $(UID):$(GID) {} \;"
# Remove sitemap as it contains the timestamp, which is a source of a lot
# of merge conflicts.
rm docs/sitemap.xml docs/sitemap.xml.gz
date > $@

# verify that the docs can be successfully built
.PHONY: verify
# verify that the docs have been properly updated.
#
# docs-src/.mkdocs-exclude contains a list of `diff -X` files to
# exclude from the verification diff.
verify: images
$(DOCKER) run \
--mount type=bind,source=$(DOCROOT),target=/d \
--sig-proxy=true \
--rm \
$(MKDOCS_IMAGE) \
/bin/bash -c "cd /d && $(MKDOCS) build --site-dir=/tmp/d && diff -X /d/docs-src/.mkdocs-exclude -qr /d/docs /tmp/d"

# clean deletes generated files
.PHONY: clean
clean:
test -f .mkdocs.timestamp && rm .mkdocs.timestamp || true
test -f .mkdocs.dockerfile.timestamp && rm .mkdocs.dockerfile.timestamp || true
rm -r $(GENROOT)/* || true
/bin/bash -c "cd /d && $(MKDOCS) build --site-dir=/tmp/d"

# serve runs mkdocs as a local webserver for interactive development.
# This will serve the live copy of the docs on 127.0.0.1:8000.
.PHONY: images serve
serve:
.PHONY: serve
serve: images
$(DOCKER) run \
-it \
--sig-proxy=true \
Expand All @@ -94,15 +62,27 @@ serve:
$(MKDOCS_IMAGE) \
/bin/bash -c "cd /d && $(MKDOCS) serve -a 0.0.0.0:8000"

# deploy will publish generated docs into gh-pages branch.
.PHONY: deploy
deploy: images
$(DOCKER) run \
-it \
--sig-proxy=true \
--mount type=bind,source=$(DOCROOT),target=/d \
--rm \
$(MKDOCS_IMAGE) \
/bin/bash -c "cd /d && git config --global url."https://$$GITHUB_USER:$$GITHUB_TOKEN@github.com/".pushInsteadOf "https://github.com/" && $(MKDOCS) gh-deploy --site-dir=/tmp/d"

# help prints usage for this Makefile.
.PHONY: help
help:
@echo "Usage:"
@echo ""
@echo "make Build the documentation"
@echo "make help Print this help message"
@echo "make clean Delete generated files"
@echo "make verify Verify docs can be successfully generated"
@echo "make serve Run the webserver for live editing (ctrl-C to quit)"
@echo "make deploy Deploy generated docs into gh-pages branch"

# init creates a new mkdocs template. This is included for completeness.
.PHONY: images init
Expand All @@ -113,4 +93,3 @@ init:
--rm \
$(MKDOCS_IMAGE) \
/bin/bash -c "$(MKDOCS) new d; find /d -exec chown $(UID):$(GID) {} \;"

6 changes: 0 additions & 6 deletions docs/.mkdocs-exclude

This file was deleted.

2 changes: 2 additions & 0 deletions mkdocs.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ RUN apk add -U --no-cache \
python3 \
bash \
diffutils \
git \
git-fast-import \
&& pip3 install -r /mkdocs.requirements.txt
18 changes: 10 additions & 8 deletions mkdocs.requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
Click==7.0
future==0.18.2
htmlmin==0.1.12
Jinja2==2.10.3
Jinja2==2.11.1
jsmin==2.2.2
livereload==2.6.1
Markdown==3.1.1
lunr==0.5.6
Markdown==3.2.1
MarkupSafe==1.1.1
mkdocs==1.0.4
mkdocs-material==4.6.0
mkdocs-minify-plugin==0.2.1
pep562==1.0
mkdocs==1.1
mkdocs-material==4.6.3
mkdocs-minify-plugin==0.2.3
nltk==3.4.5
Pygments==2.5.2
pymdown-extensions==6.2.1
pymdown-extensions==6.3
PyYAML==5.3
six==1.14.0
tornado==6.0.3
tornado==6.0.3
4 changes: 2 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
site_name: Kubernetes Service API Evolution
repo_url: http://sigs.k8s.io/service-apis
site_dir: docs
docs_dir: docs-src
strict: true

theme:
name: material
nav:
Expand Down