docker-compose.j2

Overview

This file is a Jinja2 template for generating a docker-compose YAML configuration specifically designed to orchestrate multiple services related to a blockchain node environment. The template dynamically configures services such as Aerospike (a database), node instances, staking services, and log rotation, based on provided variables and runtime conditions. It defines networking, volumes, environment variables, startup commands, and dependencies to ensure proper service initialization and operation.

The primary goal of this file is to facilitate deployment and management of blockchain-related components in isolated Docker containers while allowing flexible configuration through templating.


File Structure and Functionality

Dynamic Gossip Seeds Initialization

At the beginning, the template includes logic to initialize the GOSSIP_SEEDS variable if it is not defined, but GOSSIP_INIT is set. It collects public IP addresses and gossip ports from all hosts in the block_keepers group, concatenating them as ip:port strings. This list is then used for service environment configuration related to inter-node gossip communication.


Services Section

This section defines multiple Docker services:

1. aerospike{{ NODE_ID }}

2. node{{ NODE_ID }}

3. staking{{ NODE_ID }} (Conditional)

This service is included only if DISABLE_STAKING is not set or false.

4. logrotate{{ NODE_ID }}


Networks Section


Important Implementation Details


Interaction with Other System Components


Usage Examples

Generating Compose File for a Node Instance

Assuming relevant variables are set (e.g., NODE_ID=1, AEROSPIKE_IMAGE=..., NODE_IMAGE=...), running the Jinja2 template engine will produce a docker-compose.yaml that starts:

The services will be networked on ackinacki-net and configured to communicate via environment variables and exposed ports.

Customizing Gossip Seeds

By setting GOSSIP_SEEDS or controlling GOSSIP_INIT, the generated compose file will include different seed nodes for gossip protocol discovery, affecting cluster formation.


Mermaid Diagram: Service Workflow and Relationships

flowchart TD
Aerospike["Aerospike Service"]
Node["Node Service"]
Staking["Staking Service (optional)"]
Logrotate["Logrotate Service"]
Network["ackinacki-net Network"]
Aerospike -->|depends_on| Node
Node -->|depends_on| Aerospike
Node -->|pid namespace| Staking
Node -->|log files| Logrotate
Staking -->|network| Network
Aerospike -->|network| Network
Node -->|network| Network
Logrotate -.->|isolated| Network

Summary of Key Environment Variables in Node Service

Variable

Description

EXTERNAL_STATE_SHARE_LOCAL_BASE_DIR

Directory for shared local state.

BIND, API_ADDR, MESSAGE_ROUTER

Network binding addresses for different protocols.

AEROSPIKE_SOCKET_ADDR

Aerospike connection address.

GOSSIP_SEEDS

Comma-separated list of gossip seed nodes.

NODE_ID

Unique identifier for the node instance.

NODE_ADVERTISE_ADDR, API_ADVERTISE_ADDR

Addresses advertised to other nodes/services.

OTEL_RESOURCE_ATTRIBUTES

Attributes for telemetry resource identification.

AUTH_TOKEN

Token for authenticating external messages.

EXT_MESSAGE_AUTH_REQUIRED

Boolean flag for message authorization enforcement.


Note on Included Templates

The file includes external Jinja2 fragments for additional environment variables and commands:

These files allow modular extension of the environment and command line arguments without modifying this main template.


This file plays a central role in orchestrating blockchain node infrastructure by combining templated configuration management, container orchestration, and dynamic network setup. It enables scalable, configurable, and maintainable deployments of node clusters with integrated database, staking, and logging components.