Skip to content
Draft
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/young-foxes-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": patch
---

Update explorer compose definitions to integrate with new rollups-explorer service.
116 changes: 14 additions & 102 deletions apps/cli/src/compose/explorer.ts
Original file line number Diff line number Diff line change
@@ -1,121 +1,40 @@
import { anvil } from "viem/chains";
import type { ComposeFile, Config, Service } from "../types/compose.js";
import { DEFAULT_HEALTHCHECK } from "./common.js";

type ServiceOptions = {
databaseHost?: string;
databasePassword: string;
databasePort?: number;
apiTag?: string;
imageTag?: string;
port?: number;
};

// Explorer API service
export const apiService = (options: ServiceOptions): Service => {
const imageTag = options.apiTag ?? "latest";
const databasePassword = options.databasePassword;
const databaseHost = options.databaseHost ?? "database";
const databasePort = options.databasePort ?? 5432;
// Explorer service
export const explorerService = (options: ServiceOptions): Service => {
const imageTag = options.imageTag ?? "latest";
const port = options.port ?? 6571;

const nodeRpcUrl = `http://127.0.0.1:${port}/anvil`;
const cartesiNodeRpcUrl = `http://127.0.0.1:${port}/rpc`;

return {
image: `cartesi/rollups-explorer-api:${imageTag}`,
image: `cartesi/rollups-explorer:${imageTag}`,
environment: {
DB_PORT: databasePort.toString(),
DB_HOST: databaseHost,
DB_PASS: databasePassword,
DB_NAME: "explorer",
GQL_PORT: 4350,
NODE_RPC_URL: nodeRpcUrl,
CARTESI_NODE_RPC_URL: cartesiNodeRpcUrl,
},
expose: ["4350"],
command: ["sqd", "serve:prod"],
expose: ["3000"],
healthcheck: {
...DEFAULT_HEALTHCHECK,
test: [
"CMD",
"wget",
"--spider",
"-q",
"http://127.0.0.1:4350/graphql?query=%7B__typename%7D",
`http://127.0.0.1:3000/explorer/api/healthz`,
],
},
depends_on: {
database: { condition: "service_healthy" },
},
};
};

// Explorer API Proxy configuration
export const explorerApiProxyConfig = (): Config => {
return {
name: "explorer-api-proxy",
content: `http:
routers:
explorer-api:
rule: "PathPrefix(\`/explorer-api\`)"
middlewares:
- "remove-explorer-api-prefix"
service: explorer_api
middlewares:
remove-explorer-api-prefix:
replacePathRegex:
regex: "^/explorer-api/(.*)"
replacement: "/$1"
services:
explorer_api:
loadBalancer:
servers:
- url: "http://explorer_api:4350"
`,
};
};

// Squid Processor service
export const squidProcessorService = (options: ServiceOptions): Service => {
const imageTag = options.apiTag ?? "latest";
const databasePassword = options.databasePassword;
const databaseHost = options.databaseHost ?? "database";
const databasePort = options.databasePort ?? 5432;
const chain = anvil;
const environment: Record<string, string | number> = {
DB_HOST: databaseHost,
DB_NAME: "explorer",
DB_PASS: databasePassword,
DB_PORT: databasePort.toString(),
CHAIN_IDS: chain.id.toString(),
};
environment[`RPC_URL_${chain.id}`] = `http://anvil:8545`;
environment[`BLOCK_CONFIRMATIONS_${chain.id}`] = 0;
environment[`GENESIS_BLOCK_${chain.id}`] = 1;

return {
image: `cartesi/rollups-explorer-api:${imageTag}`,
environment,
command: ["sqd", "process:prod"],
depends_on: {
database: { condition: "service_healthy" },
},
};
};

// Explorer service
export const explorerService = (options: ServiceOptions): Service => {
const imageTag = options.imageTag ?? "latest";
const port = options.port ?? 6571;

const nodeRpcUrl = `http://127.0.0.1:${port}/anvil`;
const explorerApiUrl = `http://127.0.0.1:${port}/explorer-api/graphql`;

return {
image: `cartesi/rollups-explorer:${imageTag}`,
environment: {
CHAIN_ID: 31337,
EXPLORER_API_URL: explorerApiUrl,
NODE_RPC_URL: nodeRpcUrl,
},
expose: ["3000"],
depends_on: {
database: { condition: "service_healthy" },
anvil: { condition: "service_healthy" },
rollups_node: { condition: "service_healthy" },
},
};
};
Expand All @@ -139,23 +58,16 @@ export const explorerProxyConfig = (): Config => {

export default (options: ServiceOptions): ComposeFile => ({
configs: {
explorer_api_proxy: explorerApiProxyConfig(),
explorer_proxy: explorerProxyConfig(),
},
services: {
explorer_api: apiService(options),
explorer: explorerService(options),
squid_processor: squidProcessorService(options),
proxy: {
configs: [
{
source: "explorer_proxy",
target: "/etc/traefik/conf.d/explorer.yaml",
},
{
source: "explorer_api_proxy",
target: "/etc/traefik/conf.d/explorer-api.yaml",
},
],
},
},
Expand Down
6 changes: 2 additions & 4 deletions apps/cli/src/exec/rollups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const availableServices: Service[] = [
},
{
name: "explorer",
healthySemaphore: "explorer_api",
healthySemaphore: "explorer",
healthyTitle: (port) =>
`${chalk.cyan("explorer")} service ready at ${chalk.cyan(`${host}:${port}/explorer`)}`,
waitTitle: `${chalk.cyan("explorer")} service starting...`,
Expand Down Expand Up @@ -302,9 +302,7 @@ export const startEnvironment = async (options: {
if (services.includes("explorer")) {
files.push(
explorer({
imageTag: "1.4.0",
apiTag: "1.1.0",
databasePassword,
imageTag: "2.0.0-alpha.1",
port,
}),
);
Expand Down
Loading