diff --git a/build/docker-compose.yml b/build/docker-compose.yml index efdeaf4af..45c7b554b 100644 --- a/build/docker-compose.yml +++ b/build/docker-compose.yml @@ -7,8 +7,6 @@ services: build: context: .. dockerfile: build/Dockerfile - tags: - - "cartesi/rollups-node:devel" entrypoint: ["cartesi-rollups-node", "validator"] ports: - "4000:4000" @@ -20,8 +18,8 @@ services: condition: service_completed_successfully hardhat_set_interval: condition: service_completed_successfully - server_manager: - condition: service_healthy + build_machine: + condition: service_completed_successfully database: condition: service_healthy redis: @@ -34,13 +32,13 @@ services: #Advance Runner ADVANCE_RUNNER_HEALTHCHECK_PORT: 8080 - SERVER_MANAGER_ENDPOINT: http://server_manager:5001 + SERVER_MANAGER_ENDPOINT: http://0.0.0.0:5001 PROVIDER_HTTP_ENDPOINT: http://hardhat:8545 SESSION_ID: default_rollups_id SNAPSHOT_DIR: /var/opt/cartesi/machine-snapshots SNAPSHOT_LATEST: /var/opt/cartesi/machine-snapshots/latest - #Authority Claimer + # Authority Claimer AUTHORITY_CLAIMER_HTTP_SERVER_PORT: 8085 TX_PROVIDER_HTTP_ENDPOINT: http://hardhat:8545 TX_CHAIN_ID: 31337 @@ -48,7 +46,7 @@ services: TX_DEFAULT_CONFIRMATIONS: 2 TX_SIGNING_MNEMONIC: "test test test test test test test test test test test junk" - #Dispatcher + # Dispatcher DISPATCHER_HTTP_SERVER_PORT: 8081 DAPP_DEPLOYMENT_FILE: /deployments/localhost/dapp.json ROLLUPS_DEPLOYMENT_FILE: /opt/cartesi/share/deployments/localhost.json @@ -56,22 +54,22 @@ services: SC_GRPC_ENDPOINT: http://0.0.0.0:50051 SC_DEFAULT_CONFIRMATIONS: 1 - #GraphQL Server + # GraphQL Server GRAPHQL_HEALTHCHECK_PORT: 8082 GRAPHQL_HOST: "0.0.0.0" GRAPHQL_PORT: "4000" - #Indexer + # Indexer INDEXER_HEALTHCHECK_PORT: 8083 DAPP_CONTRACT_ADDRESS_FILE: /deployments/localhost/dapp.json REDIS_ENDPOINT: redis://redis:6379 - #Inspect Server + # Inspect Server INSPECT_SERVER_HEALTHCHECK_PORT: 8084 INSPECT_SERVER_ADDRESS: 0.0.0.0:5005 - SERVER_MANAGER_ADDRESS: server_manager:5001 + SERVER_MANAGER_ADDRESS: 0.0.0.0:5001 - #State Server + # State Server SS_SERVER_ADDRESS: 0.0.0.0:50051 SF_GENESIS_BLOCK: 0x1 SF_SAFETY_MARGIN: 1 @@ -79,6 +77,11 @@ services: BH_WS_ENDPOINT: ws://hardhat:8545 BH_BLOCK_TIMEOUT: 8 + # Server Manager + MANAGER_ADDRESS: http://0.0.0.0:5001 + SERVER_MANAGER_LOG_LEVEL: warning + REMOTE_CARTESI_MACHINE_LOG_LEVEL: info + volumes: - machine:/var/opt/cartesi/machine-snapshots - blockchain-data:/opt/cartesi/share/deployments:ro @@ -113,8 +116,8 @@ services: depends_on: hardhat: condition: service_healthy - server_manager: - condition: service_healthy + build_machine: + condition: service_completed_successfully command: [ "create", @@ -164,23 +167,13 @@ services: "http://hardhat:8545", ] - server_manager: + build_machine: + image: cartesi/rollups-machine:devel build: context: .. dockerfile: build/machine.Dockerfile - restart: always - ports: - - "5001:5001" - healthcheck: - test: ["CMD-SHELL", 'bash -c ''echo "" > /dev/tcp/127.0.0.1/5001;'''] - interval: 10s - timeout: 5s - retries: 5 volumes: - machine:/var/opt/cartesi/machine-snapshots - environment: - - SERVER_MANAGER_LOG_LEVEL=warning - - REMOTE_CARTESI_MACHINE_LOG_LEVEL=info database: image: postgres:13-alpine diff --git a/build/machine.Dockerfile b/build/machine.Dockerfile index 221811764..a0a1eb942 100644 --- a/build/machine.Dockerfile +++ b/build/machine.Dockerfile @@ -1,7 +1,7 @@ # (c) Cartesi and individual authors (see AUTHORS) # SPDX-License-Identifier: Apache-2.0 (see LICENSE) -FROM cartesi/server-manager:0.8.2 as build-server-stage +FROM cartesi/server-manager:0.8.2 as build-machine-stage USER root @@ -23,8 +23,9 @@ RUN cartesi-machine \ --store=$SNAPSHOT_DIR \ -- "ioctl-echo-loop --vouchers=1 --notices=1 --reports=1 --verbose=1" -FROM cartesi/server-manager:0.8.2 as server-stage +FROM alpine:3.18.4 as machine-stage WORKDIR /opt/cartesi/bin -COPY --from=build-server-stage --chown=cartesi:cartesi /tmp/dapp-bin /var/opt/cartesi/machine-snapshots/0_0 +COPY --from=build-machine-stage --chown=cartesi:cartesi /tmp/dapp-bin /var/opt/cartesi/machine-snapshots/0_0 RUN ln -s /var/opt/cartesi/machine-snapshots/0_0 /var/opt/cartesi/machine-snapshots/latest +ENTRYPOINT [ "/bin/sh" ] \ No newline at end of file diff --git a/internal/node/node.go b/internal/node/node.go index e8689597c..96be00d94 100644 --- a/internal/node/node.go +++ b/internal/node/node.go @@ -13,51 +13,63 @@ import ( "github.com/cartesi/rollups-node/internal/services" ) +const ( + serverManagerPort = "5001" + serverManagerAddress = "0.0.0.0:" + serverManagerPort +) + var ValidatorServices = []services.Service{ - StateServer, + StateServer, // must start before Dispatcher AdvanceRunner, AuthorityClaimer, Dispatcher, GraphQLServer, Indexer, InspectServer, + ServerManager, } var ( AdvanceRunner = services.NewService( "advance-runner", - "cartesi-rollups-advance-runner", healthcheckPort("advance-runner"), + "cartesi-rollups-advance-runner", ) AuthorityClaimer = services.NewService( "authority-claimer", - "cartesi-rollups-authority-claimer", healthcheckPort("authority-claimer"), + "cartesi-rollups-authority-claimer", ) Dispatcher = services.NewService( "dispatcher", - "cartesi-rollups-dispatcher", healthcheckPort("dispatcher"), + "cartesi-rollups-dispatcher", ) GraphQLServer = services.NewService( "graphql-server", - "cartesi-rollups-graphql-server", healthcheckPort("graphql"), + "cartesi-rollups-graphql-server", ) Indexer = services.NewService( "indexer", - "cartesi-rollups-indexer", healthcheckPort("indexer"), + "cartesi-rollups-indexer", ) InspectServer = services.NewService( "inspect-server", - "cartesi-rollups-inspect-server", healthcheckPort("inspect-server"), + "cartesi-rollups-inspect-server", ) StateServer = services.NewService( "state-server", - "cartesi-rollups-state-server", stateServerHealthcheckPort(), + "cartesi-rollups-state-server", + ) + ServerManager = services.NewService( + "server-manager", + serverManagerPort, + "server-manager", + "--manager-address="+serverManagerAddress, ) ) diff --git a/internal/services/service.go b/internal/services/service.go index 07d9d447a..25309806e 100644 --- a/internal/services/service.go +++ b/internal/services/service.go @@ -25,18 +25,21 @@ const ( type Service struct { name string - binaryName string healthcheckPort string + path string + args []string } -func NewService(name, binaryName, healthcheckPort string) Service { - return Service{name, binaryName, healthcheckPort} +// Name identifies the service +// HealthcheckPort is a port used to verify if the service is ready +func NewService(name, healthcheckPort, path string, args ...string) Service { + return Service{name, healthcheckPort, path, args} } // Start will execute a binary and wait for its completion or until the context // is canceled func (s Service) Start(ctx context.Context) error { - cmd := exec.CommandContext(ctx, s.binaryName) + cmd := exec.CommandContext(ctx, s.path, s.args...) cmd.Stderr = os.Stderr cmd.Stdout = os.Stdout cmd.Cancel = func() error { diff --git a/internal/services/service_test.go b/internal/services/service_test.go index 065c94ffd..5d0531cf4 100644 --- a/internal/services/service_test.go +++ b/internal/services/service_test.go @@ -45,7 +45,7 @@ func (s *ServiceTestSuite) SetupTest() { func (s *ServiceTestSuite) TestServiceStops() { service := Service{ name: "fake-service", - binaryName: "fake-service", + path: "fake-service", healthcheckPort: fmt.Sprint(s.servicePort), } ctx, cancel := context.WithCancel(context.Background()) @@ -69,7 +69,7 @@ func (s *ServiceTestSuite) TestServiceStops() { func (s *ServiceTestSuite) TestServiceTimeout() { service := Service{ name: "fake-service", - binaryName: "fake-service", + path: "fake-service", healthcheckPort: "0000", // wrong port } ctx, cancel := context.WithCancel(context.Background()) @@ -94,7 +94,7 @@ func (s *ServiceTestSuite) TestServiceTimeout() { func (s *ServiceTestSuite) TestServiceReady() { service := Service{ name: "fake-service", - binaryName: "fake-service", + path: "fake-service", healthcheckPort: fmt.Sprint(s.servicePort), } ctx, cancel := context.WithCancel(context.Background())