Archived
1
0

fix: Определение сети в скрипте запуска

This commit is contained in:
2025-11-27 18:08:55 +03:00
parent 52efc2fe23
commit 81d39799ac

View File

@ -29,13 +29,9 @@ echo -e "${YELLOW}📦 Step 1: Starting Docker services (PostgreSQL, Redis, Seaw
docker compose up -d docker compose up -d
# Get the actual network name from docker compose (it adds project prefix) # Get the actual network name from docker compose (it adds project prefix)
# Docker Compose uses directory name as project prefix, so network will be {project}_p1ctos4ve-network
NETWORK_NAME=$(docker network ls --format "{{.Name}}" | grep "p1ctos4ve-network" | head -n 1) NETWORK_NAME=$(docker network ls --format "{{.Name}}" | grep "p1ctos4ve-network" | head -n 1)
# Fallback to default if not found
if [ -z "$NETWORK_NAME" ]; then if [ -z "$NETWORK_NAME" ]; then
# Try to get from docker compose config
NETWORK_NAME=$(docker compose config 2>/dev/null | grep -A 2 "networks:" | grep "name:" | awk '{print $2}' | tr -d '"' | head -n 1) NETWORK_NAME=$(docker compose config 2>/dev/null | grep -A 2 "networks:" | grep "name:" | awk '{print $2}' | tr -d '"' | head -n 1)
# Final fallback
if [ -z "$NETWORK_NAME" ]; then if [ -z "$NETWORK_NAME" ]; then
NETWORK_NAME="p1ctos4ve-network" NETWORK_NAME="p1ctos4ve-network"
fi fi
@ -100,9 +96,7 @@ sleep 2
# Create S3 bucket in SeaweedFS if it doesn't exist # Create S3 bucket in SeaweedFS if it doesn't exist
echo -e "${YELLOW}📦 Creating S3 bucket in SeaweedFS...${NC}" echo -e "${YELLOW}📦 Creating S3 bucket in SeaweedFS...${NC}"
BUCKET_NAME="p1ctos4ve" BUCKET_NAME="p1ctos4ve"
# Try to create bucket via S3 API (using AWS CLI-like approach)
if ! curl -s -X PUT "http://localhost:8333/${BUCKET_NAME}" > /dev/null 2>&1; then if ! curl -s -X PUT "http://localhost:8333/${BUCKET_NAME}" > /dev/null 2>&1; then
# Alternative: create via filer API
curl -X PUT "http://localhost:8888/buckets/${BUCKET_NAME}" > /dev/null 2>&1 || true curl -X PUT "http://localhost:8888/buckets/${BUCKET_NAME}" > /dev/null 2>&1 || true
fi fi
echo -e "${GREEN}✓ Bucket ready${NC}" echo -e "${GREEN}✓ Bucket ready${NC}"
@ -116,7 +110,7 @@ docker build -t p1ctos4ve-backend:latest -f apps/backend/Dockerfile .
echo -e "${YELLOW}🗄️ Step 3: Running database migrations...${NC}" echo -e "${YELLOW}🗄️ Step 3: Running database migrations...${NC}"
docker run --rm \ docker run --rm \
--network "${NETWORK_NAME}" \ --network "${NETWORK_NAME}" \
-e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@host.docker.internal:5432/p1ctos4ve" \ -e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@postgres:5432/p1ctos4ve" \
-e REDIS_URL="redis://redis:6379" \ -e REDIS_URL="redis://redis:6379" \
-e S3_ENDPOINT="http://seaweedfs-s3:8333" \ -e S3_ENDPOINT="http://seaweedfs-s3:8333" \
-e S3_REGION="us-east-1" \ -e S3_REGION="us-east-1" \
@ -124,7 +118,7 @@ docker run --rm \
-e S3_ACCESS_KEY_ID="any" \ -e S3_ACCESS_KEY_ID="any" \
-e S3_SECRET_ACCESS_KEY="any" \ -e S3_SECRET_ACCESS_KEY="any" \
-e S3_FORCE_PATH_STYLE="true" \ -e S3_FORCE_PATH_STYLE="true" \
-e BETTER_AUTH_SECRET="$(openssl rand -hex 32)" \ -e BETTER_AUTH_SECRET="$(openssl rand-hex 32 2>/dev/null || openssl rand -hex 32)" \
-e BETTER_AUTH_URL="http://localhost:3000" \ -e BETTER_AUTH_URL="http://localhost:3000" \
-e BASE_URL="http://localhost:3000" \ -e BASE_URL="http://localhost:3000" \
-e NODE_ENV="production" \ -e NODE_ENV="production" \
@ -136,15 +130,15 @@ docker run --rm \
echo -e "${YELLOW}🧪 Step 4: Running unit tests...${NC}" echo -e "${YELLOW}🧪 Step 4: Running unit tests...${NC}"
docker run --rm \ docker run --rm \
--network "${NETWORK_NAME}" \ --network "${NETWORK_NAME}" \
-e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@host.docker.internal:5432/p1ctos4ve" \ -e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@postgres:5432/p1ctos4ve" \
-e REDIS_URL="redis://host.docker.internal:6379" \ -e REDIS_URL="redis://redis:6379" \
-e S3_ENDPOINT="http://host.docker.internal:8333" \ -e S3_ENDPOINT="http://seaweedfs-s3:8333" \
-e S3_REGION="us-east-1" \ -e S3_REGION="us-east-1" \
-e S3_BUCKET="${BUCKET_NAME}" \ -e S3_BUCKET="${BUCKET_NAME}" \
-e S3_ACCESS_KEY_ID="any" \ -e S3_ACCESS_KEY_ID="any" \
-e S3_SECRET_ACCESS_KEY="any" \ -e S3_SECRET_ACCESS_KEY="any" \
-e S3_FORCE_PATH_STYLE="true" \ -e S3_FORCE_PATH_STYLE="true" \
-e BETTER_AUTH_SECRET="$(openssl rand -hex 32)" \ -e BETTER_AUTH_SECRET="$(openssl rand-hex 32 2>/dev/null || openssl rand -hex 32)" \
-e BETTER_AUTH_URL="http://localhost:3000" \ -e BETTER_AUTH_URL="http://localhost:3000" \
-e BASE_URL="http://localhost:3000" \ -e BASE_URL="http://localhost:3000" \
-e NODE_ENV="test" \ -e NODE_ENV="test" \
@ -152,7 +146,9 @@ docker run --rm \
p1ctos4ve-backend:latest \ p1ctos4ve-backend:latest \
bun test src/tests/unit/ bun test src/tests/unit/
if [ $? -eq 0 ]; then UNIT_EXIT_CODE=$?
if [ $UNIT_EXIT_CODE -eq 0 ]; then
echo -e "${GREEN}✓ Unit tests passed${NC}" echo -e "${GREEN}✓ Unit tests passed${NC}"
else else
echo -e "${RED}✗ Unit tests failed${NC}" echo -e "${RED}✗ Unit tests failed${NC}"
@ -162,21 +158,20 @@ fi
# Step 5: Run integration tests # Step 5: Run integration tests
echo -e "${YELLOW}🔗 Step 5: Running integration tests...${NC}" echo -e "${YELLOW}🔗 Step 5: Running integration tests...${NC}"
# Start backend server in background for e2e tests
echo -e "${YELLOW}Starting backend server for e2e tests...${NC}" echo -e "${YELLOW}Starting backend server for e2e tests...${NC}"
BACKEND_CONTAINER=$(docker run -d \ BACKEND_CONTAINER=$(docker run -d \
--name p1ctos4ve-backend-test \ --name p1ctos4ve-backend-test \
--network "${NETWORK_NAME}" \ --network "${NETWORK_NAME}" \
-p 3000:3000 \ -p 3000:3000 \
-e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@host.docker.internal:5432/p1ctos4ve" \ -e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@postgres:5432/p1ctos4ve" \
-e REDIS_URL="redis://host.docker.internal:6379" \ -e REDIS_URL="redis://redis:6379" \
-e S3_ENDPOINT="http://host.docker.internal:8333" \ -e S3_ENDPOINT="http://seaweedfs-s3:8333" \
-e S3_REGION="us-east-1" \ -e S3_REGION="us-east-1" \
-e S3_BUCKET="${BUCKET_NAME}" \ -e S3_BUCKET="${BUCKET_NAME}" \
-e S3_ACCESS_KEY_ID="any" \ -e S3_ACCESS_KEY_ID="any" \
-e S3_SECRET_ACCESS_KEY="any" \ -e S3_SECRET_ACCESS_KEY="any" \
-e S3_FORCE_PATH_STYLE="true" \ -e S3_FORCE_PATH_STYLE="true" \
-e BETTER_AUTH_SECRET="$(openssl rand -hex 32)" \ -e BETTER_AUTH_SECRET="$(openssl rand-hex 32 2>/dev/null || openssl rand -hex 32)" \
-e BETTER_AUTH_URL="http://localhost:3000" \ -e BETTER_AUTH_URL="http://localhost:3000" \
-e BASE_URL="http://localhost:3000" \ -e BASE_URL="http://localhost:3000" \
-e NODE_ENV="test" \ -e NODE_ENV="test" \
@ -194,20 +189,19 @@ for i in {1..30}; do
done done
echo -e " ${GREEN}${NC}" echo -e " ${GREEN}${NC}"
# Run e2e tests in the same container (server runs in background via exec) # Try e2e tests inside backend container
# This way tests can access localhost:3000
docker exec p1ctos4ve-backend-test sh -c "bun test --preload ./src/tests/setup.ts src/tests/e2e/" || \ docker exec p1ctos4ve-backend-test sh -c "bun test --preload ./src/tests/setup.ts src/tests/e2e/" || \
docker run --rm \ docker run --rm \
--network "${NETWORK_NAME}" \ --network "${NETWORK_NAME}" \
-e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@host.docker.internal:5432/p1ctos4ve" \ -e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@postgres:5432/p1ctos4ve" \
-e REDIS_URL="redis://host.docker.internal:6379" \ -e REDIS_URL="redis://redis:6379" \
-e S3_ENDPOINT="http://host.docker.internal:8333" \ -e S3_ENDPOINT="http://seaweedfs-s3:8333" \
-e S3_REGION="us-east-1" \ -e S3_REGION="us-east-1" \
-e S3_BUCKET="${BUCKET_NAME}" \ -e S3_BUCKET="${BUCKET_NAME}" \
-e S3_ACCESS_KEY_ID="any" \ -e S3_ACCESS_KEY_ID="any" \
-e S3_SECRET_ACCESS_KEY="any" \ -e S3_SECRET_ACCESS_KEY="any" \
-e S3_FORCE_PATH_STYLE="true" \ -e S3_FORCE_PATH_STYLE="true" \
-e BETTER_AUTH_SECRET="$(openssl rand -hex 32)" \ -e BETTER_AUTH_SECRET="$(openssl rand-hex 32 2>/dev/null || openssl rand -hex 32)" \
-e BETTER_AUTH_URL="http://p1ctos4ve-backend-test:3000" \ -e BETTER_AUTH_URL="http://p1ctos4ve-backend-test:3000" \
-e BASE_URL="http://p1ctos4ve-backend-test:3000" \ -e BASE_URL="http://p1ctos4ve-backend-test:3000" \
-e NODE_ENV="test" \ -e NODE_ENV="test" \
@ -217,7 +211,6 @@ docker run --rm \
TEST_EXIT_CODE=$? TEST_EXIT_CODE=$?
# Stop and remove backend test container
echo -e "${YELLOW}Stopping test backend server...${NC}" echo -e "${YELLOW}Stopping test backend server...${NC}"
docker stop p1ctos4ve-backend-test > /dev/null 2>&1 || true docker stop p1ctos4ve-backend-test > /dev/null 2>&1 || true
docker rm p1ctos4ve-backend-test > /dev/null 2>&1 || true docker rm p1ctos4ve-backend-test > /dev/null 2>&1 || true
@ -237,18 +230,17 @@ echo -e "${YELLOW}Press Ctrl+C to stop${NC}"
docker run --rm \ docker run --rm \
--network "${NETWORK_NAME}" \ --network "${NETWORK_NAME}" \
-p 3000:3000 \ -p 3000:3000 \
-e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@host.docker.internal:5432/p1ctos4ve" \ -e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@postgres:5432/p1ctos4ve" \
-e REDIS_URL="redis://host.docker.internal:6379" \ -e REDIS_URL="redis://redis:6379" \
-e S3_ENDPOINT="http://host.docker.internal:8333" \ -e S3_ENDPOINT="http://seaweedfs-s3:8333" \
-e S3_REGION="us-east-1" \ -e S3_REGION="us-east-1" \
-e S3_BUCKET="${BUCKET_NAME}" \ -e S3_BUCKET="${BUCKET_NAME}" \
-e S3_ACCESS_KEY_ID="any" \ -e S3_ACCESS_KEY_ID="any" \
-e S3_SECRET_ACCESS_KEY="any" \ -e S3_SECRET_ACCESS_KEY="any" \
-e S3_FORCE_PATH_STYLE="true" \ -e S3_FORCE_PATH_STYLE="true" \
-e BETTER_AUTH_SECRET="$(openssl rand -hex 32)" \ -e BETTER_AUTH_SECRET="$(openssl rand-hex 32 2>/dev/null || openssl rand -hex 32)" \
-e BETTER_AUTH_URL="http://localhost:3000" \ -e BETTER_AUTH_URL="http://localhost:3000" \
-e BASE_URL="http://localhost:3000" \ -e BASE_URL="http://localhost:3000" \
-e NODE_ENV="production" \ -e NODE_ENV="production" \
-e PORT="3000" \ -e PORT="3000" \
p1ctos4ve-backend:latest p1ctos4ve-backend:latest