Skip to main content

Enables jinja like preposessing of docker-compose files.

Project description

jinja-docker-compose

jinja-docker-compose is a simple python script that wraps docker-compose to provide Jinja2 based templating ability to docker-compose. It is based on 'jinja-commpose'.

Dependencies

jinja-docker-compose requires following dependencies to be installed on the system:

  • python3
  • python3-pip
  • Docker engine

Installing

To install the script, simply run:

$ pip install jinja-docker-compose

The script is installed in ~/.local/bin. If not in the PATH add the following to your initiation script, like .bashrc

PATH=~/.local/bin:$PATH

Using jinja-docker-compose

The jinja-docker-compose preprocess the docker-compose file to act upon for instance for loops and conditional statements. The variables used in the preprocessing resides in a dictionnay file in JSON format.

jinja-docker-compose can either just do the pre-processing or as well run docker-compose on the processed file.

Example of dictionary file:

{
  "LOGGING": "false",
  "N_GPU": 2
}

docker-compose file to preprocess:

version: "3"
services:
  {% for i in range(N_GPU) %}
  ubuntu{{i}}:
    image: ubuntu:latest
  {% endfor %}
  ubuntulog:
    image: ubuntu:latest
    {% if LOGGING == 'true' %}
    logging:
      driver: syslog
      options:
        syslog-address: "tcp://graylog.example.com:516"
    {% endif %}

After processing the file looks like this:

version: "3"
services:
  ubuntu1:
    image: ubuntu:latest
  ubuntu2:
    image: ubuntu:latest
  ubuntulog:
    image: ubuntu:latest

The default names of the files are:

File Default name
Input file to preprocess docker-compose.yml.j2
Dictionary file docker-compose.dic
Output file docker-compose.yml

The options are:

Option Description
-f Input file name
-D Dictionary file name
-o Output file name
-s Uses the SafeLoader when loading the YAML, this removes the possible exploit that the default FullLoader enables.
-G Only genereates the output file, do not run docker-compose

All options that are valid options to docker-compose can also be given to jinja-docker-composeand then passed on to docker-compose

Depending on how your system is configured, you may need to run the script with sudo (i.e. if you usually need sudo to run docker, you will need sudo).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jinja_docker_compose-1.0.3.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jinja_docker_compose-1.0.3-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file jinja_docker_compose-1.0.3.tar.gz.

File metadata

  • Download URL: jinja_docker_compose-1.0.3.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.8.10 Linux/5.4.0-131-generic

File hashes

Hashes for jinja_docker_compose-1.0.3.tar.gz
Algorithm Hash digest
SHA256 15f8e69a1a9aa582b858a2e93e9424b5cd8470be4b44e90dad83e7df6754f8fe
MD5 aa32e3bebec7103e406e0bd5eea43c8a
BLAKE2b-256 5e566efa33197d7fbdee6a5d3462124bf732c0d4cefb076f6e204e0625576fd2

See more details on using hashes here.

File details

Details for the file jinja_docker_compose-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: jinja_docker_compose-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.8.10 Linux/5.4.0-131-generic

File hashes

Hashes for jinja_docker_compose-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0d28d9272b9f8674e20c201e6c106cbd02defddf6de2833e7857332db4d8a282
MD5 373f336c0f1a2b5d0fdfd8378ee0c015
BLAKE2b-256 06316cf2bfab289a5d0945c1f2313b77bd8181a0b853c60ae7a183892cd607e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page