Skip to content

Adding --latest-local to the baas test server CLI #6673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions integration-tests/baas-test-server/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ yargs(hideBin(process.argv))
.command(
["docker [githash]"],
"Runs the BaaS test image using Docker",
(yargs) => yargs.positional("githash", { type: "string" }).option("branch", { default: "master" }),
(yargs) =>
yargs
.positional("githash", { type: "string" })
.option("branch", { default: "master" })
.option("latest-local", { default: false, boolean: true }),
wrapCommand(async (argv) => {
const { AWS_PROFILE, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY } = process.env;
assert(AWS_ACCESS_KEY_ID && AWS_SECRET_ACCESS_KEY, "Missing AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY env");
Expand All @@ -95,12 +99,19 @@ yargs(hideBin(process.argv))
docker.ensureNoBaas();

if (argv.githash) {
docker.spawnBaaS({ tag: argv.githash, accessKeyId: AWS_ACCESS_KEY_ID, secretAccessKey: AWS_SECRET_ACCESS_KEY });
docker.spawnBaaS({
image: argv.githash,
accessKeyId: AWS_ACCESS_KEY_ID,
secretAccessKey: AWS_SECRET_ACCESS_KEY,
});
} else if (argv["latest-local"]) {
const id = docker.getLatestLocalId();
docker.spawnBaaS({ image: id, accessKeyId: AWS_ACCESS_KEY_ID, secretAccessKey: AWS_SECRET_ACCESS_KEY });
} else {
const tag = await docker.fetchBaasTag(argv.branch);
assert(AWS_PROFILE, "Missing AWS_PROFILE env");
docker.pullBaas({ profile: AWS_PROFILE, tag });
docker.spawnBaaS({ tag, accessKeyId: AWS_ACCESS_KEY_ID, secretAccessKey: AWS_SECRET_ACCESS_KEY });
docker.spawnBaaS({ image: tag, accessKeyId: AWS_ACCESS_KEY_ID, secretAccessKey: AWS_SECRET_ACCESS_KEY });
}
}),
)
Expand Down
22 changes: 18 additions & 4 deletions integration-tests/baas-test-server/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const BAAS_CONTAINER_NAME = "baas-test-server";
const BAAS_PORT = 9090;
const BAAS_VARIANT = process.arch === "arm64" ? "ubuntu2004-arm64" : "ubuntu2004-docker";
const ECR_HOSTNAME = "969505754201.dkr.ecr.us-east-1.amazonaws.com";
const ECR_PATHNAME = "/baas-test-images/test_server-race";

function registerExitListeners(logPrefix: string, child: cp.ChildProcess) {
function killChild() {
Expand Down Expand Up @@ -88,6 +89,19 @@ export async function fetchBaasTag(branch: string) {
}
}

export function getLatestLocalId() {
const imagesOutput = execSync("docker images --format json", { encoding: "utf8" });
for (const line of imagesOutput.split("\n")) {
if (line) {
const image = JSON.parse(line.trim());
if (image.Repository === ECR_HOSTNAME + ECR_PATHNAME && image.Tag.startsWith(BAAS_VARIANT)) {
return image.ID;
}
}
}
throw new Error("Unable to infer the latest local tag");
}

export function pullBaas({ profile, tag }: { profile: string; tag: string }) {
try {
execSync(`docker pull ${tag}`, { stdio: "inherit" });
Expand All @@ -103,15 +117,15 @@ export function pullBaas({ profile, tag }: { profile: string; tag: string }) {
}

export function spawnBaaS({
tag,
image,
accessKeyId,
secretAccessKey,
}: {
tag: string;
image: string;
accessKeyId: string;
secretAccessKey: string;
}) {
console.log("Starting server from tag", chalk.dim(tag));
console.log("Starting server from tag", chalk.dim(image));
spawn(chalk.blueBright("baas"), "docker", [
"run",
"--name",
Expand All @@ -124,6 +138,6 @@ export function spawnBaaS({
`AWS_SECRET_ACCESS_KEY=${secretAccessKey}`,
"--publish",
`${BAAS_PORT}:${BAAS_PORT}`,
tag,
image,
]);
}
Loading