index.ts
Overview
This file serves as the **entry point** for deploying the Litecoin blockchain coinstack services using Pulumi, a modern infrastructure-as-code tool. It orchestrates the setup of Litecoin-specific node daemon and indexer services by:
Reading environment and configuration files.
Fetching Kubernetes cluster access information.
Preparing service deployment arguments tailored to Litecoin.
Invoking the shared
deployCoinstackfunction to provision Kubernetes resources.
The file abstracts the complexities of blockchain node deployment by specifying service parameters such as ports, readiness probes, and configuration maps, allowing seamless, repeatable deployments into Kubernetes clusters.
Detailed Explanation
Exported Async Function (Default Export)
export = async (): Promise<Outputs> => { ... }
This is the main exported asynchronous function executed by Pulumi during the deployment process.
Purpose
To prepare all necessary parameters and configuration objects.
To call the reusable
deployCoinstackfunction with Litecoin-specific arguments.To return the output of the deployment process, which includes Kubernetes resource information and deployment status.
Parameters
This function takes no parameters.
It internally reads files and configurations needed for deployment.
Return Value
Returns a
Promise<Outputs>, whereOutputsis a type representing deployment results such as deployed services, endpoints, and metadata.
Internal Variables and Workflow
Variable | Description |
|---|---|
`appName` | Fixed string `'unchained'` representing the application namespace or deployment grouping. |
`coinstack` | Fixed string `'litecoin'` identifying the blockchain coinstack to deploy. |
`sampleEnv` | Contents of the `sample.env` file loaded via `readFileSync` which contains environment variables to be injected as Kubernetes Secrets. The file path is relative: `'../sample.env'`. |
`{ kubeconfig, config, namespace }` | Destructured result of the asynchronous `getConfig()` call that fetches Kubernetes cluster credentials, the deployment configuration object, and the Kubernetes namespace to deploy into. |
`coinServiceArgs` | An array of `CoinServiceArgs` objects, built by mapping over the configured services in `config.statefulService?.services`. Each service is customized according to its type (`daemon` or `indexer`). |
Service Mapping Logic
The function processes each service defined in the `statefulService.services` array of the config and maps it to a `CoinServiceArgs` object required by the deployment functions.
const coinServiceArgs = config.statefulService?.services?.map((service): CoinServiceArgs => {
switch (service.name) {
case 'daemon':
return {
...service,
ports: { 'daemon-rpc': { port: 8332 } },
readinessProbe: { periodSeconds: 30, failureThreshold: 10 },
}
case 'indexer':
return {
...service,
...defaultBlockbookServiceArgs,
configMapData: { 'indexer-config.json': readFileSync('../indexer/config.json').toString() },
}
default:
throw new Error(`no support for coin service: ${service.name}`)
}
})
Daemon Service:
Assigned a single RPC port
8332under the name'daemon-rpc'.Readiness probe configured to check every 30 seconds with a failure threshold of 10 before marking the pod not ready.
Indexer Service:
Extends default Blockbook service arguments (common defaults for UTXO indexers).
Loads
indexer-config.jsoninto a ConfigMap data entry, allowing the indexer pod to consume its configuration.
Error Handling:
Throws an error if an unsupported service name is encountered, enforcing strict service definitions.
Final Deployment Call
return deployCoinstack({
appName,
coinServiceArgs,
coinstack,
coinstackType: 'node',
config,
kubeconfig,
namespace,
sampleEnv,
})
Invokes
deployCoinstackwith all prepared parameters.coinstackTypeis hardcoded to'node', indicating the nature of the coinstack (i.e., node-based blockchain).Passes the Kubernetes configuration and namespace for resource provisioning.
Supplies the loaded environment variables (
sampleEnv) to be injected as secrets.
Usage Example
This file is not typically imported manually but executed by Pulumi as the deployment entrypoint.
To deploy the Litecoin coinstack:
pulumi up -s <stack-name> --cwd node/coinstacks/litecoin/pulumi
Pulumi will run this script, which will:
Read necessary config files.
Prepare service deployment arguments.
Deploy the Litecoin daemon and indexer as Kubernetes StatefulSets with appropriate configuration.
Important Implementation Details
Configuration Driven: The services to deploy are dynamically discovered from the Pulumi config (
config.statefulService.services), allowing flexible service definitions per environment.Service Customization: Each service type (
daemon,indexer) has custom ports, readiness probes, and ConfigMap data tailored to Litecoin's deployment requirements.Error Safety: The explicit error throw on unknown service names ensures that only supported services are deployed, preventing silent misconfigurations.
File Reads for ConfigMaps: The use of
readFileSyncto load JSON config files and environment variable files (sample.env) enables injecting this data into Kubernetes ConfigMaps and Secrets.Modularity: The deployment logic delegates to the shared
deployCoinstackfunction, promoting code reuse across different coinstacks.
Interaction with Other Parts of the System
Pulumi Core Library (
pulumi/src/coinstack): Provides thedeployCoinstackfunction and types likeOutputsandCoinServiceArgsused in this script.Shared Configuration Utilities: Uses
getConfig()to fetch Kubernetes context and deployment config.Constants from Blockbook Package: Imports
defaultBlockbookServiceArgswhich encapsulates common indexer service defaults for UTXO chains.Filesystem: Reads local files (
sample.env,indexer/config.json) to pass configuration data to Kubernetes pods.Kubernetes: Deploys StatefulSets, Services, ConfigMaps, and Secrets into the Kubernetes cluster for Litecoin node and indexer services.
Pulumi Deployment Process: This file acts as the entrypoint Pulumi script invoked during cluster deployment or updates.
Mermaid Diagram: Flowchart of index.ts Workflow
flowchart TD
A[Start Deployment Script]
B[Read sample.env file]
C[getConfig() → kubeconfig, config, namespace]
D[Map config.statefulService.services to coinServiceArgs]
E{Service Name?}
E -->|daemon| F[Prepare daemon service args: ports, readinessProbe]
E -->|indexer| G[Prepare indexer service args: defaultBlockbookServiceArgs + configMapData]
E -->|unknown| H[Throw Error: Unsupported service]
F & G --> I[Collect all CoinServiceArgs]
I --> J[Call deployCoinstack() with all args]
J --> K[Deploy Litecoin coinstack to Kubernetes]
K --> L[Return deployment outputs]
L --> M[End]
A --> B --> C --> D --> E
Summary
The `index.ts` file is the Litecoin blockchain coinstack's Pulumi deployment entrypoint. It reads environment and configuration files, maps configured services (`daemon` and `indexer`) to deployment arguments with Litecoin-specific settings, and calls the shared `deployCoinstack` function to provision the blockchain node and indexer services as Kubernetes StatefulSets. The script ensures strict service validation, injects configuration via ConfigMaps and Secrets, and integrates with Kubernetes through Pulumi to deliver repeatable, consistent Litecoin infrastructure deployments.
This modular approach aligns with the project's design principles of scalable multi-blockchain support, configuration-as-code, and automated infrastructure management.