refactor(backend): standardize errors and simplify configuration and test setup
This commit is contained in:
1 parent
1535c19b8c
commit
138666a7bb
92 files changed
+3994
-210
No files matched your search
+1
-1
@@ -28,7 +28,7 @@ config: ## Render all Compose files with safe example values
|
||||
build: ## Build local frontend and backend images
|
||||
APP_PROJECT="$(APP_PROJECT)" $(DOCKER) compose --env-file "$(CHECK_ENV_FILE)" -p "$(APP_PROJECT)" -f "$(CORE_FILE)" build
|
||||
|
||||
up: ## Start the core app and PostgreSQL without monitoring
|
||||
up: ## Start the core app, PostgreSQL, Redis, and SeaweedFS without monitoring
|
||||
@test -f "$(ENV_FILE)" || { printf 'Missing %s. Copy .env.example to .env and replace the placeholder passwords.\n' "$(ENV_FILE)" >&2; exit 2; }
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" $(DOCKER) compose --env-file "$(ENV_FILE)" -p "$(APP_PROJECT)" -f "$(CORE_FILE)" up -d
|
||||
|
||||
|
||||
@@ -98,6 +98,34 @@ services:
|
||||
cpus: "0.25"
|
||||
memory: 128M
|
||||
|
||||
redis-exporter:
|
||||
image: oliver006/redis_exporter:latest
|
||||
environment:
|
||||
REDIS_ADDR: redis://redis:6379
|
||||
REDIS_PASSWORD: ${REDIS_PASSWORD:?Set REDIS_PASSWORD in the root .env file}
|
||||
REDIS_EXPORTER_CONNECTION_TIMEOUT: 2s
|
||||
expose:
|
||||
- "9121"
|
||||
networks:
|
||||
- observability
|
||||
- app
|
||||
read_only: true
|
||||
cap_drop:
|
||||
- ALL
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 10m
|
||||
max-file: "3"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.25"
|
||||
memory: 128M
|
||||
|
||||
node-exporter:
|
||||
image: prom/node-exporter:latest
|
||||
command:
|
||||
|
||||
@@ -28,15 +28,104 @@ services:
|
||||
cpus: "1.0"
|
||||
memory: 2G
|
||||
|
||||
redis:
|
||||
image: redis:alpine
|
||||
environment:
|
||||
REDIS_PASSWORD: ${REDIS_PASSWORD:?Set REDIS_PASSWORD in the root .env file}
|
||||
command:
|
||||
- /bin/sh
|
||||
- -ec
|
||||
- |
|
||||
exec docker-entrypoint.sh redis-server \
|
||||
--requirepass "$${REDIS_PASSWORD}" \
|
||||
--maxmemory 128mb --maxmemory-policy allkeys-lru \
|
||||
--save "" --appendonly no
|
||||
tmpfs:
|
||||
- /data:size=16m,mode=1777
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "test \"$$(REDISCLI_AUTH=\"$${REDIS_PASSWORD}\" redis-cli ping)\" = PONG"]
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
retries: 5
|
||||
start_period: 5s
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 10m
|
||||
max-file: "3"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.5"
|
||||
memory: 256M
|
||||
|
||||
seaweedfs:
|
||||
image: chrislusf/seaweedfs:latest
|
||||
command:
|
||||
- mini
|
||||
- -dir=/data
|
||||
- -ip=seaweedfs
|
||||
- -ip.bind=0.0.0.0
|
||||
- -webdav=false
|
||||
- -admin.ui=false
|
||||
- -s3.iam=false
|
||||
- -s3.port.iceberg=0
|
||||
- -s3.port.lance=0
|
||||
- -s3.autoCreateBucket=false
|
||||
- -s3.allowDeleteBucketNotEmpty=false
|
||||
- -master.telemetry=false
|
||||
- -metricsPort=9327
|
||||
environment:
|
||||
AWS_ACCESS_KEY_ID: ${SEAWEEDFS_ACCESS_KEY:?Set SEAWEEDFS_ACCESS_KEY in the root .env file}
|
||||
AWS_SECRET_ACCESS_KEY: ${SEAWEEDFS_SECRET_KEY:?Set SEAWEEDFS_SECRET_KEY in the root .env file}
|
||||
S3_BUCKET: ${SEAWEEDFS_BUCKET:?Set SEAWEEDFS_BUCKET in the root .env file}
|
||||
volumes:
|
||||
- seaweedfs_data:/data
|
||||
expose:
|
||||
- "8333"
|
||||
- "9327"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:9333/cluster/healthz >/dev/null && nc -z 127.0.0.1 8333"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
start_period: 15s
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 10m
|
||||
max-file: "3"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "1.0"
|
||||
memory: 1G
|
||||
|
||||
backend:
|
||||
build:
|
||||
context: ../../backend
|
||||
dockerfile: Dockerfile
|
||||
environment:
|
||||
DATABASE_URL: postgres://${POSTGRES_USER:?Set POSTGRES_USER}:${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:?Set POSTGRES_DB}?sslmode=disable
|
||||
REDIS_ADDR: redis:6379
|
||||
REDIS_PASSWORD: ${REDIS_PASSWORD:?Set REDIS_PASSWORD in the root .env file}
|
||||
REDIS_DB: "0"
|
||||
REDIS_TIMEOUT: 1s
|
||||
SEAWEEDFS_ENDPOINT: http://seaweedfs:8333
|
||||
SEAWEEDFS_ACCESS_KEY: ${SEAWEEDFS_ACCESS_KEY:?Set SEAWEEDFS_ACCESS_KEY in the root .env file}
|
||||
SEAWEEDFS_SECRET_KEY: ${SEAWEEDFS_SECRET_KEY:?Set SEAWEEDFS_SECRET_KEY in the root .env file}
|
||||
SEAWEEDFS_BUCKET: ${SEAWEEDFS_BUCKET:?Set SEAWEEDFS_BUCKET in the root .env file}
|
||||
SEAWEEDFS_REGION: us-east-1
|
||||
SEAWEEDFS_TIMEOUT: 10s
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
seaweedfs:
|
||||
condition: service_healthy
|
||||
expose:
|
||||
- "8080"
|
||||
- "9090"
|
||||
@@ -82,6 +171,8 @@ services:
|
||||
volumes:
|
||||
postgres_data:
|
||||
name: ${APP_PROJECT:-app}_postgres_data
|
||||
seaweedfs_data:
|
||||
name: ${APP_PROJECT:-app}_seaweedfs_data
|
||||
|
||||
networks:
|
||||
default:
|
||||
|
||||
+52
-11
@@ -7,7 +7,6 @@ env_file="$root/.env.example"
|
||||
project=lincodex-smoke
|
||||
app_network="${project}_default"
|
||||
port=18080
|
||||
volume="${project}_postgres_data"
|
||||
network="${project}_default"
|
||||
started=0
|
||||
|
||||
@@ -19,10 +18,12 @@ compose() {
|
||||
"$@"
|
||||
}
|
||||
|
||||
if docker volume inspect "$volume" >/dev/null 2>&1; then
|
||||
printf 'Refusing to use existing smoke volume %s.\n' "$volume" >&2
|
||||
exit 2
|
||||
fi
|
||||
for volume in "${project}_postgres_data" "${project}_seaweedfs_data"; do
|
||||
if docker volume inspect "$volume" >/dev/null 2>&1; then
|
||||
printf 'Refusing to use existing smoke volume %s.\n' "$volume" >&2
|
||||
exit 2
|
||||
fi
|
||||
done
|
||||
if docker network inspect "$network" >/dev/null 2>&1; then
|
||||
printf 'Refusing to use existing smoke network %s.\n' "$network" >&2
|
||||
exit 2
|
||||
@@ -68,17 +69,57 @@ wait_for() {
|
||||
return 1
|
||||
}
|
||||
|
||||
wait_for_readiness() {
|
||||
local attempt response
|
||||
for attempt in {1..30}; do
|
||||
response=$(compose exec -T frontend wget -q -O - http://backend:8080/readyz 2>/dev/null || true)
|
||||
if [[ "$response" == '{"status":"ready"}' ]]; then
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
printf '%s\n' 'Timed out waiting for PostgreSQL, Redis, and SeaweedFS readiness.' >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
wait_for "http://127.0.0.1:$port/healthz"
|
||||
wait_for "http://127.0.0.1:$port/api/v1/healthz"
|
||||
readiness=$(compose exec -T frontend wget -q -O - http://backend:8080/readyz)
|
||||
if [[ "$readiness" != '{"status":"ready"}' ]]; then
|
||||
printf 'Backend did not confirm database readiness: %s\n' "$readiness" >&2
|
||||
exit 1
|
||||
fi
|
||||
wait_for_readiness
|
||||
status=$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' \
|
||||
"http://127.0.0.1:$port/api/v1/missing")
|
||||
if [[ "$status" != 404 ]]; then
|
||||
printf 'Unknown API route returned %s instead of 404.\n' "$status" >&2
|
||||
exit 1
|
||||
fi
|
||||
printf '%s\n' 'Technical smoke passed: frontend, API routing, and PostgreSQL readiness.'
|
||||
compose exec -T redis sh -ec '
|
||||
test "$(redis-cli ping)" = "NOAUTH Authentication required."
|
||||
export REDISCLI_AUTH="$REDIS_PASSWORD"
|
||||
test "$(redis-cli ping)" = PONG
|
||||
test "$(redis-cli --raw CONFIG GET maxmemory-policy | tail -n 1)" = allkeys-lru
|
||||
test "$(redis-cli --raw CONFIG GET appendonly | tail -n 1)" = no
|
||||
test -z "$(redis-cli --raw CONFIG GET save | tail -n 1)"
|
||||
'
|
||||
compose stop redis
|
||||
readiness=$(compose exec -T frontend wget -S -O /dev/null http://backend:8080/readyz 2>&1 || true)
|
||||
if [[ "$readiness" != *"503 Service Unavailable"* ]]; then
|
||||
printf 'Backend did not return 503 when Redis stopped: %s\n' "$readiness" >&2
|
||||
exit 1
|
||||
fi
|
||||
curl --fail --silent --show-error "http://127.0.0.1:$port/api/v1/healthz" >/dev/null
|
||||
compose up -d --wait --wait-timeout 60 redis
|
||||
wait_for_readiness
|
||||
anonymous=$(compose exec -T seaweedfs sh -c 'wget -S -O /dev/null "http://127.0.0.1:8333/$S3_BUCKET"' 2>&1 || true)
|
||||
if [[ "$anonymous" != *"403 Forbidden"* ]]; then
|
||||
printf 'SeaweedFS did not reject anonymous bucket access: %s\n' "$anonymous" >&2
|
||||
exit 1
|
||||
fi
|
||||
compose stop seaweedfs
|
||||
readiness=$(compose exec -T frontend wget -S -O /dev/null http://backend:8080/readyz 2>&1 || true)
|
||||
if [[ "$readiness" != *"503 Service Unavailable"* ]]; then
|
||||
printf 'Backend did not return 503 when SeaweedFS stopped: %s\n' "$readiness" >&2
|
||||
exit 1
|
||||
fi
|
||||
curl --fail --silent --show-error "http://127.0.0.1:$port/api/v1/healthz" >/dev/null
|
||||
compose up -d --wait --wait-timeout 90 seaweedfs
|
||||
wait_for_readiness
|
||||
printf '%s\n' 'Technical smoke passed: frontend, API routing, PostgreSQL, Redis, SeaweedFS, dependency recovery, and storage authentication.'
|
||||
Reference in new issue
Block a user