index.ts


Overview

`index.ts` is the Pulumi deployment entrypoint script responsible for provisioning the **Optimism** blockchain coinstack within the ShapeShift Unchained platform. It automates the configuration and deployment of the Optimism blockchain node services—primarily **daemon**, **op-node**, and **indexer**—onto a Kubernetes cluster.

This script reads configuration and environment files, enriches service definitions with specific parameters (such as environment variables, ports, health probes, and volume mounts), and then invokes a shared deployment function to create the necessary Kubernetes resources. It essentially translates high-level coinstack configuration into concrete Kubernetes StatefulSets, Services, and ConfigMaps for the Optimism network's node infrastructure.


Detailed Explanation

Imports


Exported Async Function (Default Export)

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

This asynchronous function is the Pulumi entrypoint. It returns a `Promise` resolving to deployment `Outputs`, which typically contain references to created Kubernetes resources and other deployment metadata.

Workflow:

  1. Set Constants:

    • appName: Fixed to 'unchained', representing the overarching application name.

    • coinstack: Fixed to 'optimism', defining the blockchain network being deployed.

  2. Read Environment File:

    • Loads ../sample.env into sampleEnv, providing environment variables for the deployment.

  3. Load Kubernetes Config:

    • Calls getConfig() to asynchronously obtain:

      • kubeconfig: Kubernetes cluster connection details.

      • config: The Pulumi configuration object which includes StatefulSet service definitions.

      • namespace: Kubernetes namespace in which to deploy.

  4. Map and Customize Coin Services:

    The script iterates over config.statefulService?.services, mapping each service (daemon, op-node, indexer) to a customized CoinServiceArgs object:

    • Daemon Service:

      • Adds a snapshot URL via environment variable.

      • Defines three ports:

        • daemon-rpc: 8545 (RPC endpoint)

        • daemon-ws: 8546 (WebSocket endpoint with path prefix /websocket)

        • daemon-auth: 8551 (authentication endpoint without ingress route)

      • Includes configMapData with:

        • jwt.hex file content (for JWT authentication)

        • evm.sh script content (helper script)

      • Defines volume mounts to inject these config files into the pod.

      • Configures Kubernetes health probes: startup, liveness, and readiness with tailored timeouts and thresholds.

    • Op-Node Service:

      • Sets environment variables for Layer 1 RPC and Beacon endpoints pointing to the Ethereum service within the cluster.

      • Opens port op-node-rpc on 9545 without ingress route.

      • Includes the evm.sh script config data and volume mounts similar to daemon (including mounting jwt.hex).

      • Defines startup, liveness, and readiness probes with specified timing parameters.

    • Indexer Service:

      • Merges the service with default Blockbook service arguments (standard for indexers).

      • Injects an indexer-config.json from the local ../indexer/config.json file into a ConfigMap.

    • Fallback:

      • Throws an error for unsupported service names, enforcing strict service definitions.

  5. Call deployCoinstack with Prepared Arguments:

    Passes the following to the deployment function:

    • appName: 'unchained'

    • coinServiceArgs: the fully mapped and customized array of service arguments.

    • coinstack: 'optimism'

    • coinstackType: 'node' (indicating this coinstack is a node-based blockchain)

    • config, kubeconfig, namespace: Kubernetes deployment context.

    • sampleEnv: environment variables file buffer.

  6. Return Deployment Outputs:

    • The promise resolves with deployment outputs, which can be used for monitoring or further automation.


Important Types


Usage Example

This file is typically executed by the Pulumi CLI during infrastructure deployment:

pulumi up -s <stack-name>

Pulumi will invoke the exported async function, which will:


Implementation Details and Algorithms


Interaction with Other System Components


Mermaid Diagram: Flowchart of Service Configuration and Deployment in index.ts

flowchart TD
  A[Start Deployment] --> B[Read sample.env File]
  B --> C[Get Kubernetes Config & Namespace]
  C --> D[Map Configured Services]
  D --> E{Service Name?}
  E -->|daemon| F[Configure Daemon Service Args]
  E -->|op-node| G[Configure Op-Node Service Args]
  E -->|indexer| H[Configure Indexer Service Args]
  E -->|other| I[Throw Unsupported Service Error]
  F --> J[Add Env Vars, Ports, Probes, VolumeMounts]
  G --> J
  H --> J
  J --> K[Aggregate Service Arguments]
  K --> L[Call deployCoinstack() with Args]
  L --> M[Deploy Kubernetes Resources]
  M --> N[Pods Start & Health Probes Run]
  N --> O[Optimism Coinstack Running]

Summary


End of Documentation for index.ts