Use env vars for ports, add .env.TEST

- WIZARD_PORT, MYSQL_PORT, BACKEND_PORT, FRONTEND_PORT env vars
- .env.TEST with default values (8080, 3306, 8000, 3000)
- Scripts load .env.TEST automatically
- LISTEN_ADDR uses env vars
- Ports bound to 127.0.0.1 for security
This commit is contained in:
Zhi
2026-03-14 08:20:55 +00:00
parent 392e050caa
commit 03067ca3a8
5 changed files with 60 additions and 22 deletions

14
.env.TEST Normal file
View File

@@ -0,0 +1,14 @@
# HarborForge Test Environment Variables
# Default port values
# Wizard service
WIZARD_PORT=8080
# MySQL service
MYSQL_PORT=3306
# Backend service
BACKEND_PORT=8000
# Frontend service
FRONTEND_PORT=3000

View File

@@ -8,6 +8,14 @@ set -e
EXPOSE_PORT="off"
COMPOSE_FILE="docker-compose-frontend.yml"
# Load environment variables from .env.TEST if exists
if [ -f ".env.TEST" ]; then
echo "📋 Loading .env.TEST..."
set -a
source .env.TEST
set +a
fi
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in

View File

@@ -15,6 +15,8 @@ services:
interval: 10s
timeout: 5s
retries: 5
ports:
- "127.0.0.1:${MYSQL_PORT:-3306}:3306"
networks:
- test-network
@@ -30,11 +32,11 @@ services:
- wizard_config:/config
environment:
CONFIG_DIR: /config
LISTEN_ADDR: "0.0.0.0:8080"
LISTEN_ADDR: "0.0.0.0:${WIZARD_PORT:-8080}"
MAX_BACKUPS: "5"
CORS_ORIGINS: http://localhost:18080
CORS_ORIGINS: http://127.0.0.1:${FRONTEND_PORT:-3000},http://localhost:${FRONTEND_PORT:-3000}
ports:
- "18080:8080"
- "127.0.0.1:${WIZARD_PORT:-8080}:${WIZARD_PORT:-8080}"
networks:
- test-network
@@ -52,9 +54,12 @@ services:
CONFIG_FILE: harborforge.json
SECRET_KEY: ${SECRET_KEY:-change_me_in_production}
LOG_LEVEL: ${LOG_LEVEL:-INFO}
DATABASE_URL: mysql+pymysql://harborforge:harborforge_pass@mysql:3306/harborforge
DATABASE_URL: mysql+pymysql://harborforge:harborforge_pass@mysql:${MYSQL_PORT:-3306}/harborforge
ports:
- "8000:8000"
- "127.0.0.1:${BACKEND_PORT:-8000}:${BACKEND_PORT:-8000}"
depends_on:
mysql:
condition: service_healthy
networks:
- test-network
@@ -63,15 +68,18 @@ services:
context: ../HarborForge.Frontend
dockerfile: Dockerfile
args:
VITE_WIZARD_PORT: 8080
VITE_WIZARD_PORT: ${WIZARD_PORT:-8080}
VITE_WIZARD_HOST: wizard
image: harborforge-test-frontend:dev
container_name: harborforge-test-frontend
restart: "no"
environment:
VITE_API_BASE_URL: http://localhost:8000
VITE_API_BASE_URL: http://127.0.0.1:${BACKEND_PORT:-8000}
ports:
- "3000:3000"
- "127.0.0.1:${FRONTEND_PORT:-3000}:${FRONTEND_PORT:-3000}"
depends_on:
- wizard
- backend
networks:
- test-network
@@ -83,10 +91,10 @@ services:
container_name: harborforge-test-runner
restart: "no"
environment:
BASE_URL: http://localhost:3000
WEB_SERVER_URL: http://localhost:3000
WIZARD_URL: http://localhost:18080/wizard
WIZARD_API_URL: http://localhost:18080
BASE_URL: http://localhost:${FRONTEND_PORT:-3000}
WEB_SERVER_URL: http://localhost:${FRONTEND_PORT:-3000}
WIZARD_URL: http://localhost:${WIZARD_PORT:-8080}/wizard
WIZARD_API_URL: http://localhost:${WIZARD_PORT:-8080}
CHROME_DEBUGGING_PORT: 9222
networks:
- test-network

View File

@@ -30,11 +30,11 @@ services:
- wizard_config:/config
environment:
CONFIG_DIR: /config
LISTEN_ADDR: "0.0.0.0:8080"
LISTEN_ADDR: "0.0.0.0:${WIZARD_PORT:-8080}"
MAX_BACKUPS: "5"
CORS_ORIGINS: http://frontend:3000
CORS_ORIGINS: http://frontend:${FRONTEND_PORT:-3000}
ports:
- "18080:8080"
- "127.0.0.1:${WIZARD_PORT:-8080}:${WIZARD_PORT:-8080}"
networks:
- test-network
@@ -52,7 +52,7 @@ services:
CONFIG_FILE: harborforge.json
SECRET_KEY: ${SECRET_KEY:-change_me_in_production}
LOG_LEVEL: ${LOG_LEVEL:-INFO}
DATABASE_URL: mysql+pymysql://harborforge:harborforge_pass@mysql:3306/harborforge
DATABASE_URL: mysql+pymysql://harborforge:harborforge_pass@mysql:${MYSQL_PORT:-3306}/harborforge
networks:
- test-network
@@ -61,13 +61,13 @@ services:
context: ../HarborForge.Frontend
dockerfile: Dockerfile
args:
VITE_WIZARD_PORT: 8080
VITE_WIZARD_PORT: ${WIZARD_PORT:-8080}
VITE_WIZARD_HOST: wizard
image: harborforge-test-frontend:dev
container_name: harborforge-test-frontend
restart: "no"
environment:
VITE_API_BASE_URL: http://backend:8000
VITE_API_BASE_URL: http://backend:${BACKEND_PORT:-8000}
networks:
- test-network
@@ -79,10 +79,10 @@ services:
container_name: harborforge-test-runner
restart: "no"
environment:
BASE_URL: http://frontend:3000
WEB_SERVER_URL: http://frontend:3000
WIZARD_URL: http://wizard:8080/wizard
WIZARD_API_URL: http://wizard:8080
BASE_URL: http://frontend:${FRONTEND_PORT:-3000}
WEB_SERVER_URL: http://frontend:${FRONTEND_PORT:-3000}
WIZARD_URL: http://wizard:${WIZARD_PORT:-8080}/wizard
WIZARD_API_URL: http://wizard:${WIZARD_PORT:-8080}
CHROME_DEBUGGING_PORT: 9222
networks:
- test-network

View File

@@ -8,6 +8,14 @@ set -e
EXPOSE_PORT="off"
COMPOSE_FILE="docker-compose-frontend.yml"
# Load environment variables from .env.TEST if exists
if [ -f ".env.TEST" ]; then
echo "📋 Loading .env.TEST..."
set -a
source .env.TEST
set +a
fi
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in