Skip to content

Commit

Permalink
feat: start server-manager as internal service
Browse files Browse the repository at this point in the history
  • Loading branch information
torives committed Nov 28, 2023
1 parent af328c6 commit ed31e94
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 44 deletions.
45 changes: 19 additions & 26 deletions build/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ services:
build:
context: ..
dockerfile: build/Dockerfile
tags:
- "cartesi/rollups-node:devel"
entrypoint: ["cartesi-rollups-node", "validator"]
ports:
- "4000:4000"
Expand All @@ -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:
Expand All @@ -34,51 +32,56 @@ 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
TX_CHAIN_IS_LEGACY: ${TX_LEGACY:-false}
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
RD_EPOCH_DURATION: 86400
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
BH_HTTP_ENDPOINT: http://hardhat:8545
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
Expand Down Expand Up @@ -113,8 +116,8 @@ services:
depends_on:
hardhat:
condition: service_healthy
server_manager:
condition: service_healthy
build_machine:
condition: service_completed_successfully
command:
[
"create",
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions build/machine.Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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" ]
28 changes: 20 additions & 8 deletions internal/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)

Expand Down
11 changes: 7 additions & 4 deletions internal/services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions internal/services/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand Down

0 comments on commit ed31e94

Please sign in to comment.