diff --git a/scripts/build/index.js b/scripts/build/index.js index dbb212e94e2..79ee0e30e33 100644 --- a/scripts/build/index.js +++ b/scripts/build/index.js @@ -67,7 +67,7 @@ const setBuildInfo = () => { }; const mkdirSync = (dirPath) => { - if (!fs.existsSync(dirPath)){ + if (!fs.existsSync(dirPath)) { fs.mkdirSync(dirPath); } }; @@ -192,7 +192,7 @@ const setDdocsVersion = () => { }); }; -const exec = async (command, args, options=({})) => { +const exec = async (command, args, options = ({})) => { options.stdio = 'inherit'; const ci = spawn(command, args, options); await new Promise((resolve, reject) => { @@ -212,7 +212,9 @@ const npmCiModules = async () => { } }; -const buildServiceImages = async () => { + + +const buildSinglePlatformServiceImages = async () => { for (const service of versions.SERVICES) { console.log(`\n\nBuilding docker image for ${service}\n\n`); const tag = versions.getImageTag(service); @@ -222,7 +224,26 @@ const buildServiceImages = async () => { } }; -const buildImages = async () => { +const buildMultiPlatformServiceImages = async () => { + for (const service of versions.SERVICES) { + console.log(`\n\nBuilding multiplatform docker image for ${service}\n\n`); + const tag = versions.getImageTag(service); + await exec('npm', ['ci', '--omit=dev'], { cwd: service }); + await exec('npm', ['dedupe'], { cwd: service }); + await exec('docker', ['buildx', 'build', '--provenance=false', '--platform=' + BUILD_PLATFORMS.join(','), + '-f', `./${service}/Dockerfile`, '--tag', tag, '--push', '.']); + } +}; + +const buildServiceImages = async () => { + if (INTERNAL_CONTRIBUTOR) { + await buildMultiPlatformServiceImages(); + } else { + await buildSinglePlatformServiceImages(); + } +}; + +const buildSinglePlatformImages = async () => { for (const service of versions.INFRASTRUCTURE) { console.log(`\n\nBuilding docker image for ${service}\n\n`); const tag = versions.getImageTag(service); @@ -231,10 +252,10 @@ const buildImages = async () => { }; const buildInfrastructureImages = async () => { - if (INTERNAL_CONTRIBUTOR){ + if (INTERNAL_CONTRIBUTOR) { await buildMultiPlatformImages(); } else { - await buildImages(); + await buildSinglePlatformImages(); } }; @@ -242,7 +263,7 @@ const buildMultiPlatformImages = async () => { for (const service of versions.INFRASTRUCTURE) { console.log(`\n\nBuilding and pushing multiplatform docker image for ${service}\n\n`); const tag = versions.getImageTag(service); - await exec('docker', ['buildx', 'build', '--provenance=false', '--platform='+BUILD_PLATFORMS.join(','), + await exec('docker', ['buildx', 'build', '--provenance=false', '--platform=' + BUILD_PLATFORMS.join(','), '-f', `./Dockerfile`, '--tag', tag, '--push', '.'], { cwd: service }); } }; @@ -255,22 +276,10 @@ const saveServiceImages = async () => { } }; -const pushServiceImages = async () => { - for (const service of [...versions.SERVICES]) { - console.log(`\n\nPushing docker image for ${service}\n\n`); - const tag = versions.getImageTag(service); - await exec('docker', ['push', tag]); - } -}; - const publishServiceImages = async () => { if (!BUILD_NUMBER) { return; } - - if (INTERNAL_CONTRIBUTOR) { - return await pushServiceImages(); - } return await saveServiceImages(); }; @@ -283,9 +292,7 @@ module.exports = { setDdocsVersion, updateServiceWorker, buildServiceImages, - buildImages, buildInfrastructureImages, saveServiceImages, - pushServiceImages, publishServiceImages };