Skip to content

Commit f064449

Browse files
committed
feat(dev): allow running e2e in a custom Docker network
1 parent 82fea3d commit f064449

5 files changed

Lines changed: 70 additions & 9 deletions

File tree

Makefile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
COMPOSE_DEV := dev/docker/docker-compose.yml
22
COMPOSE_DEBUG_SCRAPER := dev/docker/docker-compose.debug-scraper.yml
33
COMPOSE_E2E := dev/docker/docker-compose.e2e.yml
4+
COMPOSE_EXTERNAL_NET := dev/docker/docker-compose.external-network.yml
45
ENV_FILE := .env
56
CHROME_PATH ?= /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
67
RUNS ?= 10
@@ -59,11 +60,16 @@ scraper: ## Run web scraper on host (headed browser).
5960

6061
## ---------- End-to-End Testing ----------
6162

62-
e2e-up: ## Start the full e2e stack (all services in Docker). Use BUILD=1 to rebuild images.
63-
docker compose -f $(COMPOSE_DEV) -f $(COMPOSE_E2E) --env-file $(ENV_FILE) up $(if $(BUILD),--build) -d
63+
COMPOSE_E2E_FILES := -f $(COMPOSE_DEV) -f $(COMPOSE_E2E)
64+
ifdef EXTERNAL_NETWORK
65+
COMPOSE_E2E_FILES += -f $(COMPOSE_EXTERNAL_NET)
66+
endif
67+
68+
e2e-up: ## Start the full e2e stack (all services in Docker). Use BUILD=1 to rebuild images. Use EXTERNAL_NETWORK=<name> to join an external Docker network.
69+
docker compose $(COMPOSE_E2E_FILES) --env-file $(ENV_FILE) up $(if $(BUILD),--build) -d
6470

6571
e2e-down: ## Stop the e2e stack and remove volumes.
66-
docker compose -f $(COMPOSE_DEV) -f $(COMPOSE_E2E) --env-file $(ENV_FILE) down --volumes --remove-orphans
72+
docker compose $(COMPOSE_E2E_FILES) --env-file $(ENV_FILE) down --volumes --remove-orphans
6773

6874
e2e-test: ## Run Playwright e2e tests (use ARGS for extra flags, e.g. make e2e-test ARGS="--ui").
6975
cd e2e && npx playwright test $(ARGS)
@@ -91,7 +97,7 @@ e2e-report: ## Open the Playwright HTML report.
9197
cd e2e && npx playwright show-report
9298

9399
e2e-logs: ## Tail logs from e2e stack.
94-
docker compose -f $(COMPOSE_DEV) -f $(COMPOSE_E2E) logs -f
100+
docker compose $(COMPOSE_E2E_FILES) logs -f
95101

96102
## ---------- Documentation ----------
97103

dev/docker/docker-compose.e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ services:
7070
context: ../..
7171
dockerfile: Dockerfile.webui
7272
ports:
73-
- "7171:8080"
73+
- "7171:7171"
7474
volumes:
7575
- type: bind
7676
source: ./nginx-e2e.conf
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Optional overlay: join secutils_webui (nginx) to an external Docker network so that
2+
# containers on that network can reach webhook responders by subdomain hostname.
3+
#
4+
# Uses *.webhooks.secutils.local instead of *.webhooks.localhost because *.localhost
5+
# resolves to 127.0.0.1 inside containers (RFC 6761), bypassing Docker DNS aliases.
6+
# A companion nginx config translates the host back to *.webhooks.localhost for the API.
7+
#
8+
# Usage:
9+
# make e2e-up EXTERNAL_NETWORK=retrack
10+
# make e2e-up EXTERNAL_NETWORK=retrack WEBHOOK_ALIAS=abc-docs.webhooks.secutils.local
11+
#
12+
# Then from a container on the external network:
13+
# curl http://docs.webhooks.secutils.local:7171/my-path
14+
services:
15+
secutils_api:
16+
networks:
17+
net: {}
18+
external_net: {}
19+
20+
secutils_webui:
21+
networks:
22+
net: {}
23+
external_net:
24+
aliases:
25+
- "${WEBHOOK_ALIAS:-docs.webhooks.secutils.local}"
26+
volumes:
27+
- type: bind
28+
source: ./nginx-external-network.conf
29+
target: /etc/nginx/conf.d/external-network.conf
30+
31+
networks:
32+
external_net:
33+
external: true
34+
name: ${EXTERNAL_NETWORK}

dev/docker/nginx-e2e.conf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Webhook subdomain routing - mirrors Traefik IngressRoute in production.
22
server {
3-
listen 8080;
4-
listen [::]:8080;
3+
listen 7171;
4+
listen [::]:7171;
55
server_name ~^(.+)\.webhooks\.localhost$;
66

77
location / {
@@ -18,8 +18,8 @@ server {
1818
}
1919

2020
server {
21-
listen 8080 default_server;
22-
listen [::]:8080 default_server;
21+
listen 7171 default_server;
22+
listen [::]:7171 default_server;
2323
server_name localhost;
2424

2525
client_max_body_size 50m;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Webhook subdomain routing for containers on an external Docker network.
2+
#
3+
# *.localhost hostnames resolve to 127.0.0.1 inside containers (RFC 6761), so Docker
4+
# network aliases must use a different suffix. This server block accepts requests on
5+
# *.webhooks.secutils.local and translates them to the X-Forwarded-Host that the API
6+
# expects (*.webhooks.localhost).
7+
server {
8+
listen 7171;
9+
listen [::]:7171;
10+
server_name ~^(?<webhook_subdomain>.+)\.webhooks\.secutils\.local$;
11+
12+
location / {
13+
set $original_uri $uri;
14+
rewrite ^ /api/webhooks break;
15+
proxy_pass http://secutils_api:7070;
16+
proxy_set_header X-Forwarded-Host $webhook_subdomain.webhooks.localhost;
17+
proxy_set_header X-Replaced-Path $original_uri;
18+
proxy_set_header X-Real-IP $remote_addr;
19+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
20+
}
21+
}

0 commit comments

Comments
 (0)