Skip to content

Commit 77920f9

Browse files
authored
Merge pull request #14 from dash14/refactor/move-js-processing-into-container
Move rule conversion and log reporting into Docker container
2 parents 74493d2 + 4a3f702 commit 77920f9

File tree

27 files changed

+626
-332
lines changed

27 files changed

+626
-332
lines changed

Makefile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ run_restrict_mode: ## Start in restrict mode
2929
@echo "Starting buildcage in RESTRICT mode..."
3030
@COMPOSE_FILE=$(COMPOSE_FILE) \
3131
PROXY_MODE=restrict \
32-
ALLOWED_HTTP_RULES="$$(node setup/convert-rules.mjs "$${ALLOWED_HTTP_RULES:-}")" \
33-
ALLOWED_HTTPS_RULES="$$(node setup/convert-rules.mjs "$${ALLOWED_HTTPS_RULES:-github.com:443 registry.npmjs.org:443 api.github.com:443 objects.githubusercontent.com:443 httpbin.org:443 deb.debian.org:80 *.githubusercontent.com:443}")" \
32+
ALLOWED_HTTP_RULES="$${ALLOWED_HTTP_RULES:-}" \
33+
ALLOWED_HTTPS_RULES="$${ALLOWED_HTTPS_RULES:-github.com:443 registry.npmjs.org:443 api.github.com:443 objects.githubusercontent.com:443 httpbin.org:443 deb.debian.org:80 *.githubusercontent.com:443}" \
3434
docker compose up -d --wait --build
3535
@docker buildx rm buildcage 2>/dev/null || true
3636
@echo "Creating buildx builder..."
@@ -67,8 +67,17 @@ test_audit_mode: ## Run audit mode tests
6767
@$(MAKE) clean
6868

6969
.PHONY: test_unit
70-
test_unit: ## Run unit tests
71-
@node --test setup/lib/rules.test.mjs
70+
test_unit: test_legacy test_qjs ## Run unit tests
71+
72+
.PHONY: test_legacy
73+
test_legacy: ## Run legacy rules unit tests
74+
@node --test setup/lib/legacy-rules.test.mjs
75+
76+
.PHONY: test_qjs
77+
test_qjs: ## Run unit tests in Docker
78+
@docker build -t buildcage-qjs-test docker
79+
@docker run --rm --entrypoint qjs buildcage-qjs-test /opt/buildcage/tools/lib/rules.test.mjs
80+
@docker run --rm --entrypoint qjs buildcage-qjs-test /opt/buildcage/tools/lib/log-parser.test.mjs
7281

7382
.PHONY: test_audit_example
7483
run_audit_example: ## Run audit mode example tests

compose.test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ services:
33
builder:
44
environment:
55
- EXTERNAL_RESOLVER=10.200.0.53
6-
- ALLOWED_HTTPS_RULES=^allowed\.example\.com:(443|8443)$$ ^[^.]+\.wildcard\.example\.com:(443|8443)$$
7-
- ALLOWED_HTTP_RULES=^allowed\.example\.com:(80|8080)$$ ^[^.]+\.wildcard\.example\.com:(80|8080)$$
6+
- ALLOWED_HTTPS_RULES=allowed.example.com:443 allowed.example.com:8443 *.wildcard.example.com:443 *.wildcard.example.com:8443
7+
- ALLOWED_HTTP_RULES=allowed.example.com:80 allowed.example.com:8080 *.wildcard.example.com:80 *.wildcard.example.com:8080
88
networks:
99
default:
1010
test-net:

docker/Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ RUN apk add --no-cache \
2424
haproxy \
2525
dnsmasq \
2626
iptables \
27-
curl
27+
curl \
28+
quickjs
2829

2930
# s6-overlay
3031
ARG S6_OVERLAY_VERSION
@@ -55,15 +56,19 @@ COPY files/cni.conflist /etc/buildkit/cni.conflist
5556
COPY files/dnsmasq.conf /etc/dnsmasq.conf
5657

5758
# HAProxy
58-
RUN mkdir -p /etc/haproxy/rules
59+
RUN mkdir -p /etc/haproxy/rules /var/log/haproxy
5960
COPY files/haproxy.cfg.template /etc/haproxy/haproxy.cfg.template
6061

62+
# Tools (QuickJS scripts)
63+
COPY files/tools/ /opt/buildcage/tools/
64+
6165
# s6 service definitions and init scripts
6266
COPY files/s6-rc.d/ /etc/s6-overlay/s6-rc.d/
6367
COPY files/s6-scripts/ /etc/s6-overlay/scripts/
6468
RUN chmod +x /etc/s6-overlay/scripts/* && \
6569
chmod +x /etc/s6-overlay/s6-rc.d/dnsmasq/run && \
66-
chmod +x /etc/s6-overlay/s6-rc.d/haproxy/run
70+
chmod +x /etc/s6-overlay/s6-rc.d/haproxy/run && \
71+
chmod +x /etc/s6-overlay/s6-rc.d/haproxy-log/run
6772

6873
ENTRYPOINT ["/init"]
6974
CMD ["buildkitd", "--oci-worker-net=cni", "--addr", "tcp://0.0.0.0:1234"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
haproxy
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
haproxy-pipeline
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/command/execlineb -P
2+
s6-log 1 /var/log/haproxy
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
longrun
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
haproxy-log

docker/files/s6-rc.d/haproxy/run

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#!/command/with-contenv sh
2+
exec 2>&1
23
exec haproxy -f /etc/haproxy/haproxy.cfg -db

0 commit comments

Comments
 (0)