diff --git a/code/utils/deploy-pokedex.js b/code/utils/deploy-pokedex.js index 571dd3f..2e3872c 100644 --- a/code/utils/deploy-pokedex.js +++ b/code/utils/deploy-pokedex.js @@ -206,52 +206,67 @@ async function healthCheck(host, port, retries = 5) { async function deployLocal(config) { const { execSync } = await import('child_process'); console.log('\n🐳 Deploying to local Docker...'); - + // Create modified docker-compose - const modifiedCompose = createModifiedDockerCompose(config.port, config.sslPort, config.backendPort); + const modifiedCompose = createModifiedDockerCompose( + config.port, + config.sslPort, + config.backendPort + ); const tmpComposePath = path.join(SOURCE_DIR, 'docker-compose.tmp.yml'); fs.writeFileSync(tmpComposePath, modifiedCompose); - + try { - // Stop existing - console.log(' šŸ›‘ Stopping existing containers...'); + // Stop existing + console.log(' šŸ›‘ Stopping existing containers...'); + try { + execSync(`docker compose -f "${tmpComposePath}" down --remove-orphans`, { + cwd: SOURCE_DIR, + stdio: 'inherit' + }); + } catch (e) { + // Ignore if file doesn't exist yet or other issues on down try { - execSync(`docker compose -f "${tmpComposePath}" down --remove-orphans`, { cwd: SOURCE_DIR, stdio: 'inherit' }); - } catch (e) { - // Ignore if file doesn't exist yet or other issues on down - try { - execSync(`docker compose -f docker-compose.production.yml down --remove-orphans`, { cwd: SOURCE_DIR, stdio: 'inherit' }); - } catch (e2) { /* ignore */ } + execSync( + `docker compose -f docker-compose.production.yml down --remove-orphans`, + { cwd: SOURCE_DIR, stdio: 'inherit' } + ); + } catch (e2) { + /* ignore */ } + } - // Up - console.log(' šŸš€ Starting containers...'); - execSync(`docker compose -f "${tmpComposePath}" up -d --build`, { cwd: SOURCE_DIR, stdio: 'inherit' }); - - // Health Check - console.log('\nšŸ„ Performing health checks...'); - console.log(' Checking frontend...'); - const frontendHealthy = await healthCheck('localhost', config.port); - if (!frontendHealthy) throw new Error('Frontend health check failed'); - console.log(' āœ… Frontend healthy'); + // Up + console.log(' šŸš€ Starting containers...'); + execSync(`docker compose -f "${tmpComposePath}" up -d --build`, { + cwd: SOURCE_DIR, + stdio: 'inherit' + }); - console.log(' Checking backend...'); - const backendHealthy = await healthCheck('localhost', config.backendPort); - // Backend might need more time - if (!backendHealthy) throw new Error('Backend health check failed'); - console.log(' āœ… Backend healthy'); + // Health Check + console.log('\nšŸ„ Performing health checks...'); + console.log(' Checking frontend...'); + const frontendHealthy = await healthCheck('localhost', config.port); + if (!frontendHealthy) throw new Error('Frontend health check failed'); + console.log(' āœ… Frontend healthy'); - console.log(`\nšŸŽ‰ Local Deployment successful!`); - console.log(`🌐 Frontend: http://localhost:${config.port}`); - if (config.sslPort) console.log(`šŸ”’ HTTPS: https://localhost:${config.sslPort}`); - console.log(`šŸ”Œ Backend: http://localhost:${config.backendPort}`); + console.log(' Checking backend...'); + const backendHealthy = await healthCheck('localhost', config.backendPort); + // Backend might need more time + if (!backendHealthy) throw new Error('Backend health check failed'); + console.log(' āœ… Backend healthy'); + console.log(`\nšŸŽ‰ Local Deployment successful!`); + console.log(`🌐 Frontend: http://localhost:${config.port}`); + if (config.sslPort) + console.log(`šŸ”’ HTTPS: https://localhost:${config.sslPort}`); + console.log(`šŸ”Œ Backend: http://localhost:${config.backendPort}`); } catch (e) { - console.error('āŒ Local deployment failed:', e.message); - // Clean up tmp file? Maybe keep for debugging if failed - throw e; + console.error('āŒ Local deployment failed:', e.message); + // Clean up tmp file? Maybe keep for debugging if failed + throw e; } finally { - console.log(`\nā„¹ļø Docker Compose file: ${tmpComposePath}`); + console.log(`\nā„¹ļø Docker Compose file: ${tmpComposePath}`); } }