compose.j2

Overview

compose.j2 is a Jinja2 template file that defines a Docker Compose service configuration for two related services: proxy and logrotate. The file dynamically generates configuration values based on provided template variables, allowing flexible deployment setups. It primarily sets up the environment, volumes, and runtime commands for these services, managing a proxy server process with logging and certificate handling, alongside a log rotation service.

Services and Their Configurations

proxy Service

This service runs a proxy server container with the following key features:

Environment Variables Details

Certificate Generation Command

The command block executed inside the container performs:

Volumes Mounted

logrotate Service

This service manages log rotation for the proxy logs:

Implementation Details and Algorithms

Interactions with Other System Components

Usage Examples

Assuming the following variables are defined in the rendering context:

PROXY_IMAGE: "myproxy:latest"
PROXY_LOG_LEVEL: "info"
PROXY_ID: "node-01"
NODE_GROUP_ID: "groupA"
NETWORK_NAME: "prodnet"
OTEL_MY_HOST_NAME: "host01"
OTEL_COLLECTOR: "otel-collector:4317"
PROXY_SIGNING_KEYS:
  - key1.pem
  - key2.pem
PROXY_DIR: "/etc/proxy"
PROXY_CERTS_DIR: "/etc/proxy/certs"
PROXY_LOGS: "/var/log/proxy"
LOGROTATE_IMAGE: "logrotate:latest"
TEST_NAME: "proxytest"
COMMIT_HASH: "abc123"

Rendering compose.j2 with these variables will produce a Docker Compose configuration where:

Visual Diagram

flowchart TD
A[compose.j2] --> B[proxy Service]
A --> C[logrotate Service]
B --> D[Environment Variables]
B --> E[Volumes]
B --> F[Certificate Generation Command]
B --> G[Proxy Process]
E --> E1[config.yaml]
E --> E2[certs Directory]
E --> E3[logs Directory]
C --> H["Environment Variables (CRON_SCHEDULE)"]
C --> I[Volumes]
C --> J[Logrotate Script Execution]
I --> I1[logs Directory]
I --> I2[logrotate.sh Script]

This flowchart summarizes the structure of the compose.j2 file, showing the two main services and their key components such as environment variables, volumes, and commands executed.