1- import { anvil } from "viem/chains" ;
21import type { ComposeFile , Config , Service } from "../types/compose.js" ;
32import { DEFAULT_HEALTHCHECK } from "./common.js" ;
43
54type ServiceOptions = {
6- databaseHost ?: string ;
7- databasePassword : string ;
8- databasePort ?: number ;
9- apiTag ?: string ;
105 imageTag ?: string ;
116 port ?: number ;
127} ;
138
14- // Explorer API service
15- export const apiService = ( options : ServiceOptions ) : Service => {
16- const imageTag = options . apiTag ?? "latest" ;
17- const databasePassword = options . databasePassword ;
18- const databaseHost = options . databaseHost ?? "database" ;
19- const databasePort = options . databasePort ?? 5432 ;
9+ // Explorer service
10+ export const explorerService = ( options : ServiceOptions ) : Service => {
11+ const imageTag = options . imageTag ?? "latest" ;
12+ const port = options . port ?? 6571 ;
13+
14+ const nodeRpcUrl = `http://127.0.0.1:${ port } /anvil` ;
15+ const cartesiNodeRpcUrl = `http://127.0.0.1:${ port } /rpc` ;
2016
2117 return {
22- image : `cartesi/rollups-explorer-api :${ imageTag } ` ,
18+ image : `cartesi/rollups-explorer:${ imageTag } ` ,
2319 environment : {
24- DB_PORT : databasePort . toString ( ) ,
25- DB_HOST : databaseHost ,
26- DB_PASS : databasePassword ,
27- DB_NAME : "explorer" ,
28- GQL_PORT : 4350 ,
20+ NODE_RPC_URL : nodeRpcUrl ,
21+ CARTESI_NODE_RPC_URL : cartesiNodeRpcUrl ,
2922 } ,
30- expose : [ "4350" ] ,
31- command : [ "sqd" , "serve:prod" ] ,
23+ expose : [ "3000" ] ,
3224 healthcheck : {
3325 ...DEFAULT_HEALTHCHECK ,
3426 test : [
3527 "CMD" ,
3628 "wget" ,
3729 "--spider" ,
3830 "-q" ,
39- " http://127.0.0.1:4350/graphql?query=%7B__typename%7D" ,
31+ ` http://127.0.0.1:3000/explorer/api/healthz` ,
4032 ] ,
4133 } ,
42- depends_on : {
43- database : { condition : "service_healthy" } ,
44- } ,
45- } ;
46- } ;
4734
48- // Explorer API Proxy configuration
49- export const explorerApiProxyConfig = ( ) : Config => {
50- return {
51- name : "explorer-api-proxy" ,
52- content : `http:
53- routers:
54- explorer-api:
55- rule: "PathPrefix(\`/explorer-api\`)"
56- middlewares:
57- - "remove-explorer-api-prefix"
58- service: explorer_api
59- middlewares:
60- remove-explorer-api-prefix:
61- replacePathRegex:
62- regex: "^/explorer-api/(.*)"
63- replacement: "/$1"
64- services:
65- explorer_api:
66- loadBalancer:
67- servers:
68- - url: "http://explorer_api:4350"
69- ` ,
70- } ;
71- } ;
72-
73- // Squid Processor service
74- export const squidProcessorService = ( options : ServiceOptions ) : Service => {
75- const imageTag = options . apiTag ?? "latest" ;
76- const databasePassword = options . databasePassword ;
77- const databaseHost = options . databaseHost ?? "database" ;
78- const databasePort = options . databasePort ?? 5432 ;
79- const chain = anvil ;
80- const environment : Record < string , string | number > = {
81- DB_HOST : databaseHost ,
82- DB_NAME : "explorer" ,
83- DB_PASS : databasePassword ,
84- DB_PORT : databasePort . toString ( ) ,
85- CHAIN_IDS : chain . id . toString ( ) ,
86- } ;
87- environment [ `RPC_URL_${ chain . id } ` ] = `http://anvil:8545` ;
88- environment [ `BLOCK_CONFIRMATIONS_${ chain . id } ` ] = 0 ;
89- environment [ `GENESIS_BLOCK_${ chain . id } ` ] = 1 ;
90-
91- return {
92- image : `cartesi/rollups-explorer-api:${ imageTag } ` ,
93- environment,
94- command : [ "sqd" , "process:prod" ] ,
95- depends_on : {
96- database : { condition : "service_healthy" } ,
97- } ,
98- } ;
99- } ;
100-
101- // Explorer service
102- export const explorerService = ( options : ServiceOptions ) : Service => {
103- const imageTag = options . imageTag ?? "latest" ;
104- const port = options . port ?? 6571 ;
105-
106- const nodeRpcUrl = `http://127.0.0.1:${ port } /anvil` ;
107- const explorerApiUrl = `http://127.0.0.1:${ port } /explorer-api/graphql` ;
108-
109- return {
110- image : `cartesi/rollups-explorer:${ imageTag } ` ,
111- environment : {
112- CHAIN_ID : 31337 ,
113- EXPLORER_API_URL : explorerApiUrl ,
114- NODE_RPC_URL : nodeRpcUrl ,
115- } ,
116- expose : [ "3000" ] ,
11735 depends_on : {
118- database : { condition : "service_healthy" } ,
36+ anvil : { condition : "service_healthy" } ,
37+ rollups_node : { condition : "service_healthy" } ,
11938 } ,
12039 } ;
12140} ;
@@ -139,23 +58,16 @@ export const explorerProxyConfig = (): Config => {
13958
14059export default ( options : ServiceOptions ) : ComposeFile => ( {
14160 configs : {
142- explorer_api_proxy : explorerApiProxyConfig ( ) ,
14361 explorer_proxy : explorerProxyConfig ( ) ,
14462 } ,
14563 services : {
146- explorer_api : apiService ( options ) ,
14764 explorer : explorerService ( options ) ,
148- squid_processor : squidProcessorService ( options ) ,
14965 proxy : {
15066 configs : [
15167 {
15268 source : "explorer_proxy" ,
15369 target : "/etc/traefik/conf.d/explorer.yaml" ,
15470 } ,
155- {
156- source : "explorer_api_proxy" ,
157- target : "/etc/traefik/conf.d/explorer-api.yaml" ,
158- } ,
15971 ] ,
16072 } ,
16173 } ,
0 commit comments