Skip to content

Commit

Permalink
#8841 build service images multiplatform
Browse files Browse the repository at this point in the history
  • Loading branch information
1yuv committed Mar 7, 2024
1 parent 6bdf024 commit 5352e5f
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions scripts/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const setBuildInfo = () => {
};

const mkdirSync = (dirPath) => {
if (!fs.existsSync(dirPath)){
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath);
}
};
Expand Down Expand Up @@ -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) => {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -231,18 +252,18 @@ const buildImages = async () => {
};

const buildInfrastructureImages = async () => {
if (INTERNAL_CONTRIBUTOR){
if (INTERNAL_CONTRIBUTOR) {
await buildMultiPlatformImages();
} else {
await buildImages();
await buildSinglePlatformImages();
}
};

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 });
}
};
Expand All @@ -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();
};

Expand All @@ -283,9 +292,7 @@ module.exports = {
setDdocsVersion,
updateServiceWorker,
buildServiceImages,
buildImages,
buildInfrastructureImages,
saveServiceImages,
pushServiceImages,
publishServiceImages
};

0 comments on commit 5352e5f

Please sign in to comment.