start-bk.yaml

Overview

The start-bk.yaml file is an automation playbook script designed to manage the lifecycle of a Docker-based application environment, specifically related to a block keeper component. It uses Ansible's shell module to execute Docker Compose commands and Docker CLI operations, controlling the pulling of images, network creation, container orchestration, key generation, synchronization, and selective restarting of services.

This file is primarily used to:

The playbook uses conditional execution extensively based on environment variables and flags, allowing flexible orchestration depending on the deployment scenario (e.g., initial start, upgrade, or synchronization).


Playbook Tasks and Their Functions

1. Compose pull

- name: Compose pull
  ansible.builtin.shell:
    chdir: "{{ BK_DIR }}"
    cmd: docker compose pull
  when:
    - DO_START or (UPGRADE is defined and 'compose' in UPGRADE)
    - SUBNODE_ID is not defined or SUBNODE_ID == 0 or (PULL_ALL is defined and PULL_ALL)

Purpose:
Pulls the latest Docker images for the services defined in the Docker Compose file located in the BK_DIR directory.

Parameters:

Return:
Executes the shell command docker compose pull to update images.

Usage Example:
This task ensures that the latest images are available before starting or upgrading the service.


2. Create ackinacki-net manually

- name: Create ackinacki-net manually
  ansible.builtin.shell:
    cmd: docker network create ackinacki-net
  ignore_errors: true
  when:
    - CREATE_NET
    - DO_START
    - not UPGRADE is defined or not UPGRADE

Purpose:
Creates a custom Docker network named ackinacki-net. This network is presumably used for container connectivity isolated from default networks.

Parameters:

Return:
Runs docker network create ackinacki-net. Errors are ignored (for example, if the network already exists).

Usage Example:
Run when starting fresh environments that require a dedicated Docker network.


3. Compose down

- name: Compose down
  ansible.builtin.shell:
    chdir: "{{ BK_DIR }}"
    cmd: docker compose down --remove-orphans
  ignore_errors: true
  when: UPGRADE is defined and 'deep-compose' in UPGRADE

Purpose:
Stops and removes all Docker Compose services, including orphaned containers not defined in the Compose file.

Parameters:

Return:
Runs docker compose down --remove-orphans to clean up running services.

Usage Example:
Used during deep upgrade processes to fully stop existing container sets before redeployment.


4. Create BLS keys

- name: Create BLS keys
  ansible.builtin.shell:
    cmd: "docker run --rm --entrypoint /usr/local/bin/node-helper -v {{ BK_DIR }}/bk-configs:/staking {{ STAKING_IMAGE }} bls --path block_keeper{{ NODE_ID }}_bls.keys.json"
    creates: "{{ BK_DIR }}/bk-configs/block_keeper{{ NODE_ID }}_bls.keys.json"
  when: '"block_keeper" ~ NODE_ID ~ "_bls.keys.json" not in OTHER_KEYS'

Purpose:
Generates Boneh–Lynn–Shacham (BLS) cryptographic keys for the block keeper node, which are essential for node identification and cryptographic operations.

Parameters:

Return:
Runs a Docker container that executes the node-helper tool with the bls command to generate keys. The command is skipped if the key file already exists.

Usage Example:
Used to ensure each block keeper node has unique cryptographic keys before starting operations.


5. Synchronize network startup

- name: Synchronize network startup
  include_tasks: synchronized-start.yaml
  when: SYNCHRONIZED_START is defined

Purpose:
Includes another task file (synchronized-start.yaml) to synchronize the startup across multiple nodes.

Parameters:

Return:
Delegates execution to a separate task file managing coordinated startup.

Usage Example:
Used in multi-node deployments to ensure nodes start in a controlled sequence.


6. Compose up

- name: Compose up
  ansible.builtin.shell:
    chdir: "{{ BK_DIR }}"
    cmd: docker compose up -d --remove-orphans
  when: DO_START or (UPGRADE is defined and UPGRADE | length > 0)

Purpose:
Starts Docker Compose services in detached mode, removing orphaned containers.

Parameters:

Return:
Runs docker compose up -d --remove-orphans to launch containers.

Usage Example:
Starts or upgrades service containers after pulling images or performing other preparatory tasks.


7. Compose restart logrotate

- name: Compose restart logrotate
  ansible.builtin.shell:
    chdir: "{{ BK_DIR }}"
    cmd: docker compose restart "logrotate{{ NODE_ID if (NUMBERED_SERVICES | default(true)) else "" }}"
  when:
    - DO_START
    - logrotate is defined and logrotate.changed

Purpose:
Restarts the logrotate service container, optionally with a node-specific suffix, if the logrotate configuration has changed.

Parameters:

Return:
Executes docker compose restart for the logrotate container to apply changes immediately.

Usage Example:
Applies configuration changes to logging rotation without full container restart.


Important Implementation Details


Interaction with Other System Components


Mermaid Diagram: Task Flow in start-bk.yaml

flowchart TD
A[Compose pull]
B[Create ackinacki-net]
C[Compose down]
D[Create BLS keys]
E[Synchronized start]
F[Compose up]
G[Compose restart logrotate]
A --> B
B --> C
C --> D
D --> E
E --> F
F --> G
style C fill:#f9f,stroke:#333,stroke-width:2px
style E fill:#bbf,stroke:#333,stroke-width:2px

End of start-bk.yaml Documentation