-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocker-setup.sh
More file actions
executable file
Β·197 lines (161 loc) Β· 6 KB
/
docker-setup.sh
File metadata and controls
executable file
Β·197 lines (161 loc) Β· 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
# ReBin Pro Docker Setup Script
# This script sets up the development environment with Docker following security best practices
set -e # Exit on any error
echo "π³ Setting up ReBin Pro with Docker..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check Docker installation and security
check_docker() {
print_status "Checking Docker installation and security..."
if ! command -v docker &> /dev/null; then
print_error "Docker is not installed. Please install Docker from https://docs.docker.com/get-docker/"
exit 1
fi
if ! command -v docker-compose &> /dev/null; then
print_error "Docker Compose is not installed. Please install Docker Compose."
exit 1
fi
# Check if Docker daemon is running
if ! docker info &> /dev/null; then
print_error "Docker daemon is not running. Please start Docker."
exit 1
fi
# Check Docker version (minimum 20.10.0 for security features)
DOCKER_VERSION=$(docker --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
REQUIRED_VERSION="20.10.0"
if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$DOCKER_VERSION" | sort -V | head -n1)" != "$REQUIRED_VERSION" ]; then
print_warning "Docker version $DOCKER_VERSION detected. Version $REQUIRED_VERSION or higher is recommended for security features."
fi
print_success "Docker is properly installed and running"
}
# Validate environment files
validate_environment() {
print_status "Validating environment configuration..."
if [ ! -f ".env" ]; then
print_warning ".env file not found. Creating from template..."
cp env.example .env
print_warning "Please update .env with your actual API keys before running in production"
fi
# Check for required environment variables
required_vars=("SUPABASE_URL" "SUPABASE_ANON_KEY" "SUPABASE_SERVICE_ROLE_KEY" "OPENROUTER_API_KEY" "ELEVENLABS_API_KEY")
for var in "${required_vars[@]}"; do
if ! grep -q "^${var}=" .env || grep -q "^${var}=your_" .env; then
print_warning "Please set ${var} in your .env file"
fi
done
print_success "Environment validation completed"
}
# Security scan of Docker images
security_scan() {
print_status "Performing security scan of Docker images..."
# Check if trivy is available for security scanning
if command -v trivy &> /dev/null; then
print_status "Running Trivy security scan..."
docker-compose build --no-cache
trivy image --exit-code 1 --severity HIGH,CRITICAL $(docker-compose config | grep 'image:' | awk '{print $2}' | head -1) || print_warning "Security scan found issues. Please review."
else
print_warning "Trivy not installed. Skipping security scan. Install with: brew install trivy"
fi
}
# Build and start services with security measures
start_services() {
print_status "Building and starting services with security measures..."
# Stop any existing containers
docker-compose down --remove-orphans
# Build images with no cache for security
print_status "Building Docker images..."
docker-compose build --no-cache --parallel
# Start services
print_status "Starting services..."
docker-compose up -d
# Wait for services to be healthy
print_status "Waiting for services to be healthy..."
sleep 30
# Check service health
if docker-compose ps | grep -q "unhealthy"; then
print_error "Some services are unhealthy. Check logs with: docker-compose logs"
docker-compose ps
exit 1
fi
print_success "Services started successfully!"
}
# Show service information
show_service_info() {
print_status "Service Information:"
echo ""
echo "π Frontend: http://localhost:5173"
echo "π§ Backend API: http://localhost:8000"
echo "π Backend Docs: http://localhost:8000/docs"
echo "π€ CV Service: http://localhost:9000"
echo ""
echo "π Service Status:"
docker-compose ps
echo ""
echo "π View logs: docker-compose logs -f"
echo "π Stop services: docker-compose down"
echo "π Restart service: docker-compose restart <service-name>"
}
# Cleanup function
cleanup() {
print_status "Cleaning up..."
docker-compose down --remove-orphans
docker system prune -f
print_success "Cleanup completed"
}
# Main setup function
main() {
echo "π― ReBin Pro - Secure Docker Setup"
echo "=================================="
check_docker
validate_environment
security_scan
start_services
show_service_info
echo ""
print_success "Setup completed successfully! π"
echo ""
echo "π Security Features Enabled:"
echo " β
Non-root users in all containers"
echo " β
Multi-stage builds for smaller attack surface"
echo " β
Network isolation with custom subnet"
echo " β
Resource limits to prevent DoS attacks"
echo " β
Health checks for all services"
echo " β
Log rotation and monitoring"
echo " β
Security headers in nginx"
echo ""
echo "π Available Commands:"
echo " docker-compose up -d - Start all services"
echo " docker-compose down - Stop all services"
echo " docker-compose logs -f - View logs"
echo " docker-compose ps - Check service status"
echo " docker-compose restart <svc> - Restart specific service"
echo " ./docker-setup.sh cleanup - Clean up containers and images"
echo ""
echo "π For production deployment:"
echo " ./deploy.sh"
}
# Handle cleanup command
if [ "$1" = "cleanup" ]; then
cleanup
exit 0
fi
# Run main function
main "$@"