Skip to content
Open
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
32 changes: 15 additions & 17 deletions apps/cli/src/commands/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,34 @@ import { exec } from "@arbitrum/testnode-core/exec.js";
import { stopCurrentRun } from "@arbitrum/testnode-core/run-logger.js";
import { SNAPSHOTS_DIRNAME } from "@arbitrum/testnode-core/snapshot.js";
import { Cli, z } from "incur";
import { findProjectRoot } from "../project-root.js";
import { projectRoot } from "../project-root.js";

const PROJECT_ROOT = findProjectRoot();
const CONFIG_DIR = resolve(PROJECT_ROOT, "config");
const COMPOSE_FILE = resolve(PROJECT_ROOT, "docker/docker-compose.yaml");

function stopAllServices(): void {
function stopAllServices(composeFile: string): void {
console.log("[clean] Stopping Docker...");
composeDown({ composeFile: COMPOSE_FILE, projectName: "arbitrum-testnode" });
exec("docker", ["compose", "-f", COMPOSE_FILE, "-p", "arbitrum-testnode", "down", "-v"]);
composeDown({ composeFile, projectName: "arbitrum-testnode" });
exec("docker", ["compose", "-f", composeFile, "-p", "arbitrum-testnode", "down", "-v"]);
}

function removeConfigDirPreservingSnapshots(): void {
for (const entry of readdirSync(CONFIG_DIR)) {
function removeConfigDirPreservingSnapshots(configDir: string): void {
for (const entry of readdirSync(configDir)) {
if (entry === SNAPSHOTS_DIRNAME) {
continue;
}
rmSync(join(CONFIG_DIR, entry), { recursive: true, force: true });
rmSync(join(configDir, entry), { recursive: true, force: true });
}
}

function cleanConfigDir(purgeSnapshots: boolean): void {
if (!existsSync(CONFIG_DIR)) {
function cleanConfigDir(configDir: string, purgeSnapshots: boolean): void {
if (!existsSync(configDir)) {
return;
}
if (purgeSnapshots) {
console.log("[clean] Removing config directory...");
rmSync(CONFIG_DIR, { recursive: true, force: true });
rmSync(configDir, { recursive: true, force: true });
return;
}
console.log("[clean] Removing runtime data and preserving snapshots...");
removeConfigDirPreservingSnapshots();
removeConfigDirPreservingSnapshots(configDir);
}

export const cleanCli = Cli.create("clean", {
Expand All @@ -48,9 +44,11 @@ export const cleanCli = Cli.create("clean", {
.describe("Also delete snapshot bundles under config/snapshots"),
}),
run(c) {
const CONFIG_DIR = resolve(projectRoot(), "config");
const COMPOSE_FILE = resolve(projectRoot(), "docker/docker-compose.yaml");
stopCurrentRun(CONFIG_DIR);
stopAllServices();
cleanConfigDir(c.options.purgeSnapshots ?? false);
stopAllServices(COMPOSE_FILE);
cleanConfigDir(CONFIG_DIR, c.options.purgeSnapshots ?? false);
console.log("[clean] Done.");
return { success: true };
},
Expand Down
6 changes: 2 additions & 4 deletions apps/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createInitContext, runInitCommand } from "@arbitrum/testnode-core/init-runner.js";
import { Cli, z } from "incur";
import { findProjectRoot } from "../project-root.js";

const PROJECT_ROOT = findProjectRoot();
import { projectRoot } from "../project-root.js";

export const initCli = Cli.create("init", {
description: "Initialize the testnode (L1 + L2 + L3 with bridges)",
Expand Down Expand Up @@ -38,6 +36,6 @@ export const initCli = Cli.create("init", {
.describe("Deploy Timeboost contracts and restart L2 with Timeboost enabled"),
}),
async run(c) {
return runInitCommand(c.options, createInitContext(PROJECT_ROOT));
return runInitCommand(c.options, createInitContext(projectRoot()));
},
});
6 changes: 2 additions & 4 deletions apps/cli/src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import {
readTextLogTail,
} from "@arbitrum/testnode-core/run-logger.js";
import { Cli, z } from "incur";
import { findProjectRoot } from "../project-root.js";

const PROJECT_ROOT = findProjectRoot();
const CONFIG_DIR = resolve(PROJECT_ROOT, "config");
import { projectRoot } from "../project-root.js";

export const logsCli = Cli.create("logs", {
description: "Show the latest init run logs",
Expand All @@ -17,6 +14,7 @@ export const logsCli = Cli.create("logs", {
raw: z.boolean().optional().describe("Read the plain text output log instead of JSON events"),
}),
run(c) {
const CONFIG_DIR = resolve(projectRoot(), "config");
const run = loadCurrentRun(CONFIG_DIR);
if (!run) {
return { success: false, error: "No init run found" };
Expand Down
70 changes: 0 additions & 70 deletions apps/cli/src/commands/registry.ts

This file was deleted.

26 changes: 18 additions & 8 deletions apps/cli/src/commands/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ import {
verifySnapshotSemanticState,
} from "@arbitrum/testnode-core/snapshot.js";
import { Cli, z } from "incur";
import { findProjectRoot } from "../project-root.js";
import { projectRoot } from "../project-root.js";

const PROJECT_ROOT = findProjectRoot();
const CONFIG_DIR = resolve(PROJECT_ROOT, "config");
const COMPOSE_FILE = resolve(PROJECT_ROOT, "docker/docker-compose.yaml");
const SNAPSHOT_PACK_DIR = resolve(PROJECT_ROOT, "dist/snapshots");
function snapshotPackDir(): string {
return resolve(projectRoot(), "dist/snapshots");
}

const RPCS = {
l1: "http://127.0.0.1:8545",
Expand Down Expand Up @@ -56,14 +55,18 @@ const snapshotPackOptions = z.object({
outDir: z
.string()
.optional()
.describe(`Output directory for packaged assets (default: ${SNAPSHOT_PACK_DIR})`),
.describe(
"Output directory for packaged assets (default: dist/snapshots under the project root)",
),
tag: z.string().describe("Release tag used in the packaged asset names"),
});

snapshotCli.command("build", {
description: "Capture the current initialized stack into a reusable snapshot",
options: snapshotOptions,
async run(c) {
const CONFIG_DIR = resolve(projectRoot(), "config");
const COMPOSE_FILE = resolve(projectRoot(), "docker/docker-compose.yaml");
const snapshotId = c.options.id ?? DEFAULT_SNAPSHOT_ID;
await verifySnapshotSemanticState(CONFIG_DIR, RPCS);
stopRuntime({
Expand Down Expand Up @@ -99,6 +102,8 @@ snapshotCli.command("restore", {
description: "Restore a snapshot and start the stack from it",
options: snapshotOptions,
async run(c) {
const CONFIG_DIR = resolve(projectRoot(), "config");
const COMPOSE_FILE = resolve(projectRoot(), "docker/docker-compose.yaml");
const snapshotId = c.options.id ?? DEFAULT_SNAPSHOT_ID;
stopRuntime({
composeFile: COMPOSE_FILE,
Expand Down Expand Up @@ -133,6 +138,7 @@ snapshotCli.command("verify", {
description: "Verify snapshot structure and, if running, semantic bridge state",
options: snapshotOptions,
async run(c) {
const CONFIG_DIR = resolve(projectRoot(), "config");
const snapshotId = c.options.id ?? DEFAULT_SNAPSHOT_ID;
const manifest = verifySnapshotManifest(CONFIG_DIR, snapshotId);
let semanticState: "skipped" | "verified" = "skipped";
Expand All @@ -158,6 +164,8 @@ snapshotCli.command("install", {
description: "Download and install a snapshot release",
options: snapshotInstallOptions,
async run(c) {
const CONFIG_DIR = resolve(projectRoot(), "config");
const COMPOSE_FILE = resolve(projectRoot(), "docker/docker-compose.yaml");
const result = await installSnapshotRelease({
composeFile: COMPOSE_FILE,
configDir: CONFIG_DIR,
Expand All @@ -183,8 +191,9 @@ snapshotCli.command("pack", {
description: "Package a local snapshot into GitHub release assets",
options: snapshotPackOptions,
run(c) {
const CONFIG_DIR = resolve(projectRoot(), "config");
const result = packageSnapshotRelease(CONFIG_DIR, {
outDir: c.options.outDir ?? SNAPSHOT_PACK_DIR,
outDir: c.options.outDir ?? snapshotPackDir(),
tag: c.options.tag,
...(c.options.id ? { snapshotId: c.options.id } : {}),
});
Expand All @@ -205,6 +214,7 @@ snapshotCli.command("invalidate", {
description: "Remove a snapshot bundle",
options: snapshotOptions,
run(c) {
const CONFIG_DIR = resolve(projectRoot(), "config");
const snapshotId = c.options.id ?? DEFAULT_SNAPSHOT_ID;
return {
success: true,
Expand All @@ -215,5 +225,5 @@ snapshotCli.command("invalidate", {
});

export function hasDefaultSnapshot(): boolean {
return hasSnapshot(CONFIG_DIR, DEFAULT_SNAPSHOT_ID);
return hasSnapshot(resolve(projectRoot(), "config"), DEFAULT_SNAPSHOT_ID);
}
10 changes: 4 additions & 6 deletions apps/cli/src/commands/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ import {
} from "@arbitrum/testnode-core/run-logger.js";
import { loadState } from "@arbitrum/testnode-core/state.js";
import { Cli } from "incur";
import { findProjectRoot } from "../project-root.js";

const PROJECT_ROOT = findProjectRoot();
const CONFIG_DIR = resolve(PROJECT_ROOT, "config");
const COMPOSE_FILE = resolve(PROJECT_ROOT, "docker/docker-compose.yaml");
const DOCKER_OPTS = { composeFile: COMPOSE_FILE, projectName: "arbitrum-testnode" };
import { projectRoot } from "../project-root.js";

const RPCS = {
l1: "http://127.0.0.1:8545",
Expand All @@ -23,6 +18,9 @@ const RPCS = {
export const statusCli = Cli.create("status", {
description: "Show testnode status",
run() {
const CONFIG_DIR = resolve(projectRoot(), "config");
const COMPOSE_FILE = resolve(projectRoot(), "docker/docker-compose.yaml");
const DOCKER_OPTS = { composeFile: COMPOSE_FILE, projectName: "arbitrum-testnode" };
const state = loadState(CONFIG_DIR);
const run = loadCurrentRun(CONFIG_DIR);

Expand Down
10 changes: 4 additions & 6 deletions apps/cli/src/commands/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import { resolve } from "node:path";
import { composeDown } from "@arbitrum/testnode-core/docker.js";
import { stopCurrentRun } from "@arbitrum/testnode-core/run-logger.js";
import { Cli } from "incur";
import { findProjectRoot } from "../project-root.js";

const PROJECT_ROOT = findProjectRoot();
const CONFIG_DIR = resolve(PROJECT_ROOT, "config");
const COMPOSE_FILE = resolve(PROJECT_ROOT, "docker/docker-compose.yaml");
const DOCKER_OPTS = { composeFile: COMPOSE_FILE, projectName: "arbitrum-testnode" };
import { projectRoot } from "../project-root.js";

export const stopCli = Cli.create("stop", {
description: "Stop the testnode (kills Anvil + Docker)",
run() {
const CONFIG_DIR = resolve(projectRoot(), "config");
const COMPOSE_FILE = resolve(projectRoot(), "docker/docker-compose.yaml");
const DOCKER_OPTS = { composeFile: COMPOSE_FILE, projectName: "arbitrum-testnode" };
if (stopCurrentRun(CONFIG_DIR)) {
console.log("[stop] Stopped detached init run...");
}
Expand Down
Loading
Loading