Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,17 @@ deploy:

start-local: build-check
@echo "Starting mock external processor..."
@pkill -f "extproc_mock" || true
@EPP_UPSTREAM=localhost:8080 MOCK_ROLE=EPP ./target/debug/extproc_mock 0.0.0.0:9001 &
@-kill $$(cat /tmp/extproc_mock.pid 2>/dev/null) 2>/dev/null || true
@rm -f /tmp/extproc_mock.pid
@(EPP_UPSTREAM=localhost:8080 MOCK_ROLE=EPP ./target/debug/extproc_mock 0.0.0.0:9001 >/dev/null 2>&1 & echo $$! > /tmp/extproc_mock.pid) || true
@sleep 1
@echo "Starting echo server..."
@pkill -f "custom-echo-server.js" || true
@-kill $$(cat /tmp/echo-server.pid 2>/dev/null) 2>/dev/null || true
@rm -f /tmp/echo-server.pid
@cd docker/echo-server && [ ! -f package.json ] && npm init -y >/dev/null 2>&1 || true
@cd docker/echo-server && [ ! -d node_modules ] && npm install express >/dev/null 2>&1 || true
@cd docker/echo-server && PORT=8080 node custom-echo-server.js &
@(cd docker/echo-server && PORT=8080 node custom-echo-server.js >/dev/null 2>&1 & echo $$! > /tmp/echo-server.pid) || true
@sleep 1

setup-local:
./tests/setup-local-dev.sh --local
Expand All @@ -109,11 +113,11 @@ setup-docker:
./tests/setup-local-dev.sh --docker

stop:
docker compose -f $(DOCKER_COMPOSE_MAIN) down --remove-orphans
# Stop local processes
@docker compose -f $(DOCKER_COMPOSE_MAIN) down --remove-orphans 2>/dev/null || true
ifndef GITHUB_ACTIONS
pkill -f "custom-echo-server.js" 2>/dev/null || true
pkill -f "extproc_mock" 2>/dev/null || true
@-kill $$(cat /tmp/echo-server.pid 2>/dev/null) 2>/dev/null || true
@-kill $$(cat /tmp/extproc_mock.pid 2>/dev/null) 2>/dev/null || true
@rm -f /tmp/extproc_mock.pid /tmp/echo-server.pid 2>/dev/null || true
endif


Expand All @@ -126,7 +130,6 @@ else
endif

test-docker:
@echo "Starting main docker services with build..."
docker compose -f $(DOCKER_COMPOSE_MAIN) up --build -d
DOCKER_ENVIRONMENT=main ./tests/test-config.sh

Expand Down Expand Up @@ -173,4 +176,4 @@ help:
@echo "EXAMPLES:"
@echo " make start # Start full stack"
@echo " make test TEST_ENV=local # Run local tests"
@echo " make generate-config OUTPUT=/tmp/nginx.conf ENV=local TEST=bbr_on_epp_off"
@echo " make generate-config OUTPUT=/tmp/nginx.conf ENV=local TEST=bbr_on_epp_off"
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn cstr_ptr(s: *const u8) -> *const c_char {
#[cfg(not(target_os = "macos"))]
#[inline]
fn cstr_ptr(s: *const u8) -> *const c_char {
s as *const u8 as *const c_char
s as *const c_char
}

// NGINX module for Gateway API inference extensions.
Expand Down
2 changes: 1 addition & 1 deletion src/modules/bbr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn cstr_ptr(s: *const u8) -> *const c_char {
#[cfg(not(target_os = "macos"))]
#[inline]
fn cstr_ptr(s: *const u8) -> *const c_char {
s as *const u8 as *const c_char
s as *const c_char
}

/// Get an incoming request header value by name (case-insensitive).
Expand Down
2 changes: 1 addition & 1 deletion tests/configs/nginx-base.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ events {
}

http {
include /opt/homebrew/etc/nginx/mime.types;
include MIMETYPES_PATH_PLACEHOLDER;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
Expand Down
6 changes: 6 additions & 0 deletions tests/generate-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ fi
if [[ "$ENVIRONMENT" == "local" ]]; then
if [[ "$(uname)" == "Darwin" ]]; then
MODULE_PATH="$PROJECT_ROOT/target/debug/libngx_inference.dylib"
MIMETYPES_PATH="/opt/homebrew/etc/nginx/mime.types"
else
MODULE_PATH="$PROJECT_ROOT/target/debug/libngx_inference.so"
MIMETYPES_PATH="/etc/nginx/mime.types"
fi
else
MODULE_PATH="/usr/lib/nginx/modules/libngx_inference.so"
MIMETYPES_PATH="/etc/nginx/mime.types"
fi

# Validate template file exists
Expand All @@ -105,6 +108,7 @@ echo "Generating nginx configuration..."
echo " Environment: $ENVIRONMENT"
echo " Template: $TEMPLATE"
echo " Module path: $MODULE_PATH"
echo " Mime types path: $MIMETYPES_PATH"
echo " Output: $OUTPUT_FILE"

# Create output directory if it doesn't exist
Expand All @@ -125,6 +129,7 @@ if [[ -n "$SERVER_CONFIG" ]]; then
# Replace all placeholders
sed -e "s|TEST_SERVER_CONFIG_PLACEHOLDER|${SERVER_CONFIG_FILE}|g" \
-e "s|MODULE_PATH_PLACEHOLDER|${MODULE_PATH}|g" \
-e "s|MIMETYPES_PATH_PLACEHOLDER|${MIMETYPES_PATH}|g" \
-e "s|RESOLVER_PLACEHOLDER|${RESOLVER}|g" \
"$TEMPLATE" > "$OUTPUT_FILE"
else
Expand All @@ -133,6 +138,7 @@ else

# Just replace module and resolver placeholders
sed -e "s|MODULE_PATH_PLACEHOLDER|${MODULE_PATH}|g" \
-e "s|MIMETYPES_PATH_PLACEHOLDER|${MIMETYPES_PATH}|g" \
-e "s|RESOLVER_PLACEHOLDER|${RESOLVER}|g" \
"$TEMPLATE" > "$OUTPUT_FILE"
fi
Expand Down
195 changes: 180 additions & 15 deletions tests/setup-local-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ fi
echo -e "${YELLOW}Setting up for ${ENVIRONMENT} development...${NC}"
echo ""

# Detect OS and package manager
detect_os() {
if [[ -f /etc/os-release ]]; then
. /etc/os-release
OS=$ID
OS_VERSION=$VERSION_ID
elif [[ "$(uname)" == "Darwin" ]]; then
OS="macos"
else
OS="unknown"
fi
}

detect_os

# Common tools check
echo -e "${YELLOW}Checking common tools...${NC}"
tools_missing=0
Expand All @@ -72,9 +87,9 @@ if command -v curl >/dev/null 2>&1; then
echo -e "${GREEN}✓ curl found: $(curl --version | head -n1)${NC}"
else
echo -e "${RED}✗ curl not found - please install curl${NC}"
if [[ "$(uname)" == "Darwin" ]]; then
if [[ "$OS" == "macos" ]]; then
echo " brew install curl"
elif [[ "$(uname)" == "Linux" ]]; then
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
echo " sudo apt-get install curl"
fi
tools_missing=1
Expand All @@ -85,9 +100,9 @@ if command -v jq >/dev/null 2>&1; then
echo -e "${GREEN}✓ jq found: $(jq --version)${NC}"
else
echo -e "${RED}✗ jq not found - please install jq for JSON parsing${NC}"
if [[ "$(uname)" == "Darwin" ]]; then
if [[ "$OS" == "macos" ]]; then
echo " brew install jq"
elif [[ "$(uname)" == "Linux" ]]; then
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
echo " sudo apt-get install jq"
fi
tools_missing=1
Expand All @@ -104,12 +119,11 @@ if [[ "$ENVIRONMENT" == "local" ]]; then
echo -e "${GREEN}✓ nginx found: $CURRENT_VERSION${NC}"
else
echo -e "${RED}✗ nginx not found - please install nginx${NC}"
if [[ "$(uname)" == "Darwin" ]]; then
if [[ "$OS" == "macos" ]]; then
echo " brew install nginx"
elif [[ "$(uname)" == "Linux" ]]; then
echo " # Ubuntu/Debian:"
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
echo " sudo apt-get install nginx"
echo " # CentOS/RHEL:"
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
echo " sudo yum install nginx"
fi
tools_missing=1
Expand All @@ -120,14 +134,10 @@ if [[ "$ENVIRONMENT" == "local" ]]; then
echo -e "${GREEN}✓ node found: $(node --version)${NC}"
else
echo -e "${RED}✗ node not found - please install Node.js for echo server${NC}"
if [[ "$(uname)" == "Darwin" ]]; then
if [[ "$OS" == "macos" ]]; then
echo " brew install node"
elif [[ "$(uname)" == "Linux" ]]; then
echo " # Ubuntu/Debian:"
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
echo " sudo apt-get install nodejs npm"
echo " # Or use NodeSource:"
echo " curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -"
echo " sudo apt-get install -y nodejs"
fi
tools_missing=1
fi
Expand All @@ -150,6 +160,152 @@ if [[ "$ENVIRONMENT" == "local" ]]; then
tools_missing=1
fi

echo ""
echo -e "${YELLOW}Checking Rust build dependencies...${NC}"

# Check clang/LLVM (required for bindgen)
if command -v clang >/dev/null 2>&1; then
echo -e "${GREEN}✓ clang found: $(clang --version | head -n1)${NC}"
else
echo -e "${RED}✗ clang not found - required for Rust bindgen${NC}"
if [[ "$OS" == "macos" ]]; then
echo " xcode-select --install"
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
echo " sudo apt-get install clang"
elif [[ "$OS" == "alpine" ]]; then
echo " apk add clang-dev"
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
echo " sudo dnf install clang"
fi
tools_missing=1
fi

# Check PCRE2 development files
pcre2_found=false
if [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
if dpkg -l | grep -q libpcre2-dev; then
echo -e "${GREEN}✓ libpcre2-dev found${NC}"
pcre2_found=true
fi
elif [[ "$OS" == "macos" ]]; then
if brew list pcre2 &>/dev/null; then
echo -e "${GREEN}✓ pcre2 found${NC}"
pcre2_found=true
fi
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
if rpm -q pcre2-devel &>/dev/null; then
echo -e "${GREEN}✓ pcre2-devel found${NC}"
pcre2_found=true
fi
fi

if [[ "$pcre2_found" == "false" ]]; then
echo -e "${RED}✗ PCRE2 development files not found - required for nginx module build${NC}"
if [[ "$OS" == "macos" ]]; then
echo " brew install pcre2"
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
echo " sudo apt-get install libpcre2-dev"
elif [[ "$OS" == "alpine" ]]; then
echo " apk add pcre2-dev"
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
echo " sudo dnf install pcre2-devel"
fi
tools_missing=1
fi

# Check OpenSSL development files
openssl_found=false
if [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
if dpkg -l | grep -q libssl-dev; then
echo -e "${GREEN}✓ libssl-dev found${NC}"
openssl_found=true
fi
elif [[ "$OS" == "macos" ]]; then
if brew list openssl &>/dev/null; then
echo -e "${GREEN}✓ openssl found${NC}"
openssl_found=true
fi
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
if rpm -q openssl-devel &>/dev/null; then
echo -e "${GREEN}✓ openssl-devel found${NC}"
openssl_found=true
fi
fi

if [[ "$openssl_found" == "false" ]]; then
echo -e "${RED}✗ OpenSSL development files not found - required for nginx module build${NC}"
if [[ "$OS" == "macos" ]]; then
echo " brew install openssl"
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
echo " sudo apt-get install libssl-dev"
elif [[ "$OS" == "alpine" ]]; then
echo " apk add openssl-dev"
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
echo " sudo dnf install openssl-devel"
fi
tools_missing=1
fi

# Check zlib development files
zlib_found=false
if [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
if dpkg -l | grep -q zlib1g-dev; then
echo -e "${GREEN}✓ zlib1g-dev found${NC}"
zlib_found=true
fi
elif [[ "$OS" == "macos" ]]; then
if brew list zlib &>/dev/null; then
echo -e "${GREEN}✓ zlib found${NC}"
zlib_found=true
fi
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
if rpm -q zlib-devel &>/dev/null; then
echo -e "${GREEN}✓ zlib-devel found${NC}"
zlib_found=true
fi
fi

if [[ "$zlib_found" == "false" ]]; then
echo -e "${RED}✗ zlib development files not found - required for nginx gzip module${NC}"
if [[ "$OS" == "macos" ]]; then
echo " brew install zlib"
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
echo " sudo apt-get install zlib1g-dev"
elif [[ "$OS" == "alpine" ]]; then
echo " apk add zlib-dev"
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
echo " sudo dnf install zlib-devel"
fi
tools_missing=1
fi

# Check make
if command -v make >/dev/null 2>&1; then
echo -e "${GREEN}✓ make found: $(make --version | head -n1)${NC}"
else
echo -e "${RED}✗ make not found - required for nginx module build${NC}"
if [[ "$OS" == "macos" ]]; then
echo " xcode-select --install"
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
echo " sudo apt-get install build-essential"
elif [[ "$OS" == "alpine" ]]; then
echo " apk add make"
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
echo " sudo dnf install make"
fi
tools_missing=1
fi

# Optional: Check pkg-config (helpful for finding libraries)
if command -v pkg-config >/dev/null 2>&1; then
echo -e "${GREEN}✓ pkg-config found: $(pkg-config --version)${NC}"
else
echo -e "${YELLOW}⚠ pkg-config not found - optional but recommended${NC}"
if [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
echo " sudo apt-get install pkg-config"
fi
fi

elif [[ "$ENVIRONMENT" == "docker" ]]; then
echo -e "${YELLOW}Checking Docker development requirements...${NC}"

Expand Down Expand Up @@ -235,6 +391,15 @@ else
echo -e "${RED}✗ Some required tools are missing for ${ENVIRONMENT} development${NC}"
echo " Please install the missing tools and run this script again."
echo ""

# Provide a quick install command for Debian/Ubuntu
if [[ "$ENVIRONMENT" == "local" && ("$OS" == "debian" || "$OS" == "ubuntu") ]]; then
echo -e "${YELLOW}Quick install for Debian/Ubuntu:${NC}"
echo " sudo apt-get update"
echo " sudo apt-get install -y clang libpcre2-dev libssl-dev zlib1g-dev build-essential pkg-config"
echo ""
fi

echo " You can also try the other environment:"
if [[ "$ENVIRONMENT" == "local" ]]; then
echo " $0 --docker # Setup for Docker-based testing"
Expand All @@ -243,4 +408,4 @@ else
fi
fi

exit $tools_missing
exit $tools_missing
8 changes: 8 additions & 0 deletions tests/test-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,23 @@ create_config_from_template() {
local module_path="$LOCAL_MODULE_PATH"
local resolver="$CACHED_RESOLVER"

# Determine mime.types path based on OS
local mimetypes_path="/etc/nginx/mime.types"
if [[ "$(uname)" == "Darwin" ]]; then
mimetypes_path="/opt/homebrew/etc/nginx/mime.types"
fi

if [[ -n "$server_config" ]]; then
# Replace all placeholders
sed -e "s|TEST_SERVER_CONFIG_PLACEHOLDER|${server_config}|g" \
-e "s|MODULE_PATH_PLACEHOLDER|${module_path}|g" \
-e "s|MIMETYPES_PATH_PLACEHOLDER|${mimetypes_path}|g" \
-e "s|RESOLVER_PLACEHOLDER|${resolver}|g" \
"$template_file" > "$output_file"
else
# Replace module and resolver placeholders
sed -e "s|MODULE_PATH_PLACEHOLDER|${module_path}|g" \
-e "s|MIMETYPES_PATH_PLACEHOLDER|${mimetypes_path}|g" \
-e "s|RESOLVER_PLACEHOLDER|${resolver}|g" \
"$template_file" > "$output_file"
fi
Expand Down