()
| 297 | }; |
| 298 | |
| 299 | const buildDocker = async () => { |
| 300 | const { version } = await browserlessPackageJSON; |
| 301 | const finalDockerPath = path.join(compiledDir, 'Dockerfile'); |
| 302 | const argSwitches = getArgSwitches(); |
| 303 | |
| 304 | await build(); |
| 305 | |
| 306 | const dockerContents = ( |
| 307 | await fs.readFile(path.join(__dirname, '..', 'docker', 'sdk', 'Dockerfile')) |
| 308 | ).toString(); |
| 309 | |
| 310 | log(`Generating Dockerfile at "${finalDockerPath}"`); |
| 311 | |
| 312 | await fs.writeFile(finalDockerPath, dockerContents); |
| 313 | |
| 314 | const from = |
| 315 | argSwitches.from || |
| 316 | (await prompt( |
| 317 | 'Which docker image do you want to use (defaults to: ghcr.io/browserless/multi)?', |
| 318 | )) || |
| 319 | `ghcr.io/browserless/multi:v${version}`; |
| 320 | |
| 321 | const action = |
| 322 | argSwitches.action || |
| 323 | (await prompt( |
| 324 | 'Do you want to push the image or load it locally (defaults to load)?', |
| 325 | )) || |
| 326 | 'load'; |
| 327 | |
| 328 | const tag = |
| 329 | argSwitches.tag || |
| 330 | (await prompt( |
| 331 | 'What do you want to name the resulting image (eg, my-browserless:latest)?', |
| 332 | )); |
| 333 | |
| 334 | if (!tag || !tag.includes(':')) { |
| 335 | throw new Error(`A name for the image is required with a ":" and version.`); |
| 336 | } |
| 337 | |
| 338 | const platformsPrompt = |
| 339 | action === 'load' |
| 340 | ? `Which platform do you want to build for (defaults to linux/amd64)?` |
| 341 | : `Which platforms do you want to build? (defaults to "linux/amd64", must be comma-separated)?`; |
| 342 | |
| 343 | const platforms = |
| 344 | argSwitches.platform || (await prompt(platformsPrompt)) || 'linux/amd64'; |
| 345 | |
| 346 | if (action === 'load' && platforms.includes(',')) { |
| 347 | throw new Error( |
| 348 | `When "load" is specified, only one platform can be built due to limitations in buildx.`, |
| 349 | ); |
| 350 | } |
| 351 | |
| 352 | const cmd = `docker buildx build --build-arg FROM=${from} --platform ${platforms} --${action} -f ./build/Dockerfile -t ${tag} .`; |
| 353 | |
| 354 | const proceed = |
| 355 | argSwitches.proceed || |
| 356 | (await prompt(`Will execute "${cmd}" Proceed (y/n)?`)) || |
no test coverage detected