Skip to content

Commit

Permalink
fixup! feat(cli): build based on configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
tuler committed Oct 4, 2024
1 parent f5ffc5e commit c28d308
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
8 changes: 5 additions & 3 deletions apps/cli/src/builder/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const build = async (
drive: DockerDriveConfig,
sdkImage: string,
destination: string,
): Promise<void> => {
): Promise<ImageInfo | undefined> => {
const { format } = drive;

const ocitar = `${name}.oci.tar`;
Expand Down Expand Up @@ -153,7 +153,9 @@ export const build = async (
}
} finally {
// delete intermediate files
await fs.remove(path.join(destination, ocitar));
await fs.remove(path.join(destination, tar));
// await fs.remove(path.join(destination, ocitar));
// await fs.remove(path.join(destination, tar));
}

return imageInfo;
};
3 changes: 1 addition & 2 deletions apps/cli/src/builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ export const tarToExt = async (
"--block-size",
blockSize.toString(),
"--faketime",
"--root",
output,
"--readjustment",
adjustment.toString(),
"--tarball",
input,
output,
];
return execaDockerFallback(command, args, options);
};
12 changes: 3 additions & 9 deletions apps/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@ type ImageInfo = {
workdir: string;
};

type DriveResult_ = {
filename: string;
imageInfo?: ImageInfo;
};

type DriveResult = void;
type DriveResult = ImageInfo | undefined | void;

const buildDrive = async (
name: string,
drive: DriveConfig,
sdkImage: string,
destination: string,
): Promise<void> => {
): Promise<DriveResult> => {
switch (drive.builder) {
case "directory": {
return buildDirectory(name, drive, sdkImage, destination);
Expand Down Expand Up @@ -184,8 +179,7 @@ export default class Build extends BaseCommand<typeof Build> {

// get image info of root drive
const root = await results["root"];
// const imageInfo = root.imageInfo;
const imageInfo = undefined;
const imageInfo = root || undefined;

// path of machine snapshot
const snapshotPath = this.getContextPath("image");
Expand Down
19 changes: 16 additions & 3 deletions apps/cli/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import bytes from "bytes";
import os from "os";
import { extname } from "path";
import { TomlPrimitive, parse as parseToml } from "smol-toml";

Expand All @@ -7,7 +8,10 @@ import { TomlPrimitive, parse as parseToml } from "smol-toml";
*/
const DEFAULT_FORMAT = "ext2";
const DEFAULT_RAM = "128Mi";
const DEFAULT_RAM_IMAGE = "/usr/share/cartesi-machine/images/linux.bin";
const DEFAULT_RAM_IMAGE_DOCKER = "/usr/share/cartesi-machine/images/linux.bin";

Check warning on line 11 in apps/cli/src/config.ts

View workflow job for this annotation

GitHub Actions / lint

'DEFAULT_RAM_IMAGE_DOCKER' is assigned a value but never used
const DEFAULT_RAM_IMAGE_LINUX = "/usr/share/cartesi-machine/images/linux.bin";
const DEFAULT_RAM_IMAGE_MAC =
"/opt/homebrew/share/cartesi-machine/images/linux.bin";
const DEFAULT_SDK = "cartesi/sdk:0.10.0";

type Builder = "directory" | "docker" | "empty" | "none" | "tar";
Expand Down Expand Up @@ -87,14 +91,23 @@ export const defaultRootDriveConfig = (): DriveConfig => ({
tags: [],
});

export const defaultRamImage = (): string => {
switch (os.platform()) {
case "darwin":
return DEFAULT_RAM_IMAGE_MAC;
default:
return DEFAULT_RAM_IMAGE_LINUX;
}
};

export const defaultMachineConfig = (): MachineConfig => ({
assertRollingTemplate: undefined,
bootargs: [],
entrypoint: undefined,
maxMCycle: undefined,
noRollup: undefined,
ramLength: DEFAULT_RAM,
ramImage: DEFAULT_RAM_IMAGE,
ramImage: defaultRamImage(),
});

export const defaultConfig = (): Config => ({
Expand Down Expand Up @@ -265,7 +278,7 @@ const parseMachine = (value: TomlPrimitive): MachineConfig => {
maxMCycle: parseOptionalNumber(toml["max-mcycle"]),
noRollup: parseBoolean(toml["no-rollup"], false),
ramLength: parseString(toml["ram-length"], DEFAULT_RAM),
ramImage: parseString(toml["ram-image"], DEFAULT_RAM_IMAGE),
ramImage: parseString(toml["ram-image"], defaultRamImage()),
};
};

Expand Down

0 comments on commit c28d308

Please sign in to comment.