Skip to content

Commit

Permalink
docs: Use bazel to build base rst structure (envoyproxy#16894)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Northey <ryan@synca.io>
  • Loading branch information
phlax authored Jun 10, 2021
1 parent 66751b2 commit 2637d2a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 22 deletions.
4 changes: 4 additions & 0 deletions configs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ licenses(["notice"]) # Apache 2

envoy_package()

exports_files([
"google-vrp/envoy-edge.yaml",
])

py_binary(
name = "configgen",
srcs = ["configgen.py"],
Expand Down
44 changes: 44 additions & 0 deletions docs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ filegroup(
),
)

filegroup(
name = "base_rst_files",
srcs = glob(
[
"conf.py",
"_ext/*",
],
),
)

filegroup(
name = "root_rst_files",
srcs = glob(["root/**/*"]),
)

genrule(
name = "v2_redirects",
outs = ["v2_redirects.txt"],
Expand All @@ -63,3 +78,32 @@ genrule(
":v2_redirects",
],
)

genrule(
name = "google_vrp_config",
outs = ["google_vrp_config.tar"],
cmd = "tar cfh $@ --transform='s/configs/configuration\\/best_practices/' $(location //configs:google-vrp/envoy-edge.yaml)",
tools = [
"//configs:google-vrp/envoy-edge.yaml",
],
)

genrule(
name = "base_rst",
outs = ["base_rst.tar"],
cmd = "tar cfh $@ --transform='s/docs\\///' $(locations base_rst_files) && tar -rh --file=$@ --transform='s/docs\\/root\\///' $(locations root_rst_files) && tar -r --file=$@ -C $$(dirname $(location redirects)) $$(basename $(location redirects))",
tools = [
":base_rst_files",
":redirects",
":root_rst_files",
],
)

genrule(
name = "examples_rst",
outs = ["examples_rst.tar"],
cmd = "tar cfh $@ --transform='s/examples/start\\/sandboxes\\/_include/' $(locations //examples:files)",
tools = [
"//examples:files",
],
)
28 changes: 6 additions & 22 deletions docs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ else
fi

SCRIPT_DIR="$(dirname "$0")"
SRC_DIR="$(dirname "$SCRIPT_DIR")"
ENVOY_SRCDIR="$(realpath "$SRC_DIR")"
CONFIGS_DIR="${SRC_DIR}"/configs
BUILD_DIR=build_docs
[[ -z "${DOCS_OUTPUT_DIR}" ]] && DOCS_OUTPUT_DIR=generated/docs
[[ -z "${GENERATED_RST_DIR}" ]] && GENERATED_RST_DIR=generated/rst
Expand All @@ -54,8 +51,6 @@ mkdir -p "${DOCS_OUTPUT_DIR}"
rm -rf "${GENERATED_RST_DIR}"
mkdir -p "${GENERATED_RST_DIR}"

export ENVOY_SRCDIR

source_venv "$BUILD_DIR"
pip3 install --require-hashes -r "${SCRIPT_DIR}"/requirements.txt

Expand Down Expand Up @@ -89,31 +84,20 @@ bazel build "${BAZEL_BUILD_OPTIONS[@]}" //tools/docs:empty_protos_rst
bazel build "${BAZEL_BUILD_OPTIONS[@]}" //tools/docs:api_rst

# Edge hardening example YAML.
mkdir -p "${GENERATED_RST_DIR}"/configuration/best_practices
cp -f "${CONFIGS_DIR}"/google-vrp/envoy-edge.yaml "${GENERATED_RST_DIR}"/configuration/best_practices

copy_example_configs () {
mkdir -p "${GENERATED_RST_DIR}/start/sandboxes/_include"
cp -a "${SRC_DIR}"/examples/* "${GENERATED_RST_DIR}/start/sandboxes/_include"
}

copy_example_configs
bazel build "${BAZEL_BUILD_OPTIONS[@]}" //docs:google_vrp_config

rsync -av \
"${SCRIPT_DIR}"/root/ \
"${SCRIPT_DIR}"/conf.py \
"${SCRIPT_DIR}"/redirects.txt \
"${SCRIPT_DIR}"/_ext \
"${GENERATED_RST_DIR}"
bazel build "${BAZEL_BUILD_OPTIONS[@]}" //docs:base_rst

bazel build "${BAZEL_BUILD_OPTIONS[@]}" //docs:redirects
bazel build "${BAZEL_BUILD_OPTIONS[@]}" //docs:examples_rst

# TODO(phlax): once all of above jobs are moved to bazel build genrules these can be done as part of the sphinx build
tar -xf bazel-bin/docs/base_rst.tar -C "${GENERATED_RST_DIR}"
tar -xf bazel-bin/docs/examples_rst.tar -C "${GENERATED_RST_DIR}"
tar -xf bazel-bin/tools/docs/extensions_security_rst.tar -C "${GENERATED_RST_DIR}"
tar -xf bazel-bin/tools/docs/external_deps_rst.tar -C "${GENERATED_RST_DIR}"
tar -xf bazel-bin/tools/docs/empty_protos_rst.tar -C "${GENERATED_RST_DIR}"
tar -xf bazel-bin/tools/docs/api_rst.tar -C "${GENERATED_RST_DIR}"
cp -a bazel-bin/docs/envoy-redirects.txt "${GENERATED_RST_DIR}"
tar -xf bazel-bin/docs/google_vrp_config.tar -C "${GENERATED_RST_DIR}"

# To speed up validate_fragment invocations in validating_code_block
bazel build "${BAZEL_BUILD_OPTIONS[@]}" //tools/config_validation:validate_fragment
Expand Down
7 changes: 7 additions & 0 deletions examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ filegroup(
name = "lua",
srcs = glob(["**/*.lua"]),
)

filegroup(
name = "files",
srcs = glob(["**/*"]) + [
"//examples/wasm-cc:files",
],
)
5 changes: 5 additions & 0 deletions examples/wasm-cc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ envoy_wasm_cc_binary(
name = "envoy_filter_http_wasm_updated_example.wasm",
srcs = ["envoy_filter_http_wasm_updated_example.cc"],
)

filegroup(
name = "files",
srcs = glob(["**/*"]),
)

0 comments on commit 2637d2a

Please sign in to comment.