index.ts
Overview
This file serves as the Pulumi deployment entrypoint for the **Ethereum coinstack** within the Unchained multi-blockchain infrastructure platform. It defines the Kubernetes deployment configuration and parameters for Ethereum node services—including the primary daemon node, beacon daemon, and indexer—by reading configuration files and environment settings, then invoking a shared deployment utility to provision these services.
In essence, it automates the deployment of Ethereum blockchain infrastructure components into Kubernetes by:
Loading environment variables and configuration files.
Retrieving Kubernetes context and deployment namespace.
Mapping coinstack services (
daemon,daemon-beacon,indexer) to detailedCoinServiceArgsobjects describing ports, environment variables, probes, volume mounts, and startup arguments.Calling
deployCoinstack()with the aggregated configuration to create Kubernetes StatefulSets, Services, ConfigMaps, and ingress routing for these services.
This file is specific to the Ethereum coinstack and reflects Ethereum’s multi-service architecture, including JSON-RPC, WebSocket RPC, authenticated RPC, and beacon node components.
Detailed Breakdown
Imports
import { readFileSync } from 'fs'
import { deployCoinstack } from '../../../../pulumi/src/coinstack'
import { Outputs, CoinServiceArgs, getConfig } from '../../../../pulumi/src'
import { defaultBlockbookServiceArgs } from '../../../packages/blockbook/src/constants'
readFileSync: Used to synchronously read configuration files and environment files.
deployCoinstack: Core Pulumi deployment function that provisions Kubernetes resources for a coinstack.
Outputs, CoinServiceArgs, getConfig: Types and utility function from the shared Pulumi library.
defaultBlockbookServiceArgs: Default configuration constants for Blockbook-based indexer services.
Exported Async Function (Default Export)
export = async (): Promise<Outputs> => { ... }
This is the Pulumi entrypoint function executed during deployment. It returns a Promise resolving to `Outputs` which represent the result of the deployment (e.g., service endpoints, resource IDs).
Variables and Configuration Loading
appName: Fixed to'unchained'indicating the application namespace or identifier.coinstack: Fixed to'ethereum', specifying the blockchain network deployed.sampleEnv: Loads environment variables from a relative../sample.envfile.kubeconfig, config, namespace: Retrieved asynchronously viagetConfig(), providing Kubernetes cluster connection info and coinstack-specific configuration.
const sampleEnv = readFileSync('../sample.env')
const { kubeconfig, config, namespace } = await getConfig()
Service Argument Mapping
The core logic converts the configured services in `config.statefulService?.services` into an array of `CoinServiceArgs` objects, each describing how to deploy a particular service.
const coinServiceArgs = config.statefulService?.services?.map((service): CoinServiceArgs => {
switch (service.name) {
case 'daemon':
// ... configuration for Ethereum daemon node ...
case 'daemon-beacon':
// ... configuration for beacon node daemon ...
case 'indexer':
// ... configuration for indexer service ...
default:
throw new Error(`no support for coin service: ${service.name}`)
}
})
Service: daemon
Ports exposed:
JSON-RPC at 8545
WebSocket RPC at 8546 with path prefix
/websocket(with prefix stripped)Authenticated RPC at 8551 (no ingress route)
Beacon RPC at 3500 (no ingress route)
ConfigMap data:
jwt.hex(read from../daemon/jwt.hex) for JWT secret used in authenticated RPCevm.sh(read from../../../scripts/evm.sh) a helper script for node management
Volume mounts to mount these files inside the pod container.
Environment variable
NETWORKset from config.Kubernetes probes:
Startup probe with 30s period, 60 failure threshold, 10s timeout
Liveness probe with 30s period, 5 failure threshold, 10s timeout
Readiness probe with 30s period, 10 failure threshold, 10s timeout
This configuration ensures the Ethereum daemon pod is properly instrumented for health checks and has access to required secrets and scripts.
Service: daemon-beacon
Command-line arguments passed to the container:
Data directory set to
/dataGRPC gateway host and port configured
Execution endpoint pointing to local authenticated RPC (
http://localhost:8551)JWT secret path for authentication
Terms of use acceptance flag
Single volume mount for the JWT file.
Uses a monitor container (
useMonitorContainer: true) for enhanced health monitoring.Readiness probe configured with a 30s period and 10 failure threshold.
This represents the Ethereum beacon node service which handles consensus layer duties.
Service: indexer
Extends the service with default Blockbook service arguments.
Loads indexer configuration from
../indexer/config.jsoninto a ConfigMap.
This configures the indexer service for Ethereum blockchain data indexing and query APIs.
Deployment Call
After constructing the `coinServiceArgs` array, the function calls `deployCoinstack()` to perform the deployment.
return deployCoinstack({
appName,
coinServiceArgs,
coinstack,
coinstackType: 'node',
config,
kubeconfig,
namespace,
sampleEnv,
})
appName:
'unchained'coinServiceArgs: Array describing each service’s deployment details.
coinstack:
'ethereum'coinstackType:
'node'indicating this coinstack deploys node-based services.config, kubeconfig, namespace: Deployment environment info.
sampleEnv: Environment variables for the deployment.
`deployCoinstack` ultimately provisions Kubernetes resources such as StatefulSets, Services, ConfigMaps, and IngressRoutes according to these parameters.
Important Implementation Details
Service Argument Pattern: Each coinstack service is represented as a
CoinServiceArgsobject, which includes fields likeports,args,env,volumeMounts, and health probes. This pattern abstracts away Kubernetes-specific details and allows the deployment logic to be declarative and consistent across blockchains.File Reading for ConfigMaps: Sensitive files like
jwt.hexand scripts likeevm.share read synchronously from the filesystem and injected into pods as config maps and volume mounts, enabling dynamic configuration without baking secrets into container images.Health Probes: Startup, readiness, and liveness probes with tuned parameters ensure Kubernetes can accurately monitor the health and readiness of blockchain services, enabling self-healing and smooth rolling updates.
Beacon Node Integration: The beacon node daemon is tightly coupled to the authenticated RPC endpoint of the main daemon via the execution endpoint URL
http://localhost:8551and shared JWT secret. This coupling is explicitly configured in the deployment arguments.Error Handling: If an unsupported service name is encountered in the configuration, the function throws an error to prevent invalid deployments.
Interaction with Other System Components
Pulumi Core Library: This file relies heavily on shared Pulumi deployment utilities (
deployCoinstack,getConfig) to retrieve cluster info and provision resources.Kubernetes Cluster: The deployment provisions StatefulSets, Services, ConfigMaps, and IngressRoutes that run within a Kubernetes cluster, orchestrating Ethereum node pods.
Config Files & Scripts: It depends on local files (
jwt.hex,evm.sh,indexer/config.json,sample.env) for configuration and environment setup, which must be maintained in the coinstack directory structure.Other Coinstack Services: While this file configures daemon, beacon, and indexer services, the API servers or additional tooling are managed separately.
Monitoring and Health Systems: Kubernetes probes configured here integrate with cluster monitoring tools for observability and fault detection.
Usage Example
This file is not typically invoked directly by developers. Instead, it is used by the Pulumi CLI as the deployment entrypoint for the Ethereum coinstack.
From the project root, a typical deployment command might be:
pulumi up --cwd coinstacks/ethereum/pulumi
Pulumi will execute this module's exported async function, which reads configuration, maps services, and triggers Kubernetes resource creation.
Mermaid Diagram: Structure of index.ts
flowchart TD
A[Start Deployment] --> B[Read sample.env & config files]
B --> C[Retrieve kubeconfig, config, namespace]
C --> D[Map config.statefulService.services]
D --> E{Service Name}
E -->|daemon| F[Configure daemon service args]
E -->|daemon-beacon| G[Configure beacon service args]
E -->|indexer| H[Configure indexer service args]
E -->|unknown| I[Throw error]
F --> J[Add ports, env, probes, volume mounts]
G --> K[Add args, volume mounts, monitor container, probes]
H --> L[Add defaultBlockbookServiceArgs, configMapData]
J & K & L --> M[Aggregate coinServiceArgs array]
M --> N[Call deployCoinstack() with args]
N --> O[Provision Kubernetes resources]
O --> P[Deployment complete]
Summary
The `index.ts` file is a Pulumi deployment script for the Ethereum coinstack in the Unchained platform. It reads configuration files and Kubernetes context, maps blockchain node services to detailed deployment arguments, and calls a shared deployment function that provisions these services into Kubernetes. The file specifically configures Ethereum’s daemon node, beacon node, and indexer with appropriate ports, environment variables, startup arguments, volume mounts, and health probes to ensure robust, scalable blockchain infrastructure deployments.
This modular, declarative approach facilitates consistent multi-blockchain deployments within a Kubernetes environment and integrates tightly with the broader Pulumi infrastructure-as-code system used throughout the Unchained project.