Skip to content

Commit a129f3c

Browse files
committed
test: support socket activation in test harness
1 parent 6da87f9 commit a129f3c

9 files changed

Lines changed: 332 additions & 9 deletions

Containerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Multi-stage build for envoy-acme-xds
22
# Stage 1: Build dependencies and cache them
3-
FROM docker.io/rust:1.85-bookworm AS chef
3+
FROM docker.io/rust:1.93-bookworm AS chef
44
RUN cargo install cargo-chef
55
WORKDIR /app
66

Containerfile.systemd

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Multi-stage build for envoy-acme-xds with systemd socket activation
2+
# Stage 1: Build dependencies and cache them
3+
FROM docker.io/rust:1.93-bookworm AS chef
4+
RUN cargo install cargo-chef
5+
WORKDIR /app
6+
7+
# Stage 2: Prepare recipe (dependency manifest)
8+
FROM chef AS planner
9+
COPY Cargo.toml Cargo.lock ./
10+
COPY src ./src
11+
RUN cargo chef prepare --recipe-path recipe.json
12+
13+
# Stage 3: Build dependencies (cached layer)
14+
FROM chef AS builder
15+
COPY --from=planner /app/recipe.json recipe.json
16+
RUN cargo chef cook --release --recipe-path recipe.json
17+
18+
# Build the application
19+
COPY Cargo.toml Cargo.lock ./
20+
COPY src ./src
21+
RUN cargo build --release
22+
23+
# Stage 4: Runtime image with systemd
24+
FROM docker.io/debian:bookworm AS runtime
25+
ENV container=podman
26+
27+
RUN apt-get update && apt-get install -y --no-install-recommends \
28+
ca-certificates \
29+
systemd \
30+
&& rm -rf /var/lib/apt/lists/*
31+
32+
# Create directories for config and data
33+
RUN mkdir -p \
34+
/var/lib/envoy-acme-xds \
35+
/var/run \
36+
/etc/envoy-acme-xds \
37+
/usr/local/share/ca-certificates \
38+
/etc/systemd/system/sockets.target.wants
39+
40+
# Copy the binary
41+
COPY --from=builder /app/target/release/envoy-acme-xds /usr/local/bin/envoy-acme-xds
42+
43+
# Install systemd units
44+
COPY test/systemd/envoy-acme-xds.socket /etc/systemd/system/envoy-acme-xds.socket
45+
COPY test/systemd/envoy-acme-xds.service /etc/systemd/system/envoy-acme-xds.service
46+
47+
# Enable socket activation
48+
RUN ln -s /etc/systemd/system/envoy-acme-xds.socket /etc/systemd/system/sockets.target.wants/envoy-acme-xds.socket
49+
50+
STOPSIGNAL SIGRTMIN+3
51+
CMD ["/bin/systemd"]

compose.systemd.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
services:
2+
xds-server:
3+
build:
4+
context: .
5+
dockerfile: Containerfile.systemd
6+
command: ["/bin/systemd"]
7+
privileged: true
8+
tmpfs:
9+
- /run
10+
- /tmp
11+
volumes:
12+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
13+
- xds-data:/var/lib/envoy-acme-xds
14+
- ./test/xds-config-systemd.yaml:/etc/envoy-acme-xds/config.yaml:ro,Z
15+
- ./certificates/pebble-ca.pem:/etc/envoy-acme-xds/ca.pem:ro,z
16+
environment:
17+
container: podman

compose.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ services:
3535
- "site-b.example.com:172.28.0.10"
3636
- "api.example.com:172.28.0.10"
3737
volumes:
38-
- ./test/pebble:/test/config:ro
39-
- ./certificates:/test/certs:ro
38+
- ./test/pebble:/test/config:ro,Z
39+
- ./certificates:/test/certs:ro,z
4040
ports:
4141
- "14000:14000" # ACME directory
4242
- "15000:15000" # Management interface
@@ -52,8 +52,8 @@ services:
5252
dockerfile: Containerfile
5353
volumes:
5454
- xds-data:/var/lib/envoy-acme-xds
55-
- ./test/xds-config.yaml:/etc/envoy-acme-xds/config.yaml:ro
56-
- ./certificates/pebble-ca.pem:/etc/envoy-acme-xds/ca.pem:ro
55+
- ./test/xds-config.yaml:/etc/envoy-acme-xds/config.yaml:ro,Z
56+
- ./certificates/pebble-ca.pem:/etc/envoy-acme-xds/ca.pem:ro,z
5757
environment:
5858
RUST_LOG: "envoy_acme_xds=debug,tower=debug,tonic=debug,h2=debug,info"
5959
networks:
@@ -66,11 +66,12 @@ services:
6666
# Envoy proxy
6767
envoy:
6868
image: docker.io/envoyproxy/envoy:v1.32-latest
69-
command: ["envoy", "-c", "/etc/envoy/envoy.yaml", "--log-level", "info"]
69+
entrypoint: ["envoy"]
70+
command: ["-c", "/etc/envoy/envoy.yaml", "--log-level", "info"]
7071
user: "0:0" # Run as root to bind to privileged ports
7172
volumes:
7273
- xds-data:/var/lib/envoy-acme-xds
73-
- ./test/envoy/envoy.yaml:/etc/envoy/envoy.yaml:ro
74+
- ./test/envoy/envoy.yaml:/etc/envoy/envoy.yaml:ro,Z
7475
ports:
7576
- "8080:5001" # HTTP (for ACME challenges) - host:container
7677
- "8443:8443" # HTTPS

test/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ This directory contains the configuration and scripts needed to run a fully cont
1818
# Run the full test suite
1919
./test/run-test.sh
2020

21+
# Run the systemd socket activation test
22+
./test/run-test.sh --systemd
23+
2124
# Run tests and keep containers running for debugging
2225
./test/run-test.sh --keep
2326

@@ -193,6 +196,10 @@ test/
193196
├── cleanup.sh # Cleanup and reset script
194197
├── verify-validation.sh # Verification script for real ACME validation
195198
├── xds-config.yaml # XDS server configuration
199+
├── xds-config-systemd.yaml # XDS server config for systemd socket activation
200+
├── systemd/
201+
│ ├── envoy-acme-xds.service
202+
│ └── envoy-acme-xds.socket
196203
├── envoy/
197204
│ └── envoy.yaml # Envoy bootstrap configuration
198205
└── pebble/

test/run-test.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
2727
# Parse arguments
2828
KEEP_RUNNING=false
2929
REBUILD=false
30+
SYSTEMD_MODE=false
3031
while [[ $# -gt 0 ]]; do
3132
case $1 in
3233
--keep|-k)
@@ -37,12 +38,17 @@ while [[ $# -gt 0 ]]; do
3738
REBUILD=true
3839
shift
3940
;;
41+
--systemd|-s)
42+
SYSTEMD_MODE=true
43+
shift
44+
;;
4045
--help|-h)
4146
echo "Usage: $0 [OPTIONS]"
4247
echo ""
4348
echo "Options:"
4449
echo " --keep, -k Keep containers running after tests"
4550
echo " --rebuild, -r Force rebuild of containers"
51+
echo " --systemd, -s Run systemd socket activation test"
4652
echo " --help, -h Show this help message"
4753
exit 0
4854
;;
@@ -55,6 +61,11 @@ done
5561

5662
cd "${PROJECT_DIR}"
5763

64+
COMPOSE_FILES=(-f compose.yaml)
65+
if [[ "${SYSTEMD_MODE}" == "true" ]]; then
66+
COMPOSE_FILES+=(-f compose.systemd.yaml)
67+
fi
68+
5869
# Step 1: Generate certificates if needed
5970
if [[ ! -f "${CERT_DIR}/pebble-ca.pem" ]]; then
6071
log_info "Generating test certificates..."
@@ -70,7 +81,7 @@ if [[ "${REBUILD}" == "true" ]]; then
7081
BUILD_ARGS="--build"
7182
fi
7283

73-
podman compose up -d ${BUILD_ARGS}
84+
podman compose "${COMPOSE_FILES[@]}" up -d ${BUILD_ARGS}
7485

7586
# Step 3: Wait for services to be ready
7687
log_info "Waiting for services to be ready..."
@@ -138,6 +149,14 @@ run_test "Envoy has LDS listeners" \
138149
run_test "Envoy has CDS clusters" \
139150
'curl -sf http://localhost:9901/config_dump | grep -q "xds_cluster"'
140151

152+
if [[ "${SYSTEMD_MODE}" == "true" ]]; then
153+
run_test "Systemd socket active" \
154+
'podman exec xds-server systemctl is-active envoy-acme-xds.socket | grep -q "active"'
155+
156+
run_test "Systemd service active" \
157+
'podman exec xds-server systemctl is-active envoy-acme-xds.service | grep -q "active"'
158+
fi
159+
141160
# Test: HTTP port is responding
142161
run_test "Envoy HTTP port" \
143162
'curl -sf -o /dev/null -w "%{http_code}" http://localhost:8080/ 2>/dev/null | grep -qE "^(200|301|302|308)$"'
@@ -163,7 +182,7 @@ if [[ "${KEEP_RUNNING}" == "true" ]]; then
163182
echo " - Pebble ACME: https://localhost:14000/dir"
164183
else
165184
log_info "Stopping containers..."
166-
podman compose down
185+
podman compose "${COMPOSE_FILES[@]}" down
167186
fi
168187

169188
# Exit with appropriate code
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=envoy-acme-xds service
3+
After=network.target
4+
Requires=envoy-acme-xds.socket
5+
6+
[Service]
7+
Type=simple
8+
Environment=RUST_LOG=envoy_acme_xds=debug,tower=debug,tonic=debug,h2=debug,info
9+
ExecStartPre=/bin/sh -c 'if [ -f /etc/envoy-acme-xds/ca.pem ]; then cp /etc/envoy-acme-xds/ca.pem /usr/local/share/ca-certificates/custom-ca.crt && update-ca-certificates 2>/dev/null || true; fi'
10+
ExecStartPre=/bin/sh -c 'chown -R root:root /var/lib/envoy-acme-xds 2>/dev/null || true'
11+
ExecStart=/usr/local/bin/envoy-acme-xds /etc/envoy-acme-xds/config.yaml
12+
Restart=on-failure
13+
14+
[Install]
15+
WantedBy=multi-user.target

test/systemd/envoy-acme-xds.socket

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description=envoy-acme-xds socket
3+
4+
[Socket]
5+
ListenStream=/var/lib/envoy-acme-xds/envoy-xds.sock
6+
SocketMode=0777
7+
Service=envoy-acme-xds.service
8+
9+
[Install]
10+
WantedBy=sockets.target

0 commit comments

Comments
 (0)