(options: StartOptions, passthrough: string[])
| 69 | } |
| 70 | |
| 71 | export const runStart = async (options: StartOptions, passthrough: string[]): Promise<number> => { |
| 72 | ensureNotRoot() |
| 73 | |
| 74 | const explicitPortFlag = process.argv.slice(2).some((arg) => arg === '--port' || arg.startsWith('--port=')) |
| 75 | const hasPort = typeof options.port === 'number' && Number.isFinite(options.port) |
| 76 | if (explicitPortFlag && !hasPort) { |
| 77 | throw new Error('Port must be a safe integer between 1 and 65535') |
| 78 | } |
| 79 | |
| 80 | if (hasPort) { |
| 81 | if (!Number.isSafeInteger(options.port) || options.port < 1 || options.port > 65535) { |
| 82 | throw new Error('Port must be a safe integer between 1 and 65535') |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | logStep('Preparing configuration') |
| 87 | ensureConfigBootstrap() |
| 88 | |
| 89 | const composeFiles = ['docker-compose.yml'] |
| 90 | |
| 91 | if (options.tor) { |
| 92 | ensureTorDataDir() |
| 93 | composeFiles.push('docker-compose.tor.yml') |
| 94 | } |
| 95 | |
| 96 | if (options.i2p) { |
| 97 | ensureI2PDataDir() |
| 98 | composeFiles.push('docker-compose.i2p.yml') |
| 99 | } |
| 100 | |
| 101 | if (options.nginx) { |
| 102 | await ensureNginxBootstrap() |
| 103 | composeFiles.push('docker-compose.nginx.yml') |
| 104 | } |
| 105 | |
| 106 | let overrideFile: string | undefined |
| 107 | if (hasPort) { |
| 108 | overrideFile = createPortOverrideComposeFile(options.port) |
| 109 | composeFiles.push(overrideFile) |
| 110 | } |
| 111 | |
| 112 | const env: NodeJS.ProcessEnv = {} |
| 113 | |
| 114 | if (options.debug) { |
| 115 | env.DEBUG = process.env.DEBUG || 'primary:*,worker:*,knex:*' |
| 116 | } |
| 117 | |
| 118 | const spinner = ora('Starting relay...').start() |
| 119 | const composePassthrough = passthrough.filter((arg) => arg !== '--') |
| 120 | const upArgs = ['up', '--build', '--remove-orphans', ...(options.detach ? ['-d'] : []), ...composePassthrough] |
| 121 | |
| 122 | try { |
| 123 | const code = await runDockerCompose({ |
| 124 | files: composeFiles, |
| 125 | args: upArgs, |
| 126 | env, |
| 127 | }) |
| 128 |
no test coverage detected