Merge pull request #982 from munnerz/refdocs-bazel
Run all reference docs generation with Bazel
This commit is contained in:
commit
80ea8e7444
15
WORKSPACE
15
WORKSPACE
@ -157,6 +157,17 @@ filegroup(
|
||||
srcs = glob(["**/*"]),
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "static",
|
||||
srcs = [
|
||||
"stylesheet.css",
|
||||
"scroll.js",
|
||||
"actions.js",
|
||||
"tabvisibility.js",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
""",
|
||||
)
|
||||
|
||||
@ -164,7 +175,7 @@ filegroup(
|
||||
git_repository(
|
||||
name = "build_bazel_rules_nodejs",
|
||||
remote = "https://github.com/bazelbuild/rules_nodejs.git",
|
||||
tag = "0.11.5", # check for the latest tag when you install
|
||||
tag = "0.15.0", # check for the latest tag when you install
|
||||
)
|
||||
|
||||
load("@build_bazel_rules_nodejs//:package.bzl", "rules_nodejs_dependencies")
|
||||
@ -182,7 +193,7 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "npm_install")
|
||||
npm_install(
|
||||
name = "brodocs_modules",
|
||||
package_json = "@brodocs//:package.json",
|
||||
package_lock_json = "//hack/brodocs:package-lock.json",
|
||||
package_lock_json = "//hack/reference-docs/bin:package-lock.json",
|
||||
)
|
||||
|
||||
# Load kubernetes-incubator/reference-docs, to be used as part of the docs
|
||||
|
||||
3
docs/generated/reference/.gitignore
vendored
3
docs/generated/reference/.gitignore
vendored
@ -1,3 +0,0 @@
|
||||
/manifest.json
|
||||
/openapi-spec
|
||||
/includes
|
||||
@ -1,25 +1,3 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["main.go"],
|
||||
importpath = "github.com/jetstack/cert-manager/docs/generated/reference",
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"//docs/generated/reference/openapi:go_default_library",
|
||||
"//vendor/github.com/go-openapi/spec:go_default_library",
|
||||
"//vendor/k8s.io/kube-openapi/pkg/common:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "reference",
|
||||
embed = [":go_default_library"],
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
@ -29,11 +7,7 @@ filegroup(
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [
|
||||
":package-srcs",
|
||||
"//docs/generated/reference/openapi:all-srcs",
|
||||
"//docs/generated/reference/swagger-gen:all-srcs",
|
||||
],
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["openapi_generated.go"],
|
||||
importpath = "github.com/jetstack/cert-manager/docs/generated/reference/openapi",
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//vendor/github.com/go-openapi/spec:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/kube-openapi/pkg/common:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
File diff suppressed because it is too large
Load Diff
0
docs/generated/reference/output/reference/api-docs/index.html
Normal file → Executable file
0
docs/generated/reference/output/reference/api-docs/index.html
Normal file → Executable file
0
docs/generated/reference/output/reference/api-docs/navData.js
Normal file → Executable file
0
docs/generated/reference/output/reference/api-docs/navData.js
Normal file → Executable file
@ -1,60 +0,0 @@
|
||||
/*
|
||||
Copyright 2018 The Jetstack cert-manager contributors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/go-openapi/spec"
|
||||
"k8s.io/kube-openapi/pkg/common"
|
||||
|
||||
"github.com/jetstack/cert-manager/docs/generated/reference/openapi"
|
||||
)
|
||||
|
||||
func main() {
|
||||
WriteOpenAPI(openapi.GetOpenAPIDefinitions)
|
||||
}
|
||||
|
||||
// WriteOpenAPI writes the openapi json to docs/reference/openapi-spec/swagger.json
|
||||
func WriteOpenAPI(openapi func(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition) {
|
||||
defs := openapi(func(name string) spec.Ref {
|
||||
parts := strings.Split(name, "/")
|
||||
return spec.MustCreateRef(fmt.Sprintf("#/definitions/%s.%s",
|
||||
common.EscapeJsonPointer(parts[len(parts)-2]),
|
||||
common.EscapeJsonPointer(parts[len(parts)-1])))
|
||||
})
|
||||
|
||||
o, err := json.MarshalIndent(defs, "", " ")
|
||||
if err != nil {
|
||||
log.Fatalf("Could not Marshal JSON %v\n%v", err, defs)
|
||||
}
|
||||
|
||||
// wd, err := os.Getwd()
|
||||
// if err != nil {
|
||||
// log.Fatalf("Error getting working directory: %v", err)
|
||||
// }
|
||||
|
||||
_, err = os.Stdout.Write(o)
|
||||
// err = ioutil.WriteFile(filepath.Join(wd, "docs", "generated", "reference", "openapi-spec", "swagger.json"), o, 0700)
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
}
|
||||
}
|
||||
@ -114,14 +114,11 @@ sh_test(
|
||||
)
|
||||
|
||||
# Reference docs generation rules
|
||||
|
||||
sh_binary(
|
||||
name = "update-reference-docs",
|
||||
srcs = ["update-reference-docs.sh"],
|
||||
data = [
|
||||
"//hack/bin:gen-apidocs",
|
||||
"//hack/bin:swagger-gen",
|
||||
"//hack/brodocs",
|
||||
"//hack/reference-docs",
|
||||
],
|
||||
deps = [
|
||||
"@bazel_tools//tools/bash/runfiles",
|
||||
@ -132,8 +129,9 @@ sh_test(
|
||||
name = "verify-reference-docs",
|
||||
srcs = ["verify-reference-docs.sh"],
|
||||
data = [
|
||||
":update-reference-docs",
|
||||
"//:all-srcs",
|
||||
"//docs/generated/reference:all-srcs",
|
||||
"//hack:update-reference-docs.sh",
|
||||
"//hack/reference-docs",
|
||||
],
|
||||
deps = [
|
||||
"@bazel_tools//tools/bash/runfiles",
|
||||
@ -172,8 +170,8 @@ filegroup(
|
||||
":package-srcs",
|
||||
"//hack/bin:all-srcs",
|
||||
"//hack/boilerplate:all-srcs",
|
||||
"//hack/brodocs:all-srcs",
|
||||
"//hack/deploy:all-srcs",
|
||||
"//hack/reference-docs:all-srcs",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
|
||||
@ -55,24 +55,6 @@ genrule(
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
# We include these rules here to make PATH mapping easier, and to provide a
|
||||
# stable arch-independent target for generating swagger.json & apidocs.
|
||||
genrule(
|
||||
name = "fetch_swagger-gen",
|
||||
srcs = ["//docs/generated/reference/swagger-gen"],
|
||||
outs = ["swagger-gen"],
|
||||
cmd = "cp $(SRCS) $@",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
genrule(
|
||||
name = "fetch_gen-apidocs",
|
||||
srcs = ["@io_kubernetes_incubator_reference_docs//gen-apidocs"],
|
||||
outs = ["gen-apidocs"],
|
||||
cmd = "cp $(SRCS) $@",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "k8",
|
||||
values = {"host_cpu": "k8"},
|
||||
|
||||
104
hack/reference-docs/BUILD.bazel
Normal file
104
hack/reference-docs/BUILD.bazel
Normal file
@ -0,0 +1,104 @@
|
||||
genrule(
|
||||
name = "__internal_markdown_tar",
|
||||
srcs = [
|
||||
"//hack/reference-docs:config.yaml",
|
||||
"//hack/reference-docs/static_includes:all-srcs",
|
||||
"//hack/reference-docs/json_swagger:swagger.json",
|
||||
],
|
||||
outs = ["defs.tar.gz"],
|
||||
cmd = "; ".join([
|
||||
"tmpdir=$$(mktemp -d)",
|
||||
"mkdir -p \"$$tmpdir/static_includes/\"",
|
||||
"mkdir -p \"$$tmpdir/includes/\"",
|
||||
"mkdir -p \"$$tmpdir/openapi-spec/\"",
|
||||
"cp -L \"$(location //hack/reference-docs/json_swagger:swagger.json)\" \"$$tmpdir/openapi-spec/\"",
|
||||
"cp -L \"$(location //hack/reference-docs:config.yaml)\" \"$$tmpdir/\"",
|
||||
"cp -LR $(locations //hack/reference-docs/static_includes:all-srcs) \"$$tmpdir/static_includes/\"",
|
||||
"rm \"$$tmpdir/static_includes/BUILD.bazel\"",
|
||||
"$(location @io_kubernetes_incubator_reference_docs//gen-apidocs) --copyright \"<a href=\\\"https://jetstack.io\\\">Copyright 2018 Jetstack Ltd.</a>\" --title \"Cert-manager API Reference\" -config-dir $$tmpdir",
|
||||
"orig=$$(pwd)",
|
||||
"cd $$tmpdir",
|
||||
"tar -cf \"$$orig/$@\" ./manifest.json ./includes/",
|
||||
]),
|
||||
tools = [
|
||||
"@io_kubernetes_incubator_reference_docs//gen-apidocs",
|
||||
],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
genrule(
|
||||
name = "__internal_brodocs_out",
|
||||
srcs = [
|
||||
"//hack/reference-docs:__internal_markdown_tar",
|
||||
],
|
||||
outs = [
|
||||
"index.html",
|
||||
"navData.js",
|
||||
],
|
||||
cmd = "; ".join([
|
||||
"input=$$(mktemp -d)",
|
||||
"output=$$(mktemp -d)",
|
||||
"tar -C \"$$input\" -xf $(location //hack/reference-docs:__internal_markdown_tar)",
|
||||
"$(location //hack/reference-docs/bin:brodocs) \"$$input/manifest.json\" \"$$input/includes\" \"$$output\"",
|
||||
"cp $$output/index.html $(@D)",
|
||||
"cp $$output/navData.js $(@D)",
|
||||
]),
|
||||
tools = [
|
||||
"//hack/reference-docs/bin:brodocs",
|
||||
],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
# This file constructs an archive containing the full generated reference docs
|
||||
# website, including all required node_modules.
|
||||
# The output this script is then consumed by the hack/update-reference-docs.sh
|
||||
# to place the data into the correct directory to be displayed by readthedocs.
|
||||
genrule(
|
||||
name = "reference-docs",
|
||||
srcs = [
|
||||
":__internal_brodocs_out",
|
||||
"@brodocs//:static",
|
||||
"@brodocs_modules//node_modules/jquery:jquery__files",
|
||||
"@brodocs_modules//node_modules/bootstrap:bootstrap__files",
|
||||
"@brodocs_modules//node_modules/font-awesome:font-awesome__files",
|
||||
"@brodocs_modules//node_modules/highlight.js:highlight.js__files",
|
||||
"@brodocs_modules//node_modules/jquery.scrollto:jquery.scrollto__files",
|
||||
],
|
||||
outs = ["generated.tar.gz"],
|
||||
cmd = "; ".join([
|
||||
"bm=external/brodocs_modules",
|
||||
"out=$$(mktemp -d)",
|
||||
"cp -L $(locations :__internal_brodocs_out) $$out",
|
||||
"cp -L $(locations @brodocs//:static) $$out",
|
||||
"p=node_modules/jquery/dist; mkdir -p $$out/$$p && cp -L $$bm/$$p/jquery.min.js $$out/$$p",
|
||||
"p=node_modules/bootstrap/dist/css; mkdir -p $$out/$$p && cp -L $$bm/$$p/bootstrap.min.css $$out/$$p",
|
||||
"p=node_modules/font-awesome/css; mkdir -p $$out/$$p && cp -L $$bm/$$p/* $$out/$$p",
|
||||
"p=node_modules/font-awesome/fonts; mkdir -p $$out/$$p && cp -L $$bm/$$p/* $$out/$$p",
|
||||
"p=node_modules/highlight.js/styles; mkdir -p $$out/$$p && cp -L $$bm/$$p/default.css $$out/$$p",
|
||||
"p=node_modules/jquery.scrollto; mkdir -p $$out/$$p && cp -L $$bm/$$p/jquery.scrollTo.min.js $$out/$$p",
|
||||
"orig=$$(pwd)",
|
||||
"cd $$out",
|
||||
"tar -cf $$orig/$@ ./",
|
||||
]),
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [
|
||||
":package-srcs",
|
||||
"//hack/reference-docs/bin:all-srcs",
|
||||
"//hack/reference-docs/go_openapi:all-srcs",
|
||||
"//hack/reference-docs/json_swagger:all-srcs",
|
||||
"//hack/reference-docs/static_includes:all-srcs",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
@ -3,7 +3,6 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
|
||||
nodejs_binary(
|
||||
name = "brodocs",
|
||||
data = [
|
||||
"//docs/generated/reference:all-srcs",
|
||||
"@brodocs//:all-srcs",
|
||||
],
|
||||
entry_point = "brodocs/brodoc",
|
||||
@ -1,10 +1,10 @@
|
||||
example_location: "examples"
|
||||
api_groups:
|
||||
api_groups:
|
||||
- "Certmanager"
|
||||
resource_categories:
|
||||
resource_categories:
|
||||
- name: "Certmanager"
|
||||
include: "certmanager"
|
||||
resources:
|
||||
resources:
|
||||
- name: "Certificate"
|
||||
version: "v1alpha1"
|
||||
group: "certmanager"
|
||||
33
hack/reference-docs/go_openapi/BUILD.bazel
Normal file
33
hack/reference-docs/go_openapi/BUILD.bazel
Normal file
@ -0,0 +1,33 @@
|
||||
# gazelle:exclude doc.go
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load("//hack/reference-docs/go_openapi:def.bzl", "openapi_library")
|
||||
|
||||
openapi_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["doc.go"],
|
||||
go_prefix = "github.com/jetstack/cert-manager/",
|
||||
openapi_targets = [
|
||||
"pkg/apis/certmanager/v1alpha1",
|
||||
],
|
||||
tags = ["manual"],
|
||||
vendor_targets = [
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1",
|
||||
"k8s.io/apimachinery/pkg/runtime",
|
||||
"k8s.io/apimachinery/pkg/version",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
52
hack/reference-docs/go_openapi/def.bzl
Normal file
52
hack/reference-docs/go_openapi/def.bzl
Normal file
@ -0,0 +1,52 @@
|
||||
# Copyright 2018 The Jetstack cert-manager contributors.
|
||||
#
|
||||
# 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.
|
||||
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
load("@io_kubernetes_build//defs:go.bzl", "go_genrule")
|
||||
|
||||
def openapi_library(name, tags, srcs, go_prefix, openapi_targets = [], vendor_targets = []):
|
||||
deps = [
|
||||
"//vendor/github.com/go-openapi/spec:go_default_library",
|
||||
"//vendor/k8s.io/kube-openapi/pkg/common:go_default_library",
|
||||
] + ["//%s:go_default_library" % target for target in openapi_targets] + ["//vendor/%s:go_default_library" % target for target in vendor_targets]
|
||||
go_library(
|
||||
name = name,
|
||||
srcs = srcs + [":zz_generated.openapi"],
|
||||
importpath = go_prefix + "hack/reference-docs/go_openapi",
|
||||
tags = tags,
|
||||
deps = deps,
|
||||
)
|
||||
go_genrule(
|
||||
name = "zz_generated.openapi",
|
||||
srcs = ["//hack/boilerplate:boilerplate.go.txt"],
|
||||
outs = ["zz_generated.openapi.go"],
|
||||
# In order for vendored dependencies to be imported correctly,
|
||||
# the generator must run from the repo root inside the generated GOPATH.
|
||||
# All of bazel's $(location)s are relative to the original working directory, however,
|
||||
# so we must save it first.
|
||||
cmd = " ".join([
|
||||
"cd $$GOPATH/src/" + go_prefix + ";",
|
||||
"$$GO_GENRULE_EXECROOT/$(location //vendor/k8s.io/kube-openapi/example/openapi-gen)",
|
||||
"--v 1",
|
||||
"--logtostderr",
|
||||
"--go-header-file $$GO_GENRULE_EXECROOT/$(location //hack/boilerplate:boilerplate.go.txt)",
|
||||
"--output-file-base zz_generated.openapi",
|
||||
"--output-package " + go_prefix + "hack/reference-docs/go_openapi",
|
||||
# "--report-filename tmp_api_violations.report",
|
||||
"--input-dirs " + ",".join([go_prefix + target for target in openapi_targets] + [go_prefix + "vendor/" + target for target in vendor_targets]),
|
||||
"&& cp $$GOPATH/src/" + go_prefix + "hack/reference-docs/go_openapi/zz_generated.openapi.go $$GO_GENRULE_EXECROOT/$(location :zz_generated.openapi.go)",
|
||||
]),
|
||||
go_deps = deps,
|
||||
tools = ["//vendor/k8s.io/kube-openapi/example/openapi-gen"],
|
||||
)
|
||||
18
hack/reference-docs/go_openapi/doc.go
Normal file
18
hack/reference-docs/go_openapi/doc.go
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
Copyright 2018 The Jetstack cert-manager contributors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Package go_openapi describes OpenAPI type defintions for cert-manager APIs
|
||||
package go_openapi
|
||||
@ -1,20 +1,5 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
||||
|
||||
exports_files(["config.yaml"])
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["main.go"],
|
||||
importpath = "github.com/jetstack/cert-manager/docs/generated/reference/swagger-gen",
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"//docs/generated/reference/openapi:go_default_library",
|
||||
"//vendor/github.com/go-openapi/spec:go_default_library",
|
||||
"//vendor/k8s.io/kube-openapi/pkg/common:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
@ -29,9 +14,32 @@ filegroup(
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["main.go"],
|
||||
importpath = "github.com/jetstack/cert-manager/hack/reference-docs/json_swagger",
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"//hack/reference-docs/go_openapi:go_default_library",
|
||||
"//vendor/github.com/go-openapi/spec:go_default_library",
|
||||
"//vendor/k8s.io/kube-openapi/pkg/common:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "swagger-gen",
|
||||
name = "generator",
|
||||
embed = [":go_default_library"],
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
genrule(
|
||||
name = "swagger",
|
||||
outs = ["swagger.json"],
|
||||
cmd = "; ".join([
|
||||
"$(locations //hack/reference-docs/json_swagger:generator) > $@",
|
||||
]),
|
||||
tools = [":generator"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
@ -19,15 +19,14 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/go-openapi/spec"
|
||||
"k8s.io/kube-openapi/pkg/common"
|
||||
|
||||
"github.com/jetstack/cert-manager/docs/generated/reference/openapi"
|
||||
openapi "github.com/jetstack/cert-manager/hack/reference-docs/go_openapi"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -47,7 +46,8 @@ func WriteOpenAPI(openapi func(ref common.ReferenceCallback) map[string]common.O
|
||||
if err != nil {
|
||||
log.Fatalf("Could not Marshal JSON %v\n%v", err, defs)
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join("docs", "generated", "reference", "openapi-spec", "swagger.json"), o, 0700)
|
||||
|
||||
_, err = os.Stdout.Write(o)
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
}
|
||||
13
hack/reference-docs/static_includes/BUILD.bazel
Normal file
13
hack/reference-docs/static_includes/BUILD.bazel
Normal file
@ -0,0 +1,13 @@
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
@ -30,20 +30,4 @@ generate-groups.sh "deepcopy,client,informer,lister" \
|
||||
--output-base "${GOPATH}/src/" \
|
||||
--go-header-file "${runfiles}/hack/boilerplate/boilerplate.go.txt"
|
||||
|
||||
OPENAPI_PATH_SEGMENT="docs/generated/reference/openapi"
|
||||
OPENAPI_OUTPUT_DIR="${REPO_ROOT}/${OPENAPI_PATH_SEGMENT}"
|
||||
# Create all required directories
|
||||
mkdir -p "${OPENAPI_OUTPUT_DIR}"
|
||||
if [ ! -f "${OPENAPI_OUTPUT_DIR}/openapi_generated.go" ]; then
|
||||
# Create a placeholder .go file to prevent issues with openapi-gen
|
||||
echo "package openapi" > "${OPENAPI_OUTPUT_DIR}/openapi_generated.go"
|
||||
fi
|
||||
|
||||
echo "+++ Generating openapi_generated.go into 'github.com/jetstack/cert-manager/${OPENAPI_PATH_SEGMENT}'"
|
||||
# Generate Golang types for OpenAPI spec
|
||||
openapi-gen \
|
||||
--input-dirs github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha1,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/version \
|
||||
--go-header-file "${runfiles}/hack/boilerplate/boilerplate.go.txt" \
|
||||
--output-package "github.com/jetstack/cert-manager/${OPENAPI_PATH_SEGMENT}"
|
||||
|
||||
update-bazel.sh
|
||||
|
||||
@ -20,80 +20,16 @@ set -o pipefail
|
||||
|
||||
# This script should be run via `bazel run //hack:update-reference-docs`
|
||||
REPO_ROOT=${BUILD_WORKSPACE_DIRECTORY:-"$(cd "$(dirname "$0")" && pwd -P)"/..}
|
||||
runfiles="${runfiles:-$(pwd)}"
|
||||
export PATH="${runfiles}/hack/bin:${runfiles}/hack/brodocs:${PATH}"
|
||||
SCRIPT_RUNFILES="${runfiles:-$(pwd)}"
|
||||
cd "${REPO_ROOT}"
|
||||
|
||||
REFERENCE_PATH="docs/generated/reference"
|
||||
REFERENCE_ROOT=$(cd "${REPO_ROOT}/${REFERENCE_PATH}" 2> /dev/null && pwd -P)
|
||||
OUTPUT_DIR="${REFERENCE_ROOT}/output/reference/api-docs"
|
||||
# The final directory path to store the generated output data
|
||||
OUTPUT_DIR="$(cd "${REPO_ROOT}/docs/generated/reference/output/reference/api-docs" 2> /dev/null && pwd -P)"
|
||||
|
||||
## cleanup removes files that are leftover from running various tools and not required
|
||||
## for the actual output
|
||||
cleanup() {
|
||||
pushd "${REFERENCE_ROOT}"
|
||||
echo "+++ Cleaning up temporary docsgen files"
|
||||
# Clean up old temporary files
|
||||
rm -Rf "openapi-spec" "includes" "manifest.json"
|
||||
popd
|
||||
}
|
||||
TMP_OUTPUT="$(mktemp -d)"
|
||||
|
||||
tar -C "${TMP_OUTPUT}" -xf "${SCRIPT_RUNFILES}/hack/reference-docs/generated.tar.gz"
|
||||
|
||||
# Ensure we start with a clean set of directories
|
||||
trap cleanup EXIT
|
||||
cleanup
|
||||
echo "+++ Removing old output"
|
||||
rm -Rf "${OUTPUT_DIR}"
|
||||
|
||||
echo "+++ Creating temporary output directories"
|
||||
|
||||
# Generate swagger.json from the Golang generated openapi spec
|
||||
echo "+++ Running 'swagger-gen' to generate swagger.json"
|
||||
mkdir -p "${REFERENCE_ROOT}/openapi-spec"
|
||||
# Generate swagger.json
|
||||
# TODO: can we output to a tmpfile instead of in the repo?
|
||||
swagger-gen > "${REFERENCE_ROOT}/openapi-spec/swagger.json"
|
||||
|
||||
echo "+++ Running gen-apidocs"
|
||||
# Generate Markdown docs
|
||||
gen-apidocs \
|
||||
--copyright "<a href=\"https://jetstack.io\">Copyright 2018 Jetstack Ltd.</a>" \
|
||||
--title "Cert-manager API Reference" \
|
||||
--config-dir "${REFERENCE_ROOT}"
|
||||
|
||||
echo "+++ Running brodocs"
|
||||
mkdir -p "${OUTPUT_DIR}"
|
||||
|
||||
# Running a bazel-built target from the 'bazel run' context has some nuances
|
||||
# which cause runfiles to not be visible properly.
|
||||
# We fudge the vars used by the runfiles loader snippet to point to the correct
|
||||
# runfiles.
|
||||
# We depend on brodocs itself, and include all its dependencies as a dependency
|
||||
# of this target.
|
||||
BRODOCS_RUNFILES="${runfiles}/.."
|
||||
RUNFILES_DIR="${BRODOCS_RUNFILES}" brodocs \
|
||||
"${REFERENCE_ROOT}/manifest.json" \
|
||||
"${REFERENCE_ROOT}/includes" \
|
||||
"${OUTPUT_DIR}"
|
||||
|
||||
BAZEL_BRODOCS_PATH="${BRODOCS_RUNFILES}/brodocs"
|
||||
BAZEL_BRODOCS_NODE_MODULES="${BRODOCS_RUNFILES}/brodocs_modules/node_modules"
|
||||
|
||||
# Copy across support files for docs.
|
||||
# These commands had to be manually written after inspecting the required output.
|
||||
cp "${BAZEL_BRODOCS_PATH}"/stylesheet.css \
|
||||
"${BAZEL_BRODOCS_PATH}"/scroll.js \
|
||||
"${BAZEL_BRODOCS_PATH}"/actions.js \
|
||||
"${BAZEL_BRODOCS_PATH}"/tabvisibility.js \
|
||||
"${OUTPUT_DIR}/"
|
||||
mkdir -p "${OUTPUT_DIR}/node_modules/jquery/dist"
|
||||
cp "${BAZEL_BRODOCS_NODE_MODULES}/jquery/dist/jquery.min.js" "${OUTPUT_DIR}/node_modules/jquery/dist/"
|
||||
mkdir -p "${OUTPUT_DIR}/node_modules/bootstrap/dist/css"
|
||||
cp "${BAZEL_BRODOCS_NODE_MODULES}/bootstrap/dist/css/bootstrap.min.css" "${OUTPUT_DIR}/node_modules/bootstrap/dist/css/"
|
||||
mkdir -p "${OUTPUT_DIR}/node_modules/font-awesome/css"
|
||||
cp "${BAZEL_BRODOCS_NODE_MODULES}/font-awesome/css/"* "${OUTPUT_DIR}/node_modules/font-awesome/css/"
|
||||
mkdir -p "${OUTPUT_DIR}/node_modules/font-awesome/fonts"
|
||||
cp "${BAZEL_BRODOCS_NODE_MODULES}/font-awesome/fonts/"* "${OUTPUT_DIR}/node_modules/font-awesome/fonts/"
|
||||
mkdir -p "${OUTPUT_DIR}/node_modules/highlight.js/styles"
|
||||
cp "${BAZEL_BRODOCS_NODE_MODULES}/highlight.js/styles/default.css" "${OUTPUT_DIR}/node_modules/highlight.js/styles/"
|
||||
mkdir -p "${OUTPUT_DIR}/node_modules/jquery.scrollto"
|
||||
cp "${BAZEL_BRODOCS_NODE_MODULES}/jquery.scrollto/jquery.scrollTo.min.js" "${OUTPUT_DIR}/node_modules/jquery.scrollto/"
|
||||
mv "${TMP_OUTPUT}"/* "${OUTPUT_DIR}"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user