From d4e0f25f998a1506b1c6bcd966313e5061db3226 Mon Sep 17 00:00:00 2001 From: Mark Zheleznyakov Date: Thu, 27 Nov 2025 18:13:06 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=20d?= =?UTF-8?q?ocker-compose=20=D0=B8=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D1=80=D0=B0=D0=B7=D0=B2=D0=B5=D1=80=D1=82?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B2=20run.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 137 ---------------------------------- scripts/run.sh | 182 +++++++++++++++++++++++++++++++++------------ 2 files changed, 134 insertions(+), 185 deletions(-) delete mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 70ab450..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,137 +0,0 @@ -version: '3.8' - -services: - postgres: - image: postgres:16 - container_name: p1ctos4ve-postgres - environment: - POSTGRES_USER: p1ctos4ve - POSTGRES_PASSWORD: p1ctos4ve_password - POSTGRES_DB: p1ctos4ve - ports: - - "5432:5432" - volumes: - - postgres_data:/var/lib/postgresql/data - healthcheck: - test: ["CMD-SHELL", "pg_isready -U p1ctos4ve"] - interval: 5s - timeout: 5s - retries: 5 - networks: - - p1ctos4ve-network - - redis: - image: redis:7-alpine - container_name: p1ctos4ve-redis - ports: - - "6379:6379" - volumes: - - redis_data:/data - healthcheck: - test: ["CMD", "redis-cli", "ping"] - interval: 5s - timeout: 3s - retries: 5 - networks: - - p1ctos4ve-network - - seaweedfs-master: - image: chrislusf/seaweedfs:latest - container_name: p1ctos4ve-seaweedfs-master - command: "master -ip=seaweedfs-master" - ports: - - "9333:9333" - - "19333:19333" - volumes: - - seaweedfs_master_data:/data - networks: - - p1ctos4ve-network - - seaweedfs-volume: - image: chrislusf/seaweedfs:latest - container_name: p1ctos4ve-seaweedfs-volume - command: "volume -mserver=seaweedfs-master:9333 -port=8080" - ports: - - "8080:8080" - depends_on: - - seaweedfs-master - volumes: - - seaweedfs_volume_data:/data - networks: - - p1ctos4ve-network - - seaweedfs-filer: - image: chrislusf/seaweedfs:latest - container_name: p1ctos4ve-seaweedfs-filer - command: "filer -master=seaweedfs-master:9333" - ports: - - "8888:8888" - depends_on: - - seaweedfs-master - volumes: - - seaweedfs_filer_data:/data - networks: - - p1ctos4ve-network - - seaweedfs-s3: - image: chrislusf/seaweedfs:latest - container_name: p1ctos4ve-seaweedfs-s3 - entrypoint: ["/bin/sh", "-c"] - command: - - | - mkdir -p /data - cat > /data/s3.json << 'EOF' - { - "identities": [ - { - "name": "anonymous", - "credentials": [ - { - "accessKey": "", - "secretKey": "" - } - ], - "actions": ["Read:p1ctos4ve"] - }, - { - "name": "any", - "credentials": [ - { - "accessKey": "any", - "secretKey": "any" - } - ], - "actions": ["Admin", "Read", "Write"] - } - ] - } - EOF - exec /entrypoint.sh s3 -filer=seaweedfs-filer:8888 -port=8333 -ip.bind=0.0.0.0 -config=/data/s3.json - ports: - - "8333:8333" - depends_on: - - seaweedfs-master - - seaweedfs-volume - - seaweedfs-filer - volumes: - - seaweedfs_s3_data:/data - networks: - - p1ctos4ve-network - -volumes: - postgres_data: - driver: local - redis_data: - driver: local - seaweedfs_master_data: - driver: local - seaweedfs_volume_data: - driver: local - seaweedfs_filer_data: - driver: local - seaweedfs_s3_data: - driver: local - -networks: - p1ctos4ve-network: - driver: bridge diff --git a/scripts/run.sh b/scripts/run.sh index 525bede..bba96b6 100644 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -11,7 +11,9 @@ NC='\033[0m' # No Color # Cleanup function cleanup() { echo -e "\n${YELLOW}Cleaning up...${NC}" - docker compose down + docker stop p1ctos4ve-postgres p1ctos4ve-redis p1ctos4ve-seaweedfs-master p1ctos4ve-seaweedfs-volume p1ctos4ve-seaweedfs-filer p1ctos4ve-seaweedfs-s3 2>/dev/null || true + docker rm p1ctos4ve-postgres p1ctos4ve-redis p1ctos4ve-seaweedfs-master p1ctos4ve-seaweedfs-volume p1ctos4ve-seaweedfs-filer p1ctos4ve-seaweedfs-s3 2>/dev/null || true + docker network rm p1ctos4ve-network 2>/dev/null || true exit 0 } @@ -24,26 +26,109 @@ cd "$PROJECT_ROOT" echo -e "${GREEN}๐Ÿš€ Starting p1ctos4ve backend setup...${NC}" -# Step 1: Start Docker services -echo -e "${YELLOW}๐Ÿ“ฆ Step 1: Starting Docker services (PostgreSQL, Redis, SeaweedFS)...${NC}" -docker compose up -d +# Step 1: Create network +echo -e "${YELLOW}๐ŸŒ Step 1: Creating Docker network...${NC}" +docker network create p1ctos4ve-network 2>/dev/null || echo "Network already exists" +NETWORK_NAME="p1ctos4ve-network" -# Get the actual network name from docker compose (it adds project prefix) -NETWORK_NAME=$(docker network ls --format "{{.Name}}" | grep "p1ctos4ve-network" | head -n 1) -if [ -z "$NETWORK_NAME" ]; then - NETWORK_NAME=$(docker compose config 2>/dev/null | grep -A 2 "networks:" | grep "name:" | awk '{print $2}' | tr -d '"' | head -n 1) - if [ -z "$NETWORK_NAME" ]; then - NETWORK_NAME="p1ctos4ve-network" - fi -fi -echo -e "${YELLOW}Using network: ${NETWORK_NAME}${NC}" +# Step 2: Start PostgreSQL +echo -e "${YELLOW}๐Ÿ“ฆ Step 2: Starting PostgreSQL...${NC}" +docker run -d \ + --name p1ctos4ve-postgres \ + --network "${NETWORK_NAME}" \ + -p 5432:5432 \ + -e POSTGRES_USER=p1ctos4ve \ + -e POSTGRES_PASSWORD=p1ctos4ve_password \ + -e POSTGRES_DB=p1ctos4ve \ + -v p1ctos4ve-postgres-data:/var/lib/postgresql/data \ + postgres:16 + +# Step 3: Start Redis +echo -e "${YELLOW}๐Ÿ“ฆ Step 3: Starting Redis...${NC}" +docker run -d \ + --name p1ctos4ve-redis \ + --network "${NETWORK_NAME}" \ + -p 6379:6379 \ + -v p1ctos4ve-redis-data:/data \ + redis:7-alpine + +# Step 4: Start SeaweedFS Master +echo -e "${YELLOW}๐Ÿ“ฆ Step 4: Starting SeaweedFS Master...${NC}" +docker run -d \ + --name p1ctos4ve-seaweedfs-master \ + --network "${NETWORK_NAME}" \ + -p 9333:9333 \ + -p 19333:19333 \ + -v p1ctos4ve-seaweedfs-master-data:/data \ + chrislusf/seaweedfs:latest \ + master -ip=p1ctos4ve-seaweedfs-master + +# Step 5: Start SeaweedFS Volume +echo -e "${YELLOW}๐Ÿ“ฆ Step 5: Starting SeaweedFS Volume...${NC}" +docker run -d \ + --name p1ctos4ve-seaweedfs-volume \ + --network "${NETWORK_NAME}" \ + -p 8080:8080 \ + -v p1ctos4ve-seaweedfs-volume-data:/data \ + chrislusf/seaweedfs:latest \ + volume -mserver=p1ctos4ve-seaweedfs-master:9333 -port=8080 + +# Step 6: Start SeaweedFS Filer +echo -e "${YELLOW}๐Ÿ“ฆ Step 6: Starting SeaweedFS Filer...${NC}" +docker run -d \ + --name p1ctos4ve-seaweedfs-filer \ + --network "${NETWORK_NAME}" \ + -p 8888:8888 \ + -v p1ctos4ve-seaweedfs-filer-data:/data \ + chrislusf/seaweedfs:latest \ + filer -master=p1ctos4ve-seaweedfs-master:9333 + +# Step 7: Start SeaweedFS S3 +echo -e "${YELLOW}๐Ÿ“ฆ Step 7: Starting SeaweedFS S3...${NC}" +docker run -d \ + --name p1ctos4ve-seaweedfs-s3 \ + --network "${NETWORK_NAME}" \ + -p 8333:8333 \ + -v p1ctos4ve-seaweedfs-s3-data:/data \ + --entrypoint /bin/sh \ + chrislusf/seaweedfs:latest \ + -c 'mkdir -p /data && cat > /data/s3.json << '\''EOF'\'' +{ + "identities": [ + { + "name": "anonymous", + "credentials": [ + { + "accessKey": "", + "secretKey": "" + } + ], + "actions": ["Read:p1ctos4ve"] + }, + { + "name": "any", + "credentials": [ + { + "accessKey": "any", + "secretKey": "any" + } + ], + "actions": ["Admin", "Read", "Write"] + } + ] +} +EOF +exec /entrypoint.sh s3 -filer=p1ctos4ve-seaweedfs-filer:8888 -port=8333 -ip.bind=0.0.0.0 -config=/data/s3.json' # Wait for services to be healthy echo -e "${YELLOW}โณ Waiting for services to be ready...${NC}" # Wait for PostgreSQL echo -n "Waiting for PostgreSQL..." -until docker exec p1ctos4ve-postgres pg_isready -U p1ctos4ve > /dev/null 2>&1; do +for i in {1..30}; do + if docker exec p1ctos4ve-postgres pg_isready -U p1ctos4ve > /dev/null 2>&1; then + break + fi echo -n "." sleep 1 done @@ -51,7 +136,10 @@ echo -e " ${GREEN}โœ“${NC}" # Wait for Redis echo -n "Waiting for Redis..." -until docker exec p1ctos4ve-redis redis-cli ping > /dev/null 2>&1; do +for i in {1..30}; do + if docker exec p1ctos4ve-redis redis-cli ping > /dev/null 2>&1; then + break + fi echo -n "." sleep 1 done @@ -90,7 +178,6 @@ for i in {1..30}; do done echo -e " ${GREEN}โœ“${NC}" -# Wait a bit more for SeaweedFS to fully initialize sleep 2 # Create S3 bucket in SeaweedFS if it doesn't exist @@ -101,24 +188,23 @@ if ! curl -s -X PUT "http://localhost:8333/${BUCKET_NAME}" > /dev/null 2>&1; the fi echo -e "${GREEN}โœ“ Bucket ready${NC}" -# Step 2: Build backend -echo -e "${YELLOW}๐Ÿ”จ Step 2: Building backend...${NC}" -cd "$PROJECT_ROOT" +# Step 8: Build backend +echo -e "${YELLOW}๐Ÿ”จ Step 8: Building backend...${NC}" docker build -t p1ctos4ve-backend:latest -f apps/backend/Dockerfile . -# Step 3: Run migrations -echo -e "${YELLOW}๐Ÿ—„๏ธ Step 3: Running database migrations...${NC}" +# Step 9: Run migrations +echo -e "${YELLOW}๐Ÿ—„๏ธ Step 9: Running database migrations...${NC}" docker run --rm \ --network "${NETWORK_NAME}" \ - -e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@postgres:5432/p1ctos4ve" \ - -e REDIS_URL="redis://redis:6379" \ - -e S3_ENDPOINT="http://seaweedfs-s3:8333" \ + -e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@p1ctos4ve-postgres:5432/p1ctos4ve" \ + -e REDIS_URL="redis://p1ctos4ve-redis:6379" \ + -e S3_ENDPOINT="http://p1ctos4ve-seaweedfs-s3:8333" \ -e S3_REGION="us-east-1" \ -e S3_BUCKET="${BUCKET_NAME}" \ -e S3_ACCESS_KEY_ID="any" \ -e S3_SECRET_ACCESS_KEY="any" \ -e S3_FORCE_PATH_STYLE="true" \ - -e BETTER_AUTH_SECRET="$(openssl rand-hex 32 2>/dev/null || openssl rand -hex 32)" \ + -e BETTER_AUTH_SECRET="$(openssl rand -hex 32)" \ -e BETTER_AUTH_URL="http://localhost:3000" \ -e BASE_URL="http://localhost:3000" \ -e NODE_ENV="production" \ @@ -126,19 +212,19 @@ docker run --rm \ p1ctos4ve-backend:latest \ bun run db:migrate -# Step 4: Run unit tests -echo -e "${YELLOW}๐Ÿงช Step 4: Running unit tests...${NC}" +# Step 10: Run unit tests +echo -e "${YELLOW}๐Ÿงช Step 10: Running unit tests...${NC}" docker run --rm \ --network "${NETWORK_NAME}" \ - -e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@postgres:5432/p1ctos4ve" \ - -e REDIS_URL="redis://redis:6379" \ - -e S3_ENDPOINT="http://seaweedfs-s3:8333" \ + -e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@p1ctos4ve-postgres:5432/p1ctos4ve" \ + -e REDIS_URL="redis://p1ctos4ve-redis:6379" \ + -e S3_ENDPOINT="http://p1ctos4ve-seaweedfs-s3:8333" \ -e S3_REGION="us-east-1" \ -e S3_BUCKET="${BUCKET_NAME}" \ -e S3_ACCESS_KEY_ID="any" \ -e S3_SECRET_ACCESS_KEY="any" \ -e S3_FORCE_PATH_STYLE="true" \ - -e BETTER_AUTH_SECRET="$(openssl rand-hex 32 2>/dev/null || openssl rand -hex 32)" \ + -e BETTER_AUTH_SECRET="$(openssl rand -hex 32)" \ -e BETTER_AUTH_URL="http://localhost:3000" \ -e BASE_URL="http://localhost:3000" \ -e NODE_ENV="test" \ @@ -155,23 +241,23 @@ else exit 1 fi -# Step 5: Run integration tests -echo -e "${YELLOW}๐Ÿ”— Step 5: Running integration tests...${NC}" +# Step 11: Run integration tests +echo -e "${YELLOW}๐Ÿ”— Step 11: Running integration tests...${NC}" echo -e "${YELLOW}Starting backend server for e2e tests...${NC}" BACKEND_CONTAINER=$(docker run -d \ --name p1ctos4ve-backend-test \ --network "${NETWORK_NAME}" \ -p 3000:3000 \ - -e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@postgres:5432/p1ctos4ve" \ - -e REDIS_URL="redis://redis:6379" \ - -e S3_ENDPOINT="http://seaweedfs-s3:8333" \ + -e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@p1ctos4ve-postgres:5432/p1ctos4ve" \ + -e REDIS_URL="redis://p1ctos4ve-redis:6379" \ + -e S3_ENDPOINT="http://p1ctos4ve-seaweedfs-s3:8333" \ -e S3_REGION="us-east-1" \ -e S3_BUCKET="${BUCKET_NAME}" \ -e S3_ACCESS_KEY_ID="any" \ -e S3_SECRET_ACCESS_KEY="any" \ -e S3_FORCE_PATH_STYLE="true" \ - -e BETTER_AUTH_SECRET="$(openssl rand-hex 32 2>/dev/null || openssl rand -hex 32)" \ + -e BETTER_AUTH_SECRET="$(openssl rand -hex 32)" \ -e BETTER_AUTH_URL="http://localhost:3000" \ -e BASE_URL="http://localhost:3000" \ -e NODE_ENV="test" \ @@ -189,19 +275,19 @@ for i in {1..30}; do done echo -e " ${GREEN}โœ“${NC}" -# Try e2e tests inside backend container +# Run e2e tests docker exec p1ctos4ve-backend-test sh -c "bun test --preload ./src/tests/setup.ts src/tests/e2e/" || \ docker run --rm \ --network "${NETWORK_NAME}" \ - -e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@postgres:5432/p1ctos4ve" \ - -e REDIS_URL="redis://redis:6379" \ - -e S3_ENDPOINT="http://seaweedfs-s3:8333" \ + -e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@p1ctos4ve-postgres:5432/p1ctos4ve" \ + -e REDIS_URL="redis://p1ctos4ve-redis:6379" \ + -e S3_ENDPOINT="http://p1ctos4ve-seaweedfs-s3:8333" \ -e S3_REGION="us-east-1" \ -e S3_BUCKET="${BUCKET_NAME}" \ -e S3_ACCESS_KEY_ID="any" \ -e S3_SECRET_ACCESS_KEY="any" \ -e S3_FORCE_PATH_STYLE="true" \ - -e BETTER_AUTH_SECRET="$(openssl rand-hex 32 2>/dev/null || openssl rand -hex 32)" \ + -e BETTER_AUTH_SECRET="$(openssl rand -hex 32)" \ -e BETTER_AUTH_URL="http://p1ctos4ve-backend-test:3000" \ -e BASE_URL="http://p1ctos4ve-backend-test:3000" \ -e NODE_ENV="test" \ @@ -222,23 +308,23 @@ else exit 1 fi -# Step 6: Start the application -echo -e "${YELLOW}๐Ÿš€ Step 6: Starting the application...${NC}" +# Step 12: Start the application +echo -e "${YELLOW}๐Ÿš€ Step 12: Starting the application...${NC}" echo -e "${GREEN}Application will be available at http://localhost:3000${NC}" echo -e "${YELLOW}Press Ctrl+C to stop${NC}" docker run --rm \ --network "${NETWORK_NAME}" \ -p 3000:3000 \ - -e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@postgres:5432/p1ctos4ve" \ - -e REDIS_URL="redis://redis:6379" \ - -e S3_ENDPOINT="http://seaweedfs-s3:8333" \ + -e DATABASE_URL="postgresql://p1ctos4ve:p1ctos4ve_password@p1ctos4ve-postgres:5432/p1ctos4ve" \ + -e REDIS_URL="redis://p1ctos4ve-redis:6379" \ + -e S3_ENDPOINT="http://p1ctos4ve-seaweedfs-s3:8333" \ -e S3_REGION="us-east-1" \ -e S3_BUCKET="${BUCKET_NAME}" \ -e S3_ACCESS_KEY_ID="any" \ -e S3_SECRET_ACCESS_KEY="any" \ -e S3_FORCE_PATH_STYLE="true" \ - -e BETTER_AUTH_SECRET="$(openssl rand-hex 32 2>/dev/null || openssl rand -hex 32)" \ + -e BETTER_AUTH_SECRET="$(openssl rand -hex 32)" \ -e BETTER_AUTH_URL="http://localhost:3000" \ -e BASE_URL="http://localhost:3000" \ -e NODE_ENV="production" \