Skip to content

Commit d93b34e

Browse files
endersonmaiatuler
authored andcommitted
feat(cli): migrate compose from YAML to TS
1 parent 5490a39 commit d93b34e

28 files changed

Lines changed: 2176 additions & 637 deletions

.changeset/all-goats-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cartesi/cli": patch
3+
---
4+
5+
migrate compose from YAML to TS

apps/cli/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"semver": "^7.7.2",
4040
"smol-toml": "^1.4.2",
4141
"tmp": "^0.2.5",
42-
"viem": "^2.37.6"
42+
"viem": "^2.37.6",
43+
"yaml": "^2.8.2"
4344
},
4445
"devDependencies": {
4546
"@biomejs/biome": "catalog:",
@@ -56,7 +57,6 @@
5657
"@types/tmp": "^0.2.6",
5758
"@vitest/coverage-istanbul": "^3.2.4",
5859
"@wagmi/cli": "^2.5.1",
59-
"copyfiles": "^2.4.1",
6060
"npm-run-all": "^4.1.5",
6161
"rimraf": "^6.0.1",
6262
"ts-node": "^10.9.2",
@@ -66,13 +66,12 @@
6666
"vitest": "^3.2.4"
6767
},
6868
"scripts": {
69-
"build": "run-s clean codegen compile copy-files",
69+
"build": "run-s clean codegen compile",
7070
"clean": "rimraf dist",
7171
"codegen": "run-p codegen:wagmi",
7272
"codegen:wagmi": "wagmi generate",
7373
"compile": "tsc -p tsconfig.build.json",
7474
"postcompile": "chmod +x dist/index.js",
75-
"copy-files": "copyfiles -u 1 \"src/**/*.yaml\" \"src/**/*.env\" \"src/**/*.txt\" dist",
7675
"lint": "biome lint",
7776
"posttest": "pnpm lint",
7877
"test": "vitest"

apps/cli/src/commands/logs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ export const createLogsCommand = () => {
3535

3636
const serviceInfo = await getServiceInfo({
3737
projectName,
38-
service: "rollups-node",
38+
service: "rollups_node",
3939
});
4040
if (!serviceInfo) {
41-
throw new Error(`service rollups-node not found`);
41+
throw new Error(`service rollups_node not found`);
4242
}
4343

4444
await execa(

apps/cli/src/commands/status.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const createStatusCommand = () => {
2020

2121
const status = await getServiceState({
2222
projectName,
23-
service: "rollups-node",
23+
service: "rollups_node",
2424
});
2525
const deployments = await getDeployments({
2626
projectName,

apps/cli/src/compose/anvil.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import type { ComposeFile, Config, Service } from "../types/compose.js";
2+
import { DEFAULT_HEALTHCHECK } from "./common.js";
3+
4+
type ServiceOptions = {
5+
imageTag?: string;
6+
blockTime?: number;
7+
};
8+
9+
// Anvil service
10+
const service = (options?: ServiceOptions): Service => {
11+
const blockTime = options?.blockTime ?? 2;
12+
const imageTag = options?.imageTag ?? "latest";
13+
14+
return {
15+
image: `cartesi/sdk:${imageTag}`,
16+
command: ["devnet", "--block-time", blockTime.toString()],
17+
healthcheck: {
18+
...DEFAULT_HEALTHCHECK,
19+
test: ["CMD", "eth_isready"],
20+
},
21+
environment: {
22+
ANVIL_IP_ADDR: "0.0.0.0",
23+
},
24+
};
25+
};
26+
27+
const proxy = (): Config => ({
28+
name: "anvil-proxy",
29+
content: `http:
30+
routers:
31+
anvil:
32+
rule: "PathPrefix(\`/anvil\`)"
33+
middlewares:
34+
- "remove-anvil-prefix"
35+
service: anvil
36+
middlewares:
37+
remove-anvil-prefix:
38+
replacePathRegex:
39+
regex: "^/anvil(.*)"
40+
replacement: "$1"
41+
services:
42+
anvil:
43+
loadBalancer:
44+
servers:
45+
- url: "http://anvil:8545"`,
46+
});
47+
48+
export default (options?: ServiceOptions): ComposeFile => ({
49+
configs: {
50+
anvil_proxy: proxy(),
51+
},
52+
services: {
53+
anvil: service(options),
54+
proxy: {
55+
configs: [
56+
{
57+
source: "anvil_proxy",
58+
target: "/etc/traefik/conf.d/anvil.yaml",
59+
},
60+
],
61+
},
62+
},
63+
});

0 commit comments

Comments
 (0)