index.ts
Overview
This file serves as the Pulumi deployment entrypoint for the **Thorchain v1** coinstack within the ShapeShift Unchained platform. It automates the provisioning of blockchain node services in a Kubernetes environment by:
Loading configuration and environment files.
Mapping configured stateful services (specifically the daemon node) into deployment arguments.
Invoking a shared deployment function to create Kubernetes resources for the Thorchain blockchain node.
The file implements the deployment logic tailored specifically for Thorchain’s daemon service, setting environment variables, ports, and health probes necessary for Kubernetes to manage the node’s lifecycle robustly.
Detailed Explanation
Exported Async Function (Default Export)
export = async (): Promise<Outputs> => { ... }
Purpose:
The main asynchronous entrypoint invoked by Pulumi to deploy the Thorchain v1 coinstack.Returns:
APromiseresolving to anOutputsobject, representing the outcome and metadata of the deployment (e.g., deployed resources, endpoints).Function Workflow:
Define Constants:
appName: The application name, set to'unchained'.coinstack: The blockchain identifier, set to'thorchain-v1'.
Load Environment File:
Reads the
sample.envfile from the Thorchain command directory as a Buffer.
Retrieve Kubernetes Configuration:
Calls
getConfig(), a shared utility, to obtain:kubeconfig: Kubernetes cluster credentials.config: The overall coinstack configuration object.namespace: Kubernetes namespace for deployment.
Map Services to Deployment Arguments:
Iterates over
config.statefulService?.services, mapping each service into aCoinServiceArgsobject required by the deployment helper.For each service, performs a switch based on
service.name:daemonservice:Extends the service configuration with:
dataDir: Set to'/root'.env: Injects environment variables:CHAIN_ID:'thorchain-mainnet-v1'.NET: Current network fromconfig.network.
ports: Defines two named ports for the daemon service:'daemon-api': Port 1317, HTTP path prefix/lcdwith path stripping.'daemon-rpc': Port 27147, HTTP path prefix/rpcwith path stripping.
startupProbe: Kubernetes startup probe with:periodSeconds: 30failureThreshold: 60timeoutSeconds: 10
Default case:
Throws an error if a service name other than
'daemon'is encountered, indicating unsupported services.
Deploy the Coinstack:
Calls the
deployCoinstack()function with the following parameters:appName,coinServiceArgs,coinstack,coinstackType: 'go',config,kubeconfig,namespace, andsampleEnv.
This function handles the creation of Kubernetes StatefulSets, Services, ConfigMaps, and related resources for the Thorchain daemon.
Imported Entities
Import | Source Path | Description |
|---|---|---|
`readFileSync` | `'fs'` | Node.js file system method to read files synchronously. |
`deployCoinstack` | `'../../../../pulumi/src/coinstack'` | Shared Pulumi deployment function to provision blockchain services. |
`CoinServiceArgs`, `Outputs`, `getConfig` | `'../../../../pulumi/src'` | Types and utilities for deployment configuration and input/output definitions. |
Important Implementation Details
Service Mapping Strategy:
The file explicitly supports only thedaemonservice for Thorchain, reflecting the current architecture where Thorchain’s coinstack focuses on deploying only the full node daemon. Other services (such as indexers or API servers) are not handled here and would require extensions.Port Configuration:
The daemon exposes two HTTP ports that are proxied with path prefixes (
/lcdand/rpc), enabling differentiated API endpoints for the daemon’s REST and RPC interfaces.
Health Probes:
A startup probe is configured to allow the daemon sufficient time to initialize before Kubernetes begins health checking, important for blockchain nodes that may require prolonged startup.
Environment Variables:
CHAIN_IDandNETenvironment variables are critical to configure the daemon’s network and chain identification, ensuring the node joins the correct Thorchain network.
Deployment Type:
The deployment type is specified as
'go', indicating that this coinstack uses Go-based binaries/services (Thorchain is implemented in Go).
Usage Example
This file is not designed to be imported and invoked manually; instead, it is executed by the Pulumi CLI as part of the deployment process:
pulumi up --cwd path/to/thorchain-v1/pulumi
Under the hood, Pulumi loads this file as the deployment program, runs the exported async function, and manages Kubernetes resources accordingly.
Interaction with Other System Components
Pulumi Core Libraries:
Relies on shared Pulumi utilities and deployment functions (deployCoinstack,getConfig) from the commonpulumi/srclibrary to standardize deployments across coinstacks.Kubernetes Cluster:
The output manifests created bydeployCoinstack()are applied to a Kubernetes cluster, orchestrating pods, services, and ConfigMaps necessary to run Thorchain daemon nodes.Configuration Management:
Reads coinstack-specific configuration and environment files, which are typically maintained alongside other blockchain configurations to allow environment-specific overrides and tuning.Other Coinstacks:
Shares deployment patterns and code structure with other blockchain coinstacks (e.g., Litecoin, Ethereum), facilitating maintainability and consistency across the platform.
Mermaid Class Diagram
The file defines a single main function that orchestrates deployment; no classes are declared. Instead, the key data type is `CoinServiceArgs`, which represents the deployment configuration for each service.
Below is a class diagram depicting the relevant type and the exported function structure:
classDiagram
class CoinServiceArgs {
+name: string
+dataDir?: string
+env?: object
+ports?: object
+startupProbe?: Probe
+readinessProbe?: Probe
+livenessProbe?: Probe
+configMapData?: object
+volumeMounts?: array
}
class Probe {
+periodSeconds: number
+failureThreshold: number
+timeoutSeconds: number
}
class DeployFunction {
+(): Promise<Outputs>
}
DeployFunction ..> CoinServiceArgs : uses
CoinServiceArgs o-- Probe : has
Summary
This [index.ts](/projects/291/68798) file is the Pulumi deployment entrypoint for the Thorchain v1 blockchain coinstack. It reads configuration files, extracts and adapts service definitions (currently only the daemon service), sets required environment variables and ports, and delegates to a shared deployment function to provision Thorchain node services on Kubernetes. The file enforces strict service support and applies health probes to ensure resilience. By following a standardized pattern, it integrates seamlessly with the broader ShapeShift Unchained multi-blockchain deployment system, enabling consistent and automated infrastructure management for Thorchain nodes.