From b63fdd2137940e6e425c146f1564b9def457818d Mon Sep 17 00:00:00 2001 From: Carlos Salas Date: Tue, 6 Feb 2024 11:24:15 +0100 Subject: [PATCH] docs: basic netlify configuration for book Signed-off-by: Carlos Salas --- docs/book/Makefile | 43 ++++++++++++++++++++++++++++ hack/tools/Makefile | 69 +++++++++++++++++++++++++++++++++++++++++++++ hack/tools/go.mod | 5 ++++ hack/tools/go.sum | 6 ++++ hack/tools/tools.go | 2 ++ netlify.toml | 27 ++++++++++++++++++ 6 files changed, 152 insertions(+) create mode 100644 docs/book/Makefile create mode 100644 hack/tools/Makefile create mode 100644 netlify.toml diff --git a/docs/book/Makefile b/docs/book/Makefile new file mode 100644 index 000000000..8ad609233 --- /dev/null +++ b/docs/book/Makefile @@ -0,0 +1,43 @@ +# Copyright 2024 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Directories. +ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) +TOOLS_DIR := $(realpath ../../hack/tools) +TOOLS_BIN_DIR := $(TOOLS_DIR)/bin +BIN_DIR := bin +MDBOOK_INSTALL := $(realpath ../../scripts/ci-install-mdbook.sh) +TABULATE := $(TOOLS_BIN_DIR)/mdbook-tabulate +EMBED := $(TOOLS_BIN_DIR)/mdbook-embed +RELEASELINK := $(TOOLS_BIN_DIR)/mdbook-releaselink +MDBOOK := $(TOOLS_BIN_DIR)/mdbook + +export PATH := $(TOOLS_BIN_DIR):$(PATH) + +BOOK_DEPS := $(MDBOOK) $(TABULATE) $(EMBED) $(RELEASELINK) + +$(TOOLS_BIN_DIR)/%: $(TOOLS_DIR_DEPS) + make -C $(TOOLS_DIR) $(subst $(TOOLS_DIR)/,,$@) + +.PHONY: serve +serve: $(BOOK_DEPS) ## Run a local web server with the compiled book + $(MDBOOK) serve + +.PHONY: build +build: $(BOOK_DEPS) ## Build the book + $(MDBOOK) build + +.PHONY: clean +clean: + rm -rf book diff --git a/hack/tools/Makefile b/hack/tools/Makefile new file mode 100644 index 000000000..879b093c7 --- /dev/null +++ b/hack/tools/Makefile @@ -0,0 +1,69 @@ +# Copyright 2024 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ROOT_DIR_RELATIVE := ../.. + +UNAME := $(shell uname -s) + +OS := $(shell go env GOOS) +RUST_TARGET := unknown-$(OS)-gnu + +ifeq ($(OS), darwin) + RUST_TARGET := apple-darwin + GH_ARCH_SUFFIX := macOS_amd64 + GTAR := gtar +endif + +# Directories. +BIN_DIR := bin +BIN_DIR_ABS := $(abspath $(BIN_DIR)) +SHARE_DIR := share + +MDBOOK_EXTRACT_COMMAND := tar xfvz $(SHARE_DIR)/mdbook.tar.gz -C bin +MDBOOK_ARCHIVE_EXT := .tar.gz + +MDBOOK_VERSION := v0.4.5 + +# Tooling binaries. +$(BIN_DIR): + mkdir -p $@ + +$(SHARE_DIR): + mkdir -p $@ + +# Binaries. +MDBOOK := $(BIN_DIR)/mdbook +MDBOOK_SHARE := $(SHARE_DIR)/mdbook$(MDBOOK_ARCHIVE_EXT) +$(MDBOOK): $(BIN_DIR) $(SHARE_DIR) + curl -sL -o $(MDBOOK_SHARE) "https://github.com/rust-lang/mdBook/releases/download/$(MDBOOK_VERSION)/mdBook-$(MDBOOK_VERSION)-x86_64-$(RUST_TARGET)$(MDBOOK_ARCHIVE_EXT)" + $(MDBOOK_EXTRACT_COMMAND) + chmod +x $@ + touch -m $@ + +MDBOOK_EMBED := $(BIN_DIR)/mdbook-embed +$(MDBOOK_EMBED): $(BIN_DIR) go.mod go.sum + go build -tags=tools -o $(BIN_DIR)/mdbook-embed sigs.k8s.io/cluster-api/hack/tools/mdbook/embed + +MDBOOK_RELEASELINK := $(BIN_DIR)/mdbook-releaselink +$(MDBOOK_RELEASELINK): $(BIN_DIR) go.mod go.sum + go build -tags=tools -o $(BIN_DIR)/mdbook-releaselink sigs.k8s.io/cluster-api/hack/tools/mdbook/releaselink + +MDBOOK_TABULATE := $(BIN_DIR)/mdbook-tabulate +$(MDBOOK_TABULATE): $(BIN_DIR) go.mod go.sum + go build -tags=tools -o $(BIN_DIR)/mdbook-tabulate sigs.k8s.io/cluster-api/hack/tools/mdbook/tabulate + +.PHONY: clean +clean: ## Remove all tools + rm -rf bin + rm -rf share diff --git a/hack/tools/go.mod b/hack/tools/go.mod index 53ba5feb0..dfc1e8f5d 100644 --- a/hack/tools/go.mod +++ b/hack/tools/go.mod @@ -4,9 +4,12 @@ go 1.21 toolchain go1.21.6 +replace sigs.k8s.io/cluster-api => sigs.k8s.io/cluster-api v1.6.1 + require sigs.k8s.io/cluster-api/hack/tools v0.0.0-20240116064735-bfe8d0d16ff3 require ( + github.com/blang/semver/v4 v4.0.0 // indirect github.com/go-logr/logr v1.4.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/google/gofuzz v1.2.0 // indirect @@ -26,7 +29,9 @@ require ( k8s.io/apimachinery v0.28.5 // indirect k8s.io/klog/v2 v2.100.1 // indirect k8s.io/utils v0.0.0-20231127182322-b307cd553661 // indirect + sigs.k8s.io/cluster-api v0.0.0-00010101000000-000000000000 // indirect sigs.k8s.io/controller-tools v0.13.0 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect + sigs.k8s.io/kubebuilder/docs/book/utils v0.0.0-20211028165026-57688c578b5d // indirect sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect ) diff --git a/hack/tools/go.sum b/hack/tools/go.sum index 60529384e..eb98c8ed1 100644 --- a/hack/tools/go.sum +++ b/hack/tools/go.sum @@ -1,3 +1,5 @@ +github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= +github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= @@ -106,12 +108,16 @@ k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/utils v0.0.0-20231127182322-b307cd553661 h1:FepOBzJ0GXm8t0su67ln2wAZjbQ6RxQGZDnzuLcrUTI= k8s.io/utils v0.0.0-20231127182322-b307cd553661/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +sigs.k8s.io/cluster-api v1.6.1 h1:I34p/fwgRlEhs+o9cUhKXDwNNfPS3no0yJsd2bJyQVc= +sigs.k8s.io/cluster-api v1.6.1/go.mod h1:DaxwruDvSaEYq5q6FREDaGzX6UsAVUCA99Sp8vfMHyQ= sigs.k8s.io/cluster-api/hack/tools v0.0.0-20240116064735-bfe8d0d16ff3 h1:pbVMlqGtkJvCBYntRFIEsvOIGzoTTJtjW1hBEoZMSYk= sigs.k8s.io/cluster-api/hack/tools v0.0.0-20240116064735-bfe8d0d16ff3/go.mod h1:1p1NPNOaoJmhqeNiXzNvRMOEFSdJhOwSJtSyfwigFMA= sigs.k8s.io/controller-tools v0.13.0 h1:NfrvuZ4bxyolhDBt/rCZhDnx3M2hzlhgo5n3Iv2RykI= sigs.k8s.io/controller-tools v0.13.0/go.mod h1:5vw3En2NazbejQGCeWKRrE7q4P+CW8/klfVqP8QZkgA= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= +sigs.k8s.io/kubebuilder/docs/book/utils v0.0.0-20211028165026-57688c578b5d h1:KLiQzLW3RZJR19+j4pw2h5iioyAyqCkDBEAFdnGa3N8= +sigs.k8s.io/kubebuilder/docs/book/utils v0.0.0-20211028165026-57688c578b5d/go.mod h1:NRdZafr4zSCseLQggdvIMXa7umxf+Q+PJzrj3wFwiGE= sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE= sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E= sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= diff --git a/hack/tools/tools.go b/hack/tools/tools.go index 7379189f3..40a452f34 100644 --- a/hack/tools/tools.go +++ b/hack/tools/tools.go @@ -19,4 +19,6 @@ package tools import ( _ "sigs.k8s.io/cluster-api/hack/tools/conversion-verifier" + _ "sigs.k8s.io/cluster-api/hack/tools/mdbook/embed" + _ "sigs.k8s.io/cluster-api/hack/tools/mdbook/releaselink" ) diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 000000000..c39e6d2cf --- /dev/null +++ b/netlify.toml @@ -0,0 +1,27 @@ +# Netlify build instructions +[build] + command = "make -C docs/book build" + publish = "docs/book/book" + +[build.environment] + GO_VERSION = "1.21" + +# Standard Netlify redirects +[[redirects]] + from = "https://main--cluster-api-gcp.netlify.com/*" + to = "https://main.cluster-api-gcp.sigs.k8s.io/:splat" + status = 301 + force = true + +# HTTP-to-HTTPS rules +[[redirects]] + from = "http://main.cluster-api-gcp.sigs.k8s.io/*" + to = "https://main.cluster-api-gcp.sigs.k8s.io/:splat" + status = 301 + force = true + +[[redirects]] + from = "http://main--cluster-api-gcp.netlify.com/*" + to = "http://main.cluster-api-gcp.sigs.k8s.io/:splat" + status = 301 + force = true