Skip to main content

Jinja Compose

GitHub Workflow Status (with event) PyPI - Python Version PyPI - Status PyPI - License PyPI - Version PyPI - Format

jinja-compose is a tool for running docker-compose commands with Jinja2 templating.

Installation

pip install jinja-compose-wrapper

Then ensure your Python bin directory is in your PATH.

Usage

Jinja Compose operates using the same syntax as docker-compose, but with the addition of a template and optional injection file. The typical project setup looks like this:

/project_dir
├── compose.jyml
├── compose.py
└── compose.yaml  [generated by jinja-compose]

Where compose.jyml is a Jinja2 template file, compose.py is an optional Python file containing variables to be injected into the template, and compose.yaml is the generated docker-compose file.

Example

In compose.jyml we define a service called server, which only runs in production when the is_production variable is defined and only forwards ports on a certain host.

services:
  server:
    build:
      context: .
    image: sid220/apriltag_localisation:latest
    environment:
      - DAPRILTAG_PRODUCTION={{ MyJinjaComposeInjection.is_production }}
      - OPENCV_VIDEOIO_DEBUG=1
    {% if MyJinjaComposeInjection.my_static_method() == 'special_host' %}
    ports:
        - "5000:5000"
    {% endif %}

To define the is_production variable and my_static_method method, we create a compose.py file with a class that inherits from JinjaComposeInject.

from jinja_compose_wrapper.libjinja_compose import JinjaComposeInject
import socket

class MyJinjaComposeInjection(JinjaComposeInject):
    is_production = 1
    
    @staticmethod
    def my_static_method():
        return socket.gethostname()

Once done we can now bring this service up:

jinja_compose up

Or just build the yaml file:

jinja_compose -d echo

Full Usage Documentation

jinja_compose [-h] [--template TEMPLATE] [--output OUTPUT] [--injection-file INJECTION_FILE] [--dockercmd [DOCKERCMD]] [--as-root] [action ...]

positional arguments:
  action

options:
  -h, --help            show this help message and exit
  --template TEMPLATE, -i TEMPLATE, -t TEMPLATE
  --output OUTPUT, -o OUTPUT
  --injection-file INJECTION_FILE, -p INJECTION_FILE
  --dockercmd [DOCKERCMD], -d [DOCKERCMD]
  --as-root, -r

Metadata

Release files for jinja-compose-wrapper 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jinja-compose-wrapper 0.0.4
File Size Uploaded Provenance
jinja-compose-wrapper-0.0.4.tar.gz 4.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for jinja-compose-wrapper 0.0.4
File Interpreter ABI Platform
jinja_compose_wrapper-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 11.6 kB

Release files / jinja-compose-wrapper-0.0.4.tar.gz

Download URL jinja-compose-wrapper-0.0.4.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
407d7f4eb7e979b45ef2ce2bd7c47cc88d796dcd592873b81425357e1de092e7
BLAKE2b-256 checksum
How to use checksums
56cea1c6b6fb2ad1043068cf26490829e0be8bb1c801dfb69d39f359eac2f237
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / jinja_compose_wrapper-0.0.4-py3-none-any.whl

Download URL jinja_compose_wrapper-0.0.4-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
727de85f0146c0512d3f3816473a3cda4b3e57ccba1120a4d96c7dd45937d0af
BLAKE2b-256 checksum
How to use checksums
386d699ad2b2d9e1467a2f741d35899ffd36130cc5207efbbc35c5c1d86c7dd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Security for jinja-compose-wrapper 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page