Skip to content
Merged
5 changes: 5 additions & 0 deletions .changeset/eighty-squids-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": patch
---

support buildArgs in docker builder
5 changes: 5 additions & 0 deletions .changeset/good-colts-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": patch
---

remove unused image argument from shell command
5 changes: 5 additions & 0 deletions .changeset/odd-coins-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": patch
---

change from —append-entrypoint to command
5 changes: 5 additions & 0 deletions .changeset/old-knives-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": patch
---

add hidden debug flag to not remove intermediate build files
5 changes: 5 additions & 0 deletions .changeset/shaky-plants-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": patch
---

add missing "until" usage at logs command
5 changes: 5 additions & 0 deletions .changeset/ten-beers-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": patch
---

fix amount display in erc20 deposit
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
2 changes: 1 addition & 1 deletion apps/cli/biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"$schema": "https://biomejs.dev/schemas/2.1.2/schema.json",
"extends": ["../../biome.json"],
"linter": {
"rules": {
Expand Down
5 changes: 4 additions & 1 deletion apps/cli/src/builder/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const build = async (
drive: DirectoryDriveConfig,
sdkImage: string,
destination: string,
debug: boolean,
): Promise<undefined> => {
const filename = `${name}.${drive.format}`;

Expand Down Expand Up @@ -40,6 +41,8 @@ export const build = async (
}
} finally {
// delete copied
await fs.remove(dest);
if (!debug) {
await fs.remove(dest);
}
}
};
16 changes: 11 additions & 5 deletions apps/cli/src/builder/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { crane, genext2fs, mksquashfs } from "../exec/index.js";

type ImageBuildOptions = Pick<
DockerDriveConfig,
"context" | "dockerfile" | "tags" | "target"
"buildArgs" | "context" | "dockerfile" | "tags" | "target"
>;

type ImageInfo = {
Expand All @@ -21,7 +21,7 @@ type ImageInfo = {
* Build Docker image (linux/riscv64). Returns image id.
*/
const buildImage = async (options: ImageBuildOptions): Promise<string> => {
const { context, dockerfile, tags, target } = options;
const { buildArgs, context, dockerfile, tags, target } = options;
const buildResult = tmp.tmpNameSync();
const args = [
"buildx",
Expand All @@ -39,6 +39,9 @@ const buildImage = async (options: ImageBuildOptions): Promise<string> => {
// set tags for the image built
args.push(...tags.flatMap((tag) => ["--tag", tag]));

// set build args
args.push(...buildArgs.flatMap((arg) => ["--build-arg", arg]));

if (target) {
args.push("--target", target);
}
Expand Down Expand Up @@ -83,6 +86,7 @@ export const build = async (
drive: DockerDriveConfig,
sdkImage: string,
destination: string,
debug: boolean,
): Promise<ImageInfo | undefined> => {
const { format } = drive;

Expand All @@ -97,7 +101,7 @@ export const build = async (
image = drive.image;
try {
imageInfo = await getImageInfo(image);
} catch (error) {
} catch {
await execa("docker", ["image", "pull", image]);
imageInfo = await getImageInfo(image);
}
Expand Down Expand Up @@ -142,8 +146,10 @@ export const build = async (
}
} finally {
// delete intermediate files
await fs.remove(path.join(destination, ocitar));
await fs.remove(path.join(destination, tar));
if (!debug) {
await fs.remove(path.join(destination, ocitar));
await fs.remove(path.join(destination, tar));
}
}

return imageInfo;
Expand Down
19 changes: 14 additions & 5 deletions apps/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Command } from "@commander-js/extra-typings";
import { Command, Option } from "@commander-js/extra-typings";
import fs from "fs-extra";
import path from "node:path";
import tmp from "tmp";
Expand All @@ -18,13 +18,14 @@ const buildDrive = async (
drive: DriveConfig,
sdkImage: string,
destination: string,
debug: boolean,
): Promise<DriveResult> => {
switch (drive.builder) {
case "directory": {
return buildDirectory(name, drive, sdkImage, destination);
return buildDirectory(name, drive, sdkImage, destination, debug);
}
case "docker": {
return buildDocker(name, drive, sdkImage, destination);
return buildDocker(name, drive, sdkImage, destination, debug);
}
case "empty": {
return buildEmpty(name, drive, sdkImage, destination);
Expand All @@ -48,8 +49,16 @@ export const createBuildCommand = () => {
"path to the configuration file",
"cartesi.toml",
)
.addOption(
new Option(
"--debug",
"enable debug mode (do not remove intermediate files)",
)
.default(false)
.hideHelp(),
)
.option("-d, --drives-only", "only build drives, do not boot machine")
.action(async ({ config, drivesOnly }) => {
.action(async ({ config, debug, drivesOnly }) => {
// clean up temp files we create along the process
tmp.setGracefulCleanup();

Expand All @@ -66,7 +75,7 @@ export const createBuildCommand = () => {
const results = Object.entries(c.drives).reduce<
Record<string, Promise<DriveResult>>
>((acc, [name, drive]) => {
acc[name] = buildDrive(name, drive, c.sdk, destination);
acc[name] = buildDrive(name, drive, c.sdk, destination, debug);
return acc;
}, {});

Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/commands/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const createDepositCommand = () => {
"name of project (used by docker compose and cartesi-rollups-node)",
)
.option("--rpc-url <url>", "RPC URL of the Cartesi Devnet")
.action(async (options, command) => {
.action(async (_options, command) => {
// get registered subcommands
const commands = command.commands;

Expand Down
9 changes: 4 additions & 5 deletions apps/cli/src/commands/deposit/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import chalk from "chalk";
import ora from "ora";
import {
type Address,
type PublicClient,
erc20Abi,
formatUnits,
getAddress,
isAddress,
isHex,
parseUnits,
type PublicClient,
} from "viem";
import { getProjectName } from "../../base.js";
import {
Expand Down Expand Up @@ -75,8 +75,7 @@ const parseToken = async (options: {
};

export const createErc20Command = () => {
// biome-ignore lint/complexity/noBannedTypes: commander pattern
return new Command<[], {}, DepositCommandOpts>("erc20")
return new Command<[], Record<string, never>, DepositCommandOpts>("erc20")
.description("Deposit ERC-20 to the application")
.configureHelp({ showGlobalOptions: true })
.argument("[amount]", "amount to send")
Expand Down Expand Up @@ -147,7 +146,7 @@ export const createErc20Command = () => {

// approve if needed
if (allowance < amount) {
progress.start(`Approving ${amountStr}...`);
progress.start(`Approving ${amountLabel}...`);
const { request } = await testClient.simulateContract({
abi: erc20Abi,
account,
Expand All @@ -157,7 +156,7 @@ export const createErc20Command = () => {
});
const hash = await testClient.writeContract(request);
await testClient.waitForTransactionReceipt({ hash });
progress.succeed(`Approved ${amountStr}`);
progress.succeed(`Approved ${amountLabel}`);
}

// simulate deposit call
Expand Down
5 changes: 2 additions & 3 deletions apps/cli/src/commands/deposit/erc721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
type Address,
BaseError,
ContractFunctionRevertedError,
type PublicClient,
erc721Abi,
getAddress,
isAddress,
isHex,
type PublicClient,
} from "viem";
import { getProjectName } from "../../base.js";
import {
Expand Down Expand Up @@ -70,8 +70,7 @@ const parseToken = async (options: {
};

export const createErc721Command = () => {
// biome-ignore lint/complexity/noBannedTypes: commander pattern
return new Command<[], {}, DepositCommandOpts>("erc721")
return new Command<[], Record<string, never>, DepositCommandOpts>("erc721")
.description("Deposit ERC-721 to the application")
.configureHelp({ showGlobalOptions: true })
.argument("[token-id]", "token ID")
Expand Down
3 changes: 1 addition & 2 deletions apps/cli/src/commands/deposit/ether.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { connect } from "../../wallet.js";
import type { DepositCommandOpts } from "../deposit.js";

export const createEtherCommand = () => {
// biome-ignore lint/complexity/noBannedTypes: commander pattern
return new Command<[], {}, DepositCommandOpts>("ether")
return new Command<[], Record<string, never>, DepositCommandOpts>("ether")
.description("Deposit ether to the application")
.configureHelp({ showGlobalOptions: true })
.argument("[amount]", "amount, in ETH units")
Expand Down
3 changes: 2 additions & 1 deletion apps/cli/src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ export const createLogsCommand = () => {
"Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)",
)
.configureHelp({ showGlobalOptions: true })
.action(async (options, command) => {
.action(async (options) => {
const { follow, color, since, tail, until } = options;
const projectName = getProjectName(options);
const logOptions: string[] = ["--no-log-prefix"];
if (follow) logOptions.push("--follow");
if (color === false) logOptions.push("--no-color");
if (since) logOptions.push("--since", since);
if (tail) logOptions.push("--tail", tail);
if (until) logOptions.push("--until", until);
await execa(
"docker",
[
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { getMachineHash, getProjectName } from "../base.js";
import { DEFAULT_SDK_VERSION, PREFERRED_PORT } from "../config.js";
import {
AVAILABLE_SERVICES,
type RollupsDeployment,
deployApplication,
removeApplication,
type RollupsDeployment,
startEnvironment,
stopEnvironment,
waitHealthyEnvironment,
Expand All @@ -33,7 +33,7 @@ const shell = async (options: {
const { build, epochLength, log, projectName } = options;

// keep track of last deployment
let lastDeployment: RollupsDeployment | undefined = undefined;
let lastDeployment: RollupsDeployment | undefined;
let salt = 0;

// deploy for the first time
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/commands/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const getInput = async (
case "uint256":
try {
return BigInt(v);
} catch (e) {
} catch {
throw new Error(`Invalid uint value: ${v}`);
}
case "bytes":
Expand Down Expand Up @@ -116,7 +116,7 @@ export const createSendCommand = () => {
"name of project (used by docker compose and cartesi-rollups-node)",
)
.option("--rpc-url <url>", "RPC URL of the Cartesi Devnet")
.action(async (input, options, program) => {
.action(async (input, options) => {
const { application, from } = options;

const projectName = getProjectName(options);
Expand Down
3 changes: 1 addition & 2 deletions apps/cli/src/commands/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import { bootMachine } from "../machine.js";

export const createShellCommand = () => {
return new Command("shell")
.argument("[image]", "image ID|name")
.option("--command <command>", "shell command to run", "/bin/sh")
.option(
"-c, --config <config>",
"path to the configuration file",
"cartesi.toml",
)
.option("--run-as-root", "run as root user", false)
.action(async (image, { command, config, runAsRoot }) => {
.action(async ({ command, config, runAsRoot }) => {
// get application configuration from 'cartesi.toml'
const c = getApplicationConfig(config);

Expand Down
4 changes: 4 additions & 0 deletions apps/cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export type DirectoryDriveConfig = {

export type DockerDriveConfig = {
builder: "docker";
buildArgs: string[]; // default is empty array
context: string;
dockerfile: string;
extraSize: number; // default is 0 (no extra size)
Expand Down Expand Up @@ -163,6 +164,7 @@ type TomlTable = { [key: string]: TomlPrimitive };

export const defaultRootDriveConfig = (): DriveConfig => ({
builder: "docker",
buildArgs: [],
context: ".",
dockerfile: "Dockerfile", // file on current working directory
extraSize: 0,
Expand Down Expand Up @@ -410,6 +412,7 @@ const parseDrive = (drive: TomlPrimitive): DriveConfig => {
}
case "docker": {
const {
buildArgs,
context,
dockerfile,
extraSize,
Expand All @@ -423,6 +426,7 @@ const parseDrive = (drive: TomlPrimitive): DriveConfig => {
} = drive as TomlTable;
return {
builder: "docker",
buildArgs: parseStringArray(buildArgs),
image: parseOptionalString(image),
context: parseString(context, "."),
dockerfile: parseString(dockerfile, "Dockerfile"),
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/exec/cartesi-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const version = async (
return parse(output.version);
}
return null;
} catch (e: unknown) {
} catch {
return null;
}
};
2 changes: 1 addition & 1 deletion apps/cli/src/exec/rollups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const getDeployments = async (
"list",
]);
return JSON.parse(stdout).map(parseDeployment);
} catch (e: unknown) {
} catch {
return [];
}
};
Expand Down
Loading
Loading