Skip to content
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

feat: allow to select sdk with .sdk_name #27

Merged
merged 2 commits into from
May 15, 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
5 changes: 5 additions & 0 deletions .changeset/early-moles-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": patch
---

feat: allow to select sdk with .sdk_name label
28 changes: 15 additions & 13 deletions apps/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
env: string[];
ramSize: string;
sdkVersion: string;
sdkName: string;
workdir: string;
};

Expand All @@ -28,7 +29,8 @@
const CARTESI_DEFAULT_RAM_SIZE = "128Mi";

const CARTESI_LABEL_SDK_VERSION = `${CARTESI_LABEL_PREFIX}.sdk_version`;
const CARTESI_DEFAULT_SDK_VERSION = "0.6.0";
const CARTESI_LABEL_SDK_NAME = `${CARTESI_LABEL_PREFIX}.sdk_name`;
const CARTESI_DEFAULT_SDK_VERSION = "0.6.2";

export default class BuildApplication extends BaseCommand<
typeof BuildApplication
Expand Down Expand Up @@ -99,6 +101,7 @@
entrypoint: imageInfo["Config"]["Entrypoint"] ?? [],
env: imageInfo["Config"]["Env"] || [],
ramSize: labels[CARTESI_LABEL_RAM_SIZE] ?? CARTESI_DEFAULT_RAM_SIZE,
sdkName: labels[CARTESI_LABEL_SDK_NAME] ?? "cartesi/sdk",
sdkVersion:
labels[CARTESI_LABEL_SDK_VERSION] ??
CARTESI_DEFAULT_SDK_VERSION,
Expand All @@ -112,7 +115,10 @@
// fail if using unsupported sdk version
if (!semver.valid(info.sdkVersion)) {
this.warn("sdk version is not a valid semver");
} else if (semver.lt(info.sdkVersion, CARTESI_DEFAULT_SDK_VERSION)) {
} else if (
info.sdkName == "cartesi/sdk" &&
semver.lt(info.sdkVersion, CARTESI_DEFAULT_SDK_VERSION)
) {
throw new Error(`Unsupported sdk version: ${info.sdkVersion} (used) < ${CARTESI_DEFAULT_SDK_VERSION} (minimum).
Update your application Dockerfile using one of the templates at https://github.com/cartesi/application-templates/tree/${DEFAULT_TEMPLATES_BRANCH}
`);
Expand Down Expand Up @@ -147,7 +153,7 @@
outputFilePath: string,
): Promise<void> {
// create docker tarball from app image
const { stdout: appCid } = await execa("docker", [

Check warning on line 156 in apps/cli/src/commands/build.ts

View workflow job for this annotation

GitHub Actions / lint

'appCid' is assigned a value but never used
"image",
"save",
image,
Expand Down Expand Up @@ -232,26 +238,22 @@
const driveLabel = "root"; // XXX: does this need to be customizable?

// list of environment variables of docker image
const envs = info.env.map(
(variable) => `--append-entrypoint=export ${variable}`,
);
const envs = info.env.map((variable) => `--env=${variable}`);

// ENTRYPOINT and CMD as a space separated string
const entrypoint = [...info.entrypoint, ...info.cmd].join(" ");

// command to change working directory if WORKDIR is defined
const cwd = info.workdir ? `--append-init=WORKDIR=${info.workdir}` : "";
const cwd = info.workdir ? `--workdir=${info.workdir}` : "";
return [
"cartesi-machine",
"--assert-rolling-template",
"create_machine_snapshot",
`--ram-length=${ramSize}`,
`--flash-drive=label:${driveLabel},filename:/tmp/input`,
"--final-hash",
`--store=/tmp/output`,
"--append-bootargs=no4lvl",
`--drive-label=${driveLabel}`,
`--drive-filename=/tmp/input`,
`--output=/tmp/output`,
cwd,
...envs,
`--append-entrypoint=${entrypoint}`,
`--entrypoint=${entrypoint}`,
];
}

Expand Down
Loading