fix: Удален docker-compose и добавлено развертывание в run.sh
This commit is contained in:
182
scripts/run.sh
182
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" \
|
||||
|
||||
Reference in New Issue
Block a user