index.ts
Overview
This file serves as the Pulumi deployment entrypoint for the **Gnosis** blockchain coinstack within the Unchained multi-blockchain infrastructure. It orchestrates the deployment of blockchain node services—specifically daemon nodes, beacon nodes, and indexers—into a Kubernetes cluster by preparing service-specific configuration and passing them to a shared deployment utility (`deployCoinstack`).
The primary functionality includes:
Reading environment and configuration files.
Fetching Kubernetes context and namespace information.
Mapping configured services from the coinstack’s stateful service configuration into detailed deployment arguments (
CoinServiceArgs), customizing ports, commands, volumes, health probes, and config maps.Calling
deployCoinstackto provision Kubernetes StatefulSets, Services, ConfigMaps, and related resources for the coinstack services.
This file abstracts the specifics of the Gnosis blockchain node deployment while leveraging shared Pulumi libraries for consistency across all coinstacks.
Detailed Explanation
Imports
readFileSync (from
fs): Reads local files synchronously, used here to load environment and configuration files such as.envfiles, JWT tokens, and indexer configs.deployCoinstack (from the shared Pulumi coinstack library): The deployment function that takes prepared service arguments and provisions Kubernetes resources.
Outputs, CoinServiceArgs, getConfig (from shared Pulumi library): Types and helper functions for configuration retrieval and deployment parameters.
defaultBlockbookServiceArgs (from blockbook package): Provides default configuration values for indexer services based on Blockbook.
Exported Async Function (Default Export)
export = async (): Promise<Outputs> => { ... }
This is the Pulumi entrypoint function, returning a Promise resolving to `Outputs` which encapsulates deployment results.
Execution Steps:
Define Deployment Context Variables
const appName = 'unchained' const coinstack = 'gnosis'These identify the application and blockchain coinstack.
Read Sample Environment File
const sampleEnv = readFileSync('../sample.env')Loads environment variable definitions for deployment.
Load Kubernetes Config and Namespace
const { kubeconfig, config, namespace } = await getConfig()Retrieves cluster access credentials, deployment configuration, and namespace.
Map Stateful Services to Deployment Arguments
const coinServiceArgs = config.statefulService?.services?.map((service): CoinServiceArgs => { switch (service.name) { ... } })For each service listed in the coinstack’s
statefulService.servicesconfiguration, the code builds aCoinServiceArgsobject customized by service name. This object includes ports, commands, volume mounts, config maps, Kubernetes probes, and any special flags.Supported service names and their configurations:
daemonPorts:
daemon-http: TCP 8545 (HTTP RPC)daemon-ws: TCP 8546 (WebSocket RPC) with path prefix/websocketand stripping enableddaemon-auth: TCP 8551 (authentication endpoint), with ingress routing disabled
ConfigMap Data:
Loads
jwt.hexfile contents for authentication tokens
Kubernetes Probes:
Startup, liveness, and readiness probes configured with specific timeouts and thresholds
Volume Mounts:
Mounts the
jwt.hexfile at/jwt.hexinside the container
daemon-beaconCommand:
Runs Lighthouse beacon node with specific flags for Gnosis network, disabling UPnP, setting data directories, enabling HTTP endpoint, linking to the execution endpoint and JWT token, and specifying a checkpoint sync URL
ConfigMap Data:
Same
jwt.hexfile for JWT authentication
Volume Mounts:
Mounts
jwt.hexat/jwt.hex
Flags:
useMonitorContainer: trueenables monitoring container sidecar (for health/metrics)
Readiness Probe:
Configured with period and failure threshold
indexerExtends
defaultBlockbookServiceArgsto inherit default indexer settingsConditional configuration based on environment:
For development (
config.environment === 'dev'), disables processing of ERC-1155 tokens by adding-processerc1155=falseflag to the commandOtherwise, disables readiness probe (presumably due to a known patch or behavior on Gnosis)
ConfigMap Data:
Loads
indexer-config.jsonfor indexer-specific configuration
Default Case
Throws an error if an unsupported service name is encountered, preventing deployment of unrecognized services.
Invoke Deployment
return deployCoinstack({ appName, coinServiceArgs, coinstack, coinstackType: 'node', config, kubeconfig, namespace, sampleEnv, })Calls the shared deployment function with the constructed arguments, triggering provisioning of all Kubernetes resources required for the coinstack.
Parameters and Return Types
Parameters
The exported async function takes no explicit parameters. It relies on:
Local environment and configuration files (e.g.,
../sample.env,../daemon/jwt.hex,../indexer/config.json)Pulumi configuration fetched via
getConfig()
Return Value
Returns a Promise resolving to an
Outputsobject representing the Kubernetes deployment outputs (e.g., service endpoints, pod statuses).
Usage Example
This file is typically invoked by the Pulumi CLI during deployment, e.g.:
pulumi up --cwd path/to/coinstacks/gnosis/pulumi
No direct function calls or parameters are needed; Pulumi loads and executes this entrypoint asynchronously.
Important Implementation Details
Service Mapping: Uses a
switchstatement to customize the service deployment arguments based on service name, enabling fine-tuned configuration per service type.File Reading: Reads critical configuration files synchronously before deployment to embed their contents in Kubernetes ConfigMaps.
Health Probes: Configures Kubernetes startup, readiness, and liveness probes with careful timeout and failure thresholds to ensure robust pod health monitoring.
Volume Mounts: Mounts sensitive files such as
jwt.hexas Kubernetes ConfigMaps to avoid baking secrets into container images.Beacon Node Command: Includes a custom command array for the
daemon-beaconservice that specifies Lighthouse-specific flags for Gnosis chain consensus layer node operation.Conditional Logic Based on Environment: Adjusts indexer service command-line flags depending on whether the environment is development or production.
Interaction with Other System Components
Pulumi Core Libraries: Imports
deployCoinstack,getConfig, and related types from the shared Pulumi infrastructure codebase, which contains reusable deployment primitives and helpers.Kubernetes Cluster: Deploys StatefulSets, Services, and ConfigMaps into a configured Kubernetes cluster namespace.
Blockbook Indexer Package: Uses
defaultBlockbookServiceArgsconstants from the Blockbook package to standardize indexer deployment configurations.File System: Reads configuration files and secrets from the local filesystem relative to this script’s location.
Other Coinstack Services: This deployment script is part of a larger multi-blockchain deployment system, each coinstack having similar scripts with variations tailored to the blockchain protocol.
Mermaid Diagram: Flowchart of Service Configuration & Deployment Flow
flowchart TD
A[Start: Pulumi Deployment Entry] --> B[Read sample.env]
B --> C[Get Kubernetes Config & Namespace]
C --> D{Map stateful services}
D --> E[Service: daemon]
D --> F[Service: daemon-beacon]
D --> G[Service: indexer]
D --> H[Unsupported Service -> Throw Error]
E --> I[Set ports, probes, mounts, jwt config]
F --> J[Set command (lighthouse), mounts, probes, monitor container]
G --> K[Extend defaultBlockbookServiceArgs, set config, conditional flags]
I --> L[Aggregate service args]
J --> L
K --> L
L --> M[Call deployCoinstack with args]
M --> N[Provision Kubernetes resources]
N --> O[Pods start & run probes]
O --> P[Deployment complete]
Summary
This [index.ts](/projects/291/68798) file is the Gnosis blockchain coinstack Pulumi deployment script that:
Reads configuration files and environment variables.
Constructs detailed service deployment arguments for daemon, beacon, and indexer services with blockchain-specific customizations.
Calls a shared Pulumi deployment function to provision Kubernetes resources.
Ensures health monitoring and secure configuration injection via ConfigMaps.
It fits into the multi-blockchain Unchained architecture by providing a modular, declarative deployment of Gnosis blockchain infrastructure components, enabling scalable and maintainable multi-chain operation within Kubernetes.
If you need more details on the shared `deployCoinstack` function or the `CoinServiceArgs` interface, please refer to the Pulumi core library documentation.