Skip to content

Commit

Permalink
feat(bazel): incorporate wasm filters into bazel build [KAG-4210] (#1…
Browse files Browse the repository at this point in the history
…2853) (#8917)

* feat(bazel): add wasm filters to build

* fix(bazel): mv wasm filters to kong/filters



* fix(bazel): filter file renaming



* chore(wasm): response_transofmrer filter 0.1.2

* fix(bazel): filter typo

* feat(wasm): swap to datakit filter

* fix(bazel): rename wasm filters repo

* fix(bazel): mv wasm filters to kong/wasm

---------

Co-authored-by: Isa Farnik <isa@konghq.com>
  • Loading branch information
flrgh and curiositycasualty authored Apr 24, 2024
1 parent b84d016 commit aee3845
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 2 deletions.
16 changes: 15 additions & 1 deletion build/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@kong_bindings//:variables.bzl", "KONG_VAR")
load("@bazel_skylib//lib:selects.bzl", "selects")
load("//build:build_system.bzl", "kong_directory_genrule", "kong_rules_group", "kong_template_file")
load("@kong//build/openresty/wasmx/filters:variables.bzl", "WASM_FILTERS_TARGETS")

exports_files([
"package/nfpm.yaml",
Expand Down Expand Up @@ -75,6 +76,18 @@ install_webui_cmd = select({
"@kong//:skip_webui_flags": "\n",
})

install_wasm_filters_cmd = select({
"@kong//:wasmx_flag": """
mkdir -pv ${BUILD_DESTDIR}/kong/wasm
""" + " ".join(["""
tpath="$(locations %s)"
fname="$(echo "${tpath}" | cut -d'/' -f2)"
cp -v "$tpath" "${BUILD_DESTDIR}/kong/wasm/${fname}"
""" % t for t in WASM_FILTERS_TARGETS]),
"//conditions:default": "\n",
})

install_wasm_deps_cmd = select({
"@kong//:wasmx_flag": """
for fname in $(locations @ngx_wasmx_module//:lua_libs); do
Expand Down Expand Up @@ -182,7 +195,7 @@ kong_directory_genrule(
"@kong//:wasmx_flag": [
"@ngx_wasmx_module//:lua_libs",
"@openresty//:wasm_runtime",
],
] + WASM_FILTERS_TARGETS,
"//conditions:default": [],
}) + lib_deps + lualib_deps,
cmd =
Expand Down Expand Up @@ -256,6 +269,7 @@ kong_directory_genrule(
install_curl_cmd +
link_modules_dir +
install_wasm_deps_cmd +
install_wasm_filters_cmd +
"""
mkdir -p ${BUILD_DESTDIR}/etc/kong
cp kong.conf.default ${BUILD_DESTDIR}/etc/kong/kong.conf.default
Expand Down
3 changes: 2 additions & 1 deletion build/openresty/BUILD.openresty.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@bazel_skylib//lib:selects.bzl", "selects")
load("@kong//build/openresty/wasmx:rules.bzl", "wasm_runtime", "wasmx_configure_options", "wasmx_env")
load("@openresty_binding//:variables.bzl", "LUAJIT_VERSION")
load("@kong_bindings//:variables.bzl", "KONG_VAR")
load("@kong//build/openresty/wasmx/filters:variables.bzl", "WASM_FILTERS_TARGETS")

filegroup(
name = "luajit_srcs",
Expand Down Expand Up @@ -280,7 +281,7 @@ configure_make(
# wasm_runtime has to be a "data" (target) instead of "build_data" (exec)
# to be able to lookup by its path (relative to INSTALLDIR)
":wasm_runtime",
],
] + WASM_FILTERS_TARGETS,
"//conditions:default": [],
}),
env = wasmx_env,
Expand Down
2 changes: 2 additions & 0 deletions build/openresty/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ load("//build/openresty/atc_router:atc_router_repositories.bzl", "atc_router_rep
load("//build/openresty/jsonschema:jsonschema_repositories.bzl", "jsonschema_repositories")
load("//build/openresty/msgpack_c:msgpack_c_repositories.bzl", "msgpack_c_repositories")
load("//build/openresty/wasmx:wasmx_repositories.bzl", "wasmx_repositories")
load("//build/openresty/wasmx/filters:repositories.bzl", "wasm_filters_repositories")
load("//build/openresty/brotli:brotli_repositories.bzl", "brotli_repositories")

# This is a dummy file to export the module's repository.
Expand All @@ -28,6 +29,7 @@ def openresty_repositories():
jsonschema_repositories()
msgpack_c_repositories()
wasmx_repositories()
wasm_filters_repositories()
brotli_repositories()

openresty_version = KONG_VAR["OPENRESTY"]
Expand Down
14 changes: 14 additions & 0 deletions build/openresty/wasmx/filters/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("@kong//build/openresty/wasmx/filters:variables.bzl", "WASM_FILTERS_TARGETS")

filegroup(
name = "all_srcs",
srcs = glob(
include = ["**"],
exclude = ["*.bazel"],
),
)

exports_files(
WASM_FILTERS_TARGETS,
visibility = ["//visibility:public"],
)
19 changes: 19 additions & 0 deletions build/openresty/wasmx/filters/repositories.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load(":variables.bzl", "WASM_FILTERS")

def wasm_filters_repositories():
for filter in WASM_FILTERS:
for file in filter["files"].keys():
renamed_file = file.replace("filter", filter["name"])

maybe(
http_file,
name = renamed_file,
url = "https://github.com/%s/releases/download/%s/%s" % (
filter["repo"],
filter["tag"],
file,
),
sha256 = filter["files"][file],
)
23 changes: 23 additions & 0 deletions build/openresty/wasmx/filters/variables.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
A list of wasm filters.
"""

WASM_FILTERS = [
{
"name": "datakit-filter",
"repo": "Kong/datakit-filter",
"tag": "0.1.0",
"files": {
"datakit.meta.json": "b9f3b6d51d9566fae1a34c0e5c00f0d5ad5dc8f6ce7bf81931fd0be189de205d",
"datakit.wasm": "a494c254915e222c3bd2b36944156680b4534bdadf438fb2143df9e0a4ef60ad",
},
},
]

WASM_FILTERS_TARGETS = [
[
"@%s//file" % file
for file in filter["files"].keys()
]
for filter in WASM_FILTERS
][0]

0 comments on commit aee3845

Please sign in to comment.