()
| 83 | } |
| 84 | |
| 85 | async function main() { |
| 86 | const options = program.parse().opts() |
| 87 | |
| 88 | console.log(chalk.blue('🚀 Starting Sim...')) |
| 89 | |
| 90 | // Check if Docker is installed and running |
| 91 | const dockerRunning = await isDockerRunning() |
| 92 | if (!dockerRunning) { |
| 93 | console.error( |
| 94 | chalk.red('❌ Docker is not running or not installed. Please start Docker and try again.') |
| 95 | ) |
| 96 | process.exit(1) |
| 97 | } |
| 98 | |
| 99 | // Use port from options, with 3000 as default |
| 100 | const port = options.port |
| 101 | |
| 102 | // Pull latest images if not skipped |
| 103 | if (options.pull) { |
| 104 | await pullImage('ghcr.io/simstudioai/simstudio:latest') |
| 105 | await pullImage('ghcr.io/simstudioai/migrations:latest') |
| 106 | await pullImage('ghcr.io/simstudioai/realtime:latest') |
| 107 | await pullImage('pgvector/pgvector:pg17') |
| 108 | } |
| 109 | |
| 110 | // Ensure Docker network exists |
| 111 | if (!(await ensureNetworkExists())) { |
| 112 | console.error(chalk.red('❌ Failed to create Docker network')) |
| 113 | process.exit(1) |
| 114 | } |
| 115 | |
| 116 | // Clean up any existing containers |
| 117 | await cleanupExistingContainers() |
| 118 | |
| 119 | // Create data directory |
| 120 | const dataDir = join(homedir(), '.simstudio', 'data') |
| 121 | if (!existsSync(dataDir)) { |
| 122 | try { |
| 123 | mkdirSync(dataDir, { recursive: true }) |
| 124 | } catch (_error) { |
| 125 | console.error(chalk.red(`❌ Failed to create data directory: ${dataDir}`)) |
| 126 | process.exit(1) |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | // Start PostgreSQL container |
| 131 | console.log(chalk.blue('🔄 Starting PostgreSQL database...')) |
| 132 | const dbSuccess = await runCommand([ |
| 133 | 'docker', |
| 134 | 'run', |
| 135 | '-d', |
| 136 | '--name', |
| 137 | DB_CONTAINER, |
| 138 | '--network', |
| 139 | NETWORK_NAME, |
| 140 | '-e', |
| 141 | 'POSTGRES_USER=postgres', |
| 142 | '-e', |
no test coverage detected