jinja-compose-wrapper


Namejinja-compose-wrapper JSON
Version 0.0.4 PyPI version JSON
download
home_pagehttps://github.com/Sid220/jinja-compose
SummaryDocker compose to the next level with Jinja2 templating
upload_time2023-09-25 22:44:53
maintainer
docs_urlNone
authorSidney Trzepacz
requires_python
licenseMIT
keywords python docker compose jinja2 template templating
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Jinja Compose
![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/sid220/jinja-compose/pytest.yml?logo=github&label=Tests&link=https%3A%2F%2Fgithub.com%2FSid220%2Fjinja-compose%2Factions%2Fworkflows%2Fpytest.yml) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/jinja-compose-wrapper) ![PyPI - Status](https://img.shields.io/pypi/status/jinja-compose-wrapper?logo=pypi&label=PyPI%20Status) ![PyPI - License](https://img.shields.io/pypi/l/jinja-compose-wrapper) ![PyPI - Version](https://img.shields.io/pypi/v/jinja-compose-wrapper?label=PyPI%20Version&logo=pypi) ![PyPI - Format](https://img.shields.io/pypi/format/jinja-compose-wrapper?logo=pypi&label=PyPI%20Format)

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

## Installation
```bash
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.
```yaml
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`.
```python
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:
```bash
jinja_compose up
```
Or just build the yaml file:
```bash
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
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Sid220/jinja-compose",
    "name": "jinja-compose-wrapper",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,docker,compose,jinja2,template,templating",
    "author": "Sidney Trzepacz",
    "author_email": "<lafakeslimshady@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/56/ce/a1c6b6fb2ad1043068cf26490829e0be8bb1c801dfb69d39f359eac2f237/jinja-compose-wrapper-0.0.4.tar.gz",
    "platform": null,
    "description": "# Jinja Compose\n![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/sid220/jinja-compose/pytest.yml?logo=github&label=Tests&link=https%3A%2F%2Fgithub.com%2FSid220%2Fjinja-compose%2Factions%2Fworkflows%2Fpytest.yml) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/jinja-compose-wrapper) ![PyPI - Status](https://img.shields.io/pypi/status/jinja-compose-wrapper?logo=pypi&label=PyPI%20Status) ![PyPI - License](https://img.shields.io/pypi/l/jinja-compose-wrapper) ![PyPI - Version](https://img.shields.io/pypi/v/jinja-compose-wrapper?label=PyPI%20Version&logo=pypi) ![PyPI - Format](https://img.shields.io/pypi/format/jinja-compose-wrapper?logo=pypi&label=PyPI%20Format)\n\n`jinja-compose` is a tool for running docker-compose commands with Jinja2 templating.\n\n## Installation\n```bash\npip install jinja-compose-wrapper\n```\nThen ensure your Python bin directory is in your PATH.\n\n## Usage\nJinja Compose operates using the same syntax as docker-compose, but with the addition of a template and optional injection file.\nThe typical project setup looks like this:\n```\n/project_dir\n\u251c\u2500\u2500 compose.jyml\n\u251c\u2500\u2500 compose.py\n\u2514\u2500\u2500 compose.yaml  [generated by jinja-compose]\n```\nWhere `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.\n\n### Example\nIn `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.\n```yaml\nservices:\n  server:\n    build:\n      context: .\n    image: sid220/apriltag_localisation:latest\n    environment:\n      - DAPRILTAG_PRODUCTION={{ MyJinjaComposeInjection.is_production }}\n      - OPENCV_VIDEOIO_DEBUG=1\n    {% if MyJinjaComposeInjection.my_static_method() == 'special_host' %}\n    ports:\n        - \"5000:5000\"\n    {% endif %}\n```\nTo define the `is_production` variable and `my_static_method` method, we create a `compose.py` file with a class that inherits from `JinjaComposeInject`.\n```python\nfrom jinja_compose_wrapper.libjinja_compose import JinjaComposeInject\nimport socket\n\nclass MyJinjaComposeInjection(JinjaComposeInject):\n    is_production = 1\n    \n    @staticmethod\n    def my_static_method():\n        return socket.gethostname()\n```\nOnce done we can now bring this service up:\n```bash\njinja_compose up\n```\nOr just build the yaml file:\n```bash\njinja_compose -d echo\n```\n## Full Usage Documentation\n```\njinja_compose [-h] [--template TEMPLATE] [--output OUTPUT] [--injection-file INJECTION_FILE] [--dockercmd [DOCKERCMD]] [--as-root] [action ...]\n\npositional arguments:\n  action\n\noptions:\n  -h, --help            show this help message and exit\n  --template TEMPLATE, -i TEMPLATE, -t TEMPLATE\n  --output OUTPUT, -o OUTPUT\n  --injection-file INJECTION_FILE, -p INJECTION_FILE\n  --dockercmd [DOCKERCMD], -d [DOCKERCMD]\n  --as-root, -r\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Docker compose to the next level with Jinja2 templating",
    "version": "0.0.4",
    "project_urls": {
        "Homepage": "https://github.com/Sid220/jinja-compose"
    },
    "split_keywords": [
        "python",
        "docker",
        "compose",
        "jinja2",
        "template",
        "templating"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "386d699ad2b2d9e1467a2f741d35899ffd36130cc5207efbbc35c5c1d86c7dd9",
                "md5": "e34b5c9d2b732f68a00cdc101da850a1",
                "sha256": "727de85f0146c0512d3f3816473a3cda4b3e57ccba1120a4d96c7dd45937d0af"
            },
            "downloads": -1,
            "filename": "jinja_compose_wrapper-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e34b5c9d2b732f68a00cdc101da850a1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6897,
            "upload_time": "2023-09-25T22:44:51",
            "upload_time_iso_8601": "2023-09-25T22:44:51.952299Z",
            "url": "https://files.pythonhosted.org/packages/38/6d/699ad2b2d9e1467a2f741d35899ffd36130cc5207efbbc35c5c1d86c7dd9/jinja_compose_wrapper-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "56cea1c6b6fb2ad1043068cf26490829e0be8bb1c801dfb69d39f359eac2f237",
                "md5": "2a1a9a9fa2a29e701d96b23d50026da9",
                "sha256": "407d7f4eb7e979b45ef2ce2bd7c47cc88d796dcd592873b81425357e1de092e7"
            },
            "downloads": -1,
            "filename": "jinja-compose-wrapper-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "2a1a9a9fa2a29e701d96b23d50026da9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4733,
            "upload_time": "2023-09-25T22:44:53",
            "upload_time_iso_8601": "2023-09-25T22:44:53.673503Z",
            "url": "https://files.pythonhosted.org/packages/56/ce/a1c6b6fb2ad1043068cf26490829e0be8bb1c801dfb69d39f359eac2f237/jinja-compose-wrapper-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-25 22:44:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Sid220",
    "github_project": "jinja-compose",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "jinja-compose-wrapper"
}
        
Elapsed time: 0.16151s