diff --git a/apps/cli/src/builder/docker.ts b/apps/cli/src/builder/docker.ts index faa2238b..03595756 100644 --- a/apps/cli/src/builder/docker.ts +++ b/apps/cli/src/builder/docker.ts @@ -98,7 +98,7 @@ export const build = async ( drive: DockerDriveConfig, sdkImage: string, destination: string, -): Promise => { +): Promise => { const { format } = drive; const ocitar = `${name}.oci.tar`; @@ -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; }; diff --git a/apps/cli/src/builder/index.ts b/apps/cli/src/builder/index.ts index 0a36754d..659946f2 100644 --- a/apps/cli/src/builder/index.ts +++ b/apps/cli/src/builder/index.ts @@ -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); }; diff --git a/apps/cli/src/commands/build.ts b/apps/cli/src/commands/build.ts index 046ea38e..f7319d35 100644 --- a/apps/cli/src/commands/build.ts +++ b/apps/cli/src/commands/build.ts @@ -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 => { +): Promise => { switch (drive.builder) { case "directory": { return buildDirectory(name, drive, sdkImage, destination); @@ -184,8 +179,7 @@ export default class Build extends BaseCommand { // 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"); diff --git a/apps/cli/src/config.ts b/apps/cli/src/config.ts index 1e062647..7e5e4393 100644 --- a/apps/cli/src/config.ts +++ b/apps/cli/src/config.ts @@ -1,4 +1,5 @@ import bytes from "bytes"; +import os from "os"; import { extname } from "path"; import { TomlPrimitive, parse as parseToml } from "smol-toml"; @@ -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"; +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"; @@ -87,6 +91,15 @@ 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: [], @@ -94,7 +107,7 @@ export const defaultMachineConfig = (): MachineConfig => ({ maxMCycle: undefined, noRollup: undefined, ramLength: DEFAULT_RAM, - ramImage: DEFAULT_RAM_IMAGE, + ramImage: defaultRamImage(), }); export const defaultConfig = (): Config => ({ @@ -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()), }; };