Makefile.docker 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # Makefile for SeaweedFS S3 IAM Integration Tests with Docker Compose
  2. .PHONY: help docker-build docker-up docker-down docker-logs docker-test docker-clean docker-status docker-keycloak-setup
  3. # Default target
  4. .DEFAULT_GOAL := help
  5. # Docker Compose configuration
  6. COMPOSE_FILE := docker-compose.yml
  7. PROJECT_NAME := seaweedfs-iam-test
  8. help: ## Show this help message
  9. @echo "SeaweedFS S3 IAM Integration Tests - Docker Compose"
  10. @echo ""
  11. @echo "Available commands:"
  12. @echo ""
  13. @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
  14. @echo ""
  15. @echo "Environment:"
  16. @echo " COMPOSE_FILE: $(COMPOSE_FILE)"
  17. @echo " PROJECT_NAME: $(PROJECT_NAME)"
  18. docker-build: ## Build local SeaweedFS image for testing
  19. @echo "🔨 Building local SeaweedFS image..."
  20. @echo "Creating build directory..."
  21. @cd ../../.. && mkdir -p .docker-build
  22. @echo "Building weed binary..."
  23. @cd ../../.. && cd weed && go build -o ../.docker-build/weed
  24. @echo "Copying required files to build directory..."
  25. @cd ../../.. && cp docker/filer.toml .docker-build/ && cp docker/entrypoint.sh .docker-build/
  26. @echo "Building Docker image..."
  27. @cd ../../.. && docker build -f docker/Dockerfile.local -t local/seaweedfs:latest .docker-build/
  28. @echo "Cleaning up build directory..."
  29. @cd ../../.. && rm -rf .docker-build
  30. @echo "✅ Built local/seaweedfs:latest"
  31. docker-up: ## Start all services with Docker Compose
  32. @echo "🚀 Starting SeaweedFS S3 IAM integration environment..."
  33. @docker-compose -p $(PROJECT_NAME) -f $(COMPOSE_FILE) up -d
  34. @echo ""
  35. @echo "✅ Environment started! Services will be available at:"
  36. @echo " 🔐 Keycloak: http://localhost:8080 (admin/admin)"
  37. @echo " 🗄️ S3 API: http://localhost:8333"
  38. @echo " 📁 Filer: http://localhost:8888"
  39. @echo " 🎯 Master: http://localhost:9333"
  40. @echo ""
  41. @echo "⏳ Waiting for all services to be healthy..."
  42. @docker-compose -p $(PROJECT_NAME) -f $(COMPOSE_FILE) ps
  43. docker-down: ## Stop and remove all containers
  44. @echo "🛑 Stopping SeaweedFS S3 IAM integration environment..."
  45. @docker-compose -p $(PROJECT_NAME) -f $(COMPOSE_FILE) down -v
  46. @echo "✅ Environment stopped and cleaned up"
  47. docker-restart: docker-down docker-up ## Restart the entire environment
  48. docker-logs: ## Show logs from all services
  49. @docker-compose -p $(PROJECT_NAME) -f $(COMPOSE_FILE) logs -f
  50. docker-logs-s3: ## Show logs from S3 service only
  51. @docker-compose -p $(PROJECT_NAME) -f $(COMPOSE_FILE) logs -f weed-s3
  52. docker-logs-keycloak: ## Show logs from Keycloak service only
  53. @docker-compose -p $(PROJECT_NAME) -f $(COMPOSE_FILE) logs -f keycloak
  54. docker-status: ## Check status of all services
  55. @echo "📊 Service Status:"
  56. @docker-compose -p $(PROJECT_NAME) -f $(COMPOSE_FILE) ps
  57. @echo ""
  58. @echo "🏥 Health Checks:"
  59. @docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep $(PROJECT_NAME) || true
  60. docker-test: docker-wait-healthy ## Run integration tests against Docker environment
  61. @echo "🧪 Running SeaweedFS S3 IAM integration tests..."
  62. @echo ""
  63. @KEYCLOAK_URL=http://localhost:8080 go test -v -timeout 10m ./...
  64. docker-test-single: ## Run a single test (use TEST_NAME=TestName)
  65. @if [ -z "$(TEST_NAME)" ]; then \
  66. echo "❌ Please specify TEST_NAME, e.g., make docker-test-single TEST_NAME=TestKeycloakAuthentication"; \
  67. exit 1; \
  68. fi
  69. @echo "🧪 Running single test: $(TEST_NAME)"
  70. @KEYCLOAK_URL=http://localhost:8080 go test -v -run "$(TEST_NAME)" -timeout 5m ./...
  71. docker-keycloak-setup: ## Manually run Keycloak setup (usually automatic)
  72. @echo "🔧 Running Keycloak setup manually..."
  73. @docker-compose -p $(PROJECT_NAME) -f $(COMPOSE_FILE) run --rm keycloak-setup
  74. docker-clean: ## Clean up everything (containers, volumes, images)
  75. @echo "🧹 Cleaning up Docker environment..."
  76. @docker-compose -p $(PROJECT_NAME) -f $(COMPOSE_FILE) down -v --remove-orphans
  77. @docker system prune -f
  78. @echo "✅ Cleanup complete"
  79. docker-shell-s3: ## Get shell access to S3 container
  80. @docker-compose -p $(PROJECT_NAME) -f $(COMPOSE_FILE) exec weed-s3 sh
  81. docker-shell-keycloak: ## Get shell access to Keycloak container
  82. @docker-compose -p $(PROJECT_NAME) -f $(COMPOSE_FILE) exec keycloak bash
  83. docker-debug: ## Show debug information
  84. @echo "🔍 Docker Environment Debug Information"
  85. @echo ""
  86. @echo "📋 Docker Compose Config:"
  87. @docker-compose -p $(PROJECT_NAME) -f $(COMPOSE_FILE) config
  88. @echo ""
  89. @echo "📊 Container Status:"
  90. @docker-compose -p $(PROJECT_NAME) -f $(COMPOSE_FILE) ps
  91. @echo ""
  92. @echo "🌐 Network Information:"
  93. @docker network ls | grep $(PROJECT_NAME) || echo "No networks found"
  94. @echo ""
  95. @echo "💾 Volume Information:"
  96. @docker volume ls | grep $(PROJECT_NAME) || echo "No volumes found"
  97. # Quick test targets
  98. docker-test-auth: ## Quick test of authentication only
  99. @KEYCLOAK_URL=http://localhost:8080 go test -v -run "TestKeycloakAuthentication" -timeout 2m ./...
  100. docker-test-roles: ## Quick test of role mapping only
  101. @KEYCLOAK_URL=http://localhost:8080 go test -v -run "TestKeycloakRoleMapping" -timeout 2m ./...
  102. docker-test-s3ops: ## Quick test of S3 operations only
  103. @KEYCLOAK_URL=http://localhost:8080 go test -v -run "TestKeycloakS3Operations" -timeout 2m ./...
  104. # Development workflow
  105. docker-dev: docker-down docker-up docker-test ## Complete dev workflow: down -> up -> test
  106. # Show service URLs for easy access
  107. docker-urls: ## Display all service URLs
  108. @echo "🌐 Service URLs:"
  109. @echo ""
  110. @echo " 🔐 Keycloak Admin: http://localhost:8080 (admin/admin)"
  111. @echo " 🔐 Keycloak Realm: http://localhost:8080/realms/seaweedfs-test"
  112. @echo " 📁 S3 API: http://localhost:8333"
  113. @echo " 📂 Filer UI: http://localhost:8888"
  114. @echo " 🎯 Master UI: http://localhost:9333"
  115. @echo " 💾 Volume Server: http://localhost:8080"
  116. @echo ""
  117. @echo " 📖 Test Users:"
  118. @echo " • admin-user (password: adminuser123) - s3-admin role"
  119. @echo " • read-user (password: readuser123) - s3-read-only role"
  120. @echo " • write-user (password: writeuser123) - s3-read-write role"
  121. @echo " • write-only-user (password: writeonlyuser123) - s3-write-only role"
  122. # Wait targets for CI/CD
  123. docker-wait-healthy: ## Wait for all services to be healthy
  124. @echo "⏳ Waiting for all services to be healthy..."
  125. @timeout 300 bash -c ' \
  126. required_services="keycloak weed-master weed-volume weed-filer weed-s3"; \
  127. while true; do \
  128. all_healthy=true; \
  129. for service in $$required_services; do \
  130. if ! docker-compose -p $(PROJECT_NAME) -f $(COMPOSE_FILE) ps $$service | grep -q "healthy"; then \
  131. echo "Waiting for $$service to be healthy..."; \
  132. all_healthy=false; \
  133. break; \
  134. fi; \
  135. done; \
  136. if [ "$$all_healthy" = "true" ]; then \
  137. break; \
  138. fi; \
  139. sleep 5; \
  140. done \
  141. '
  142. @echo "✅ All required services are healthy"