@@ -135,19 +135,87 @@ volumes:
135135 console . log ( chalk . green ( '✓ docker-compose.yml created' ) )
136136 }
137137
138- // Start Docker Compose
138+ // Check if Docker daemon is running
139+ try {
140+ console . log ( chalk . blue ( '🔍 Checking Docker daemon...' ) )
141+ execSync ( 'docker info' , { stdio : 'ignore' } )
142+ } catch ( error ) {
143+ console . error ( chalk . red ( '❌ Docker daemon is not running. Please start Docker Desktop or the Docker service.' ) )
144+ process . exit ( 1 )
145+ }
146+
147+ // Handle Docker network issues
139148 try {
140- // Check if the docker image exists locally, otherwise pull it
149+ console . log ( chalk . blue ( '🔍 Testing Docker networking...' ) )
150+ execSync ( 'docker network ls' , { stdio : 'ignore' } )
151+ } catch ( error ) {
152+ console . error ( chalk . red ( '❌ Docker networking issue detected. Please check your Docker installation.' ) )
153+ process . exit ( 1 )
154+ }
155+
156+ // Add permission check for Docker socket
157+ if ( process . platform === 'linux' ) {
141158 try {
142- console . log ( chalk . blue ( '🔍 Checking for Docker image...' ) )
143- execSync ( 'docker image inspect ghcr.io/simstudioai/sim:latest' , { stdio : 'ignore' } )
144- console . log ( chalk . green ( '✓ Found existing Docker image' ) )
159+ execSync ( 'ls -l /var/run/docker.sock' , { stdio : 'ignore' } )
145160 } catch ( error ) {
146- console . log ( chalk . blue ( '🚚 Pulling latest Docker image...' ) )
147- execSync ( 'docker pull ghcr.io/simstudioai/sim:latest' , { stdio : 'inherit' } )
148- console . log ( chalk . green ( '✓ Successfully pulled Docker image' ) )
161+ console . warn ( chalk . yellow ( '⚠️ Could not check Docker socket permissions. You might need to run with sudo.' ) )
149162 }
163+ }
164+
165+ // Add timeout handling for image pull
166+ try {
167+ console . log ( chalk . blue ( '🚚 Pulling latest Docker image...' ) )
168+ // Set a timeout and capture output
169+ const pullProcess = execSync ( 'docker pull ghcr.io/simstudioai/sim:latest' , {
170+ timeout : 180000 , // 3 minutes
171+ stdio : 'pipe'
172+ } )
173+ console . log ( chalk . green ( '✓ Successfully pulled Docker image' ) )
174+ } catch ( error : unknown ) {
175+ if ( error && typeof error === 'object' && 'code' in error && error . code === 'ETIMEDOUT' ) {
176+ console . error ( chalk . red ( '❌ Image pull timed out. Check your internet connection.' ) )
177+ } else {
178+ const errorMessage = error instanceof Error ? error . message : String ( error )
179+ console . error ( chalk . red ( '❌ Failed to pull Docker image:' ) , errorMessage )
180+ console . log ( chalk . yellow ( 'Attempting to use cached image if available...' ) )
181+ }
182+ }
150183
184+ // Handle database connectivity issues
185+ setTimeout ( ( ) => {
186+ try {
187+ execSync ( 'docker compose exec -T db pg_isready -U postgres' , { stdio : 'ignore' } )
188+ console . log ( chalk . green ( '✓ Database is ready' ) )
189+ } catch ( error ) {
190+ console . error ( chalk . red ( '❌ Could not connect to the database. Check the logs with:' ) )
191+ console . log ( chalk . yellow ( ' docker compose logs db' ) )
192+ }
193+ } , 10000 )
194+
195+ // Handle port conflicts
196+ try {
197+ console . log ( chalk . blue ( `🔍 Checking if port ${ answers . port } is available...` ) )
198+ execSync ( `lsof -i :${ answers . port } || true` , { stdio : 'pipe' } ) . toString ( )
199+ // If we get output, the port is in use
200+ console . warn ( chalk . yellow ( `⚠️ Port ${ answers . port } may already be in use. This could cause conflicts.` ) )
201+ } catch ( error ) {
202+ // Port is likely available, which is good
203+ }
204+
205+ // Add graceful shutdown handling
206+ process . on ( 'SIGINT' , ( ) => {
207+ console . log ( chalk . blue ( '\n👋 Shutting down Sim Studio...' ) )
208+ try {
209+ execSync ( 'docker compose down' , { stdio : 'inherit' } )
210+ console . log ( chalk . green ( '✓ Shutdown complete' ) )
211+ } catch ( error ) {
212+ console . error ( chalk . red ( '❌ Error during shutdown:' ) , error )
213+ }
214+ process . exit ( 0 )
215+ } )
216+
217+ // Start Docker Compose
218+ try {
151219 console . log ( chalk . blue ( '🚀 Starting Sim Studio with Docker Compose...' ) )
152220 execSync ( 'docker compose up -d' , { stdio : 'inherit' } )
153221
0 commit comments