Import apache2 for testing
Create `971-Robot-Code/ldap.json`. It is a JSON file with the LDAP URL
and password.
{
"ldap_bind_dn": "...",
"ldap_url": "...",
"ldap_password": "..."
}
Run like this:
$ bazel run //build_tests:apache_https_demo
Then you can navigate to `https://localhost:7000`.
If the ports are taken, customize with:
* `--https_port`
* `--wrapped_port`
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: I56432388b774932fc6cf295da52ac8bc9e974cd7
diff --git a/tools/build_rules/apache.bzl b/tools/build_rules/apache.bzl
new file mode 100644
index 0000000..9fb2ef5
--- /dev/null
+++ b/tools/build_rules/apache.bzl
@@ -0,0 +1,82 @@
+def _apache_binary_impl(ctx):
+ binary_path = ctx.attr.binary.files_to_run.executable.short_path
+
+ out = ctx.actions.declare_file(ctx.label.name)
+ ctx.actions.write(out, """\
+#!/bin/bash
+
+exec ./tools/build_rules/apache_runner --binary "{}" "$@"
+""".format(binary_path), is_executable = True)
+
+ # Collect files and runfiles for the tools that we're wrapping.
+ files = depset(transitive = [
+ ctx.attr._apache_runner.files,
+ ctx.attr.binary.files,
+ ])
+
+ runfiles = ctx.attr._apache_runner.default_runfiles
+ runfiles = runfiles.merge(ctx.attr.binary.default_runfiles)
+
+ return [
+ DefaultInfo(
+ executable = out,
+ files = files,
+ runfiles = runfiles,
+ ),
+ ]
+
+apache_wrapper = rule(
+ implementation = _apache_binary_impl,
+ attrs = {
+ "binary": attr.label(
+ mandatory = True,
+ executable = True,
+ cfg = "target",
+ doc = "The binary that we're wrapping with LDAP+HTTPS.",
+ ),
+ "_apache_runner": attr.label(
+ default = "@//tools/build_rules:apache_runner",
+ executable = True,
+ cfg = "target",
+ ),
+ },
+ doc = """\
+This rule wraps another web server and provides LDAP and HTTPS support.
+
+It's not intended to be used in production. It's intended to provide team
+members with a way to test their code in a production-like environment. E.g. to
+test whether your server makes use of LDAP credentials correctly.
+
+Write this as a wrapper around another binary like so:
+
+ apache_wrapper(
+ name = "wrapped_server",
+ binary = "//path/to:server_binary",
+ )
+
+Then you can run Apache and the wrapped binary like so:
+
+ $ bazel run :wrapped_server
+
+The wrapped binary can find the port that Apache is wrapping via the
+APACHE_WRAPPED_PORT environment variable.
+
+This rule assumes that you have a file at the root of the workspace called
+"ldap.json". You can customize this path with the `--ldap_info` argument. The
+JSON file has to have these three entries in it:
+
+ {
+ "ldap_bind_dn": "...",
+ "ldap_url": "...",
+ "ldap_password": "..."
+ }
+
+where the "..." values are replaced with the information to connect to an LDAP
+server. If you want to connect to our FRC971 LDAP server, please contact a
+Software mentor. Or ask on the `#coding` Slack channel.
+
+If the default ports of 7000 and 7500 are already taken, you can change them via
+the `--https_port` and `--wrapped_port` arguments.
+""",
+ executable = True,
+)