Skip to content

Commit

Permalink
[docker] publish different build profiles (#5748)
Browse files Browse the repository at this point in the history
  • Loading branch information
rustielin authored Dec 1, 2022
1 parent b3e9614 commit 21660ed
Showing 1 changed file with 45 additions and 20 deletions.
65 changes: 45 additions & 20 deletions docker/release-images.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// 2. docker login - with authorization to push to the `aptoslabs` org
// 3. gcloud auth configure-docker us-west1-docker.pkg.dev
// 4. gcloud auth login --update-adc
// 5. aws-mfa
// 5. AWS CLI credentials configured
//
// Once you have all prerequisites fulfilled, you can run this script via:
// GIT_SHA=${{ github.sha }} GCP_DOCKER_ARTIFACT_REPO="${{ secrets.GCP_DOCKER_ARTIFACT_REPO }}" AWS_ACCOUNT_ID="${{ secrets.AWS_ECR_ACCOUNT_NUM }}" IMAGE_TAG_PREFIX="${{ inputs.image_tag_prefix }}" ./docker/release_images.sh --wait-for-image-seconds=1800
Expand All @@ -33,10 +33,30 @@ const Features = {
};

const IMAGES_TO_RELEASE = {
validator: [Features.Default, Features.Indexer],
forge: [Features.Default],
tools: [Features.Default],
"node-checker": [Features.Default],
validator: {
performance: [
Features.Default,
],
release: [
Features.Default,
Features.Indexer,
],
},
forge: {
release: [
Features.Default,
],
},
tools: {
release: [
Features.Default,
],
},
"node-checker": {
release: [
Features.Default,
],
}
};

import { execSync } from "node:child_process";
Expand Down Expand Up @@ -102,20 +122,25 @@ const TARGET_REGISTRIES = [
// default 10 seconds
parsedArgs.WAIT_FOR_IMAGE_SECONDS = parseInt(parsedArgs.WAIT_FOR_IMAGE_SECONDS ?? 10, 10);

for (const [image, features] of Object.entries(IMAGES_TO_RELEASE)) {
for (const feature of features) {
const featureSuffix = feature === Features.Default ? "" : feature;

for (const targetRegistry of TARGET_REGISTRIES) {
const imageSource = `${parsedArgs.GCP_DOCKER_ARTIFACT_REPO}/${image}:${joinTagSegments(
featureSuffix,
parsedArgs.GIT_SHA,
)}`;
const imageTarget = `${targetRegistry}/${image}:${joinTagSegments(parsedArgs.IMAGE_TAG_PREFIX, featureSuffix)}`;
console.info(chalk.green(`INFO: copying ${imageSource} to ${imageTarget}`));
await waitForImageToBecomeAvailable(imageSource, parsedArgs.WAIT_FOR_IMAGE_SECONDS);
await $`${crane} copy ${imageSource} ${imageTarget}`;
await $`${crane} copy ${imageSource} ${joinTagSegments(imageTarget, parsedArgs.GIT_SHA)}`;
for (const [image, imageConfig] of Object.entries(IMAGES_TO_RELEASE)) {
for (const [profile, features] of Object.entries(imageConfig)) {
// build profiles that are not the default "release" will have a separate prefix
const profilePrefix = profile === "release" ? "" : profile;
for (const feature of features) {
const featureSuffix = feature === Features.Default ? "" : feature;

for (const targetRegistry of TARGET_REGISTRIES) {
const imageSource = `${parsedArgs.GCP_DOCKER_ARTIFACT_REPO}/${image}:${joinTagSegments(
profilePrefix,
featureSuffix,
parsedArgs.GIT_SHA,
)}`;
const imageTarget = `${targetRegistry}/${image}:${joinTagSegments(parsedArgs.IMAGE_TAG_PREFIX, profilePrefix, featureSuffix)}`;
console.info(chalk.green(`INFO: copying ${imageSource} to ${imageTarget}`));
await waitForImageToBecomeAvailable(imageSource, parsedArgs.WAIT_FOR_IMAGE_SECONDS);
await $`${crane} copy ${imageSource} ${imageTarget}`;
await $`${crane} copy ${imageSource} ${joinTagSegments(imageTarget, parsedArgs.GIT_SHA)}`;
}
}
}
}
Expand All @@ -141,7 +166,7 @@ async function waitForImageToBecomeAvailable(imageToWaitFor, waitForImageSeconds
console.log(
chalk.yellow(
// prettier-ignore
`WARN: Image ${imageToWaitFor} not available yet - waiting ${ WAIT_TIME_IN_BETWEEN_ATTEMPTS / 1000 } seconds to try again. Time elapsed: ${timeElapsedSeconds().toFixed( 0, )} seconds. Max wait time: ${waitForImageSeconds} seconds`,
`WARN: Image ${imageToWaitFor} not available yet - waiting ${WAIT_TIME_IN_BETWEEN_ATTEMPTS / 1000} seconds to try again. Time elapsed: ${timeElapsedSeconds().toFixed(0,)} seconds. Max wait time: ${waitForImageSeconds} seconds`,
),
);
await sleep(WAIT_TIME_IN_BETWEEN_ATTEMPTS);
Expand Down

0 comments on commit 21660ed

Please sign in to comment.