index.ts

Overview

This file serves as the **Pulumi entry point** for deploying the Bitcoin coinstack within the Unchained infrastructure automation system. Its primary responsibility is to:

It integrates blockchain-specific parameters with the generic deployment automation framework, enabling consistent, configurable, and repeatable deployment of Bitcoin node services on Kubernetes clusters.


Detailed Explanation

Module Imports

import { readFileSync } from 'fs'
import { deployCoinstack } from '../../../../pulumi/src/coinstack'
import { CoinServiceArgs, Outputs, getConfig } from '../../../../pulumi/src'
import { defaultBlockbookServiceArgs } from '../../../packages/blockbook/src/constants'

Exported Async Function (Default Pulumi Entry Point)

export = async (): Promise<Outputs> => { ... }

This anonymous async function is the Pulumi program’s entry point, following Pulumi’s JavaScript/TypeScript pattern.


Variables and Configuration

const appName = 'unchained'
const coinstack = 'bitcoin'
const sampleEnv = readFileSync('../sample.env')
const { kubeconfig, config, namespace } = await getConfig()

Preparing coinServiceArgs

const coinServiceArgs = config.statefulService?.services?.map((service): CoinServiceArgs => {
  switch (service.name) {
    case 'daemon':
      return {
        ...service,
        ports: { 'daemon-rpc': { port: 8332 } },
        env: {
          NETWORK: config.network,
        },
        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}`)
  }
})

**Parameters:**

**Returns:**


Deploying the Coinstack

return deployCoinstack({
  appName,
  coinServiceArgs,
  coinstack,
  coinstackType: 'node',
  config,
  kubeconfig,
  namespace,
  sampleEnv,
})

Calls the core deployment orchestration function with all necessary parameters:


Usage Example

This file is executed automatically by Pulumi CLI as the deployment entry point. To deploy the Bitcoin coinstack:

pulumi up --cwd node/coinstacks/bitcoin/pulumi

Pulumi will run this async function, which:


Important Implementation Details


Interaction with Other System Components


Visual Diagram: File Structure and Workflow

flowchart TD
    A[Start] --> B[Read sample.env file]
    B --> C[Retrieve Kubernetes config via getConfig()]
    C --> D[Map config.statefulService.services to coinServiceArgs]
    D -->|For each service| E{Service name}
    E -->|daemon| F[Add ports, env, readinessProbe]
    E -->|indexer| G[Merge defaultBlockbookServiceArgs + configMapData]
    E -->|other| H[Throw Error: unsupported service]
    F & G --> I[Collect CoinServiceArgs array]
    I --> J[Call deployCoinstack with deployment parameters]
    J --> K[Deploy Kubernetes resources for coinstack]
    K --> L[End]

Summary

The **index.ts** file is the Bitcoin coinstack Pulumi deployment entry point. It prepares blockchain node service configurations and invokes the deployment orchestration function to deploy the daemon and indexer as Kubernetes StatefulSets with appropriate environment variables, ports, and health checks. This file acts as the critical bridge between blockchain-specific deployment parameters and the generic Pulumi-based deployment automation framework.