laebelmaker


Namelaebelmaker JSON
Version 0.4.1 PyPI version JSON
download
home_page
SummaryGenerate traefik labels easily
upload_time2024-03-11 10:47:56
maintainer
docs_urlNone
author
requires_python>=3.9
license
keywords traefik label generate
VCS
bugtrack_url
requirements pyyaml
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Laebelmaker

<a target="_blank" href="https://www.python.org/"><img src="https://img.shields.io/badge/Python-FFD43B?style=for-the-badge&logo=python&logoColor=blue"/></a>

<a target="_blank" href="https://choosealicense.com/licenses/mit/"><img src="https://img.shields.io/pypi/l/laebelmaker.svg?maxAge=86400&style=flat-square"/></a>
<a target="_blank" href="https://pypi.org/project/laebelmaker/"><img src="https://img.shields.io/pypi/v/laebelmaker.svg?maxAge=86400&style=flat-square"/></a>
<a target="_blank" href="https://pypi.org/project/laebelmaker/"><img src="https://img.shields.io/pypi/dm/laebelmaker?style=flat-square"/></a>
<a target="_blank" href="https://pypi.org/project/laebelmaker/"><img src="https://img.shields.io/pypi/pyversions/laebelmaker.svg?maxAge=86400&style=flat-square"/></a>
<a target="_blank" href="https://github.com/ivanbratovic/laebelmaker/actions/workflows/python-app.yml"><img src="https://img.shields.io/github/actions/workflow/status/ivanbratovic/laebelmaker/python-app.yml?style=flat-square"/></a>
<a target="_blank" href="https://github.com/ivanbratovic/laebelmaker"><img src="https://img.shields.io/github/last-commit/ivanbratovic/laebelmaker?style=flat-square" /></a>


Tool for generating Traefik labels. Written in Python.

## Installation

Laebelmaker is published on PyPI. You can use pip to install it:
```
python3 -m pip install --user laebelmaker
```

It is recommended that you also install the `docker` module. You
can install both Laebelmaker and docker as its dependency with:
```
python3 -m pip install --user laebelmaker[docker]
```
This will allow Laebelmaker to use metadata of Docker images
to prevent redundant prompts from the user, e.g. when an image
exposes a single port.

## Usage

Laebelmaker can be used to automatically generate Traefik labels
from various sources, such as `docker-compose.yml` files, running
Docker containers and user-given options.

You can always consult the help menu for all features with short
(and hopefully clear) explanations:

```
$ laebelmaker --help
usage: laebelmaker [-h] [-i] [-c NAME] [-f FORMAT] [FILE ...]

Generate Traefik labels

positional arguments:
  FILE                  Compose file to generate labels for

options:
  -h, --help            show this help message and exit
  -i, --interactive     use interactive mode
  -c NAME, --container NAME
                        generate labels for a given container on the system
  -f FORMAT, --format FORMAT
                        set output format, one of: [docker, none, yaml]
```

## Examples

### CLI Interactive Mode

```
$ laebelmaker -i
Enter value for 'deploy name': myapp
Enter value for 'url': myapp.example.com
Enter value for 'port' (integer): 25565
Enter value for 'https redirection' (yes/No): no
--START GENERATED LABELS FOR 'myapp'--
traefik.enable=true
traefik.http.routers.myapp.rule=Host(`myapp.example.com`)
traefik.http.services.myapp.loadbalancer.server.port=25565
--END GENERATED LABELS FOR 'myapp'--
```


### With Compose YAML file

Invoking laebelmaker on a Docker Compose YAML file, the program will
prompt the user for different options, with the defaults given in
parentheses. This example also modifies the output format with
`-f yaml`, which means the labels are immediately ready to be used
in a YAML file.

```
$ laebelmaker -f yaml examples/docker-compose-testapp.yml
Found multiple services.
 1. testapp
 2. testapp-db
Service number to use (default 1): 1
Enter value for 'url': testapp.example.com/api
Enter value for 'https redirection' (yes/No): yes
Enter value for 'web entrypoint': http
Enter value for 'websecure entrypoint': https
Enter value for 'tls resolver': letsencrypt
--START GENERATED LABELS FOR 'testapp'--
  - traefik.enable=true
  - traefik.http.routers.testapp.rule=(Host(`testapp.example.com`) && PathPrefix(`/api`))
  - traefik.http.routers.testapp.entrypoints=http
  - traefik.http.routers.testapp-https.rule=(Host(`testapp.example.com`) && PathPrefix(`/api`))
  - traefik.http.routers.testapp-https.entrypoints=https
  - traefik.http.routers.testapp.middlewares=testapp-redir
  - traefik.http.middlewares.testapp-redir.redirectscheme.scheme=https
  - traefik.http.routers.testapp-https.tls=true
  - traefik.http.routers.testapp-https.tls.certresolver=letsencrypt
  - traefik.http.services.testapp.loadbalancer.server.port=80
--END GENERATED LABELS FOR 'testapp'--
```

If an invalid file is given, Laebelmaker should hopefully print a
sensible error message.
```
$ laebelmaker examples/invalid-image-tag.yml
Pulling image:
 ⠿ ubuntu:latestest Failed
Invalid image tag: 'ubuntu:latestest' in 'examples/invalid-image-tag.yml'.
Failed to produce output.
Try running: laebelmaker --help
```

## To-do

* [x] Generate Traefik labels using an interactive CLI
* [x] Generate Traefik labels using command-line options
* [x] Generate labels from existing service definitions (e.g. Docker Compose YAML files)
* [x] Learn how to and publish this project to PyPi
* [x] Add combined Rule types (with logical operators)
* [x] Add automated tests
* [ ] Increase code coverage for tests
* [ ] Add support for TCP/UDP routers and services
* [ ] Remove pyyaml as a hard dependency
* [ ] Add local Traefik config as data source (e.g. for entrypoint and TLS resolver names)
* [ ] Add Dockerfile as a data source
* [ ] Add K8s YAML as a data source
* [ ] Add Docker Swarm YAML as a data source
* [ ] Add more sophisticated Rule parsing (e.g. from a given URL)

Something to think about:

* [ ] Expand out of Traefik into a more general use-case
* [ ] Compatibility for Windows machines

## Guidelines for development

* Ease of use is a priority
* Use sensible defaults without asking, when possible
* When defaults are not possible, offer the user a sensible prefilled value
* The code should be as Pythonic as possible
* Use type hints as much as possible to catch logical errors

## Local development setup

For local development, a [virtual environment](https://docs.python.org/3/tutorial/venv.html)
is highly recommended. The following section will assume you installed a virtual
environment with the [`venv`](https://docs.python.org/3/library/venv.html) module:
```
python3 -m venv venv
```

All requirements for development are given in `requirements-dev.txt`.
Install all of them before contributing. This is required for `pre-commit`.
You can use the following command to install the requirements:
```
python3 -m pip --require-virtualenv install -r requirements-dev.txt
```

Before commiting, install pre-commit hooks for Git by running:
```
pre-commit install
```

This will run the following programs to verify a commit:

* [Black](https://pypi.org/project/black) - code formatting
* [MyPy](https://mypy.readthedocs.io/en/stable/) - static type checking
* [PyTest](https://docs.pytest.org/en/7.2.x/) - unit tests
* [PyLint](https://pypi.org/project/pylint/) - code linting

You can install the Laebelmaker project locally in
[Development Mode](https://setuptools.pypa.io/en/latest/userguide/development_mode.html):
```
python3 -m pip install -e .
```
The project will be installed in the virtual environment but will remain editable.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "laebelmaker",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "traefik,label,generate",
    "author": "",
    "author_email": "Ivan Bratovi\u0107 <ivanbratovic4@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/ea/94/5507d6b0f3dc7d0cdb8b92a8b19ca2c51ec86235599ce6690b4e0b11883d/laebelmaker-0.4.1.tar.gz",
    "platform": null,
    "description": "# Laebelmaker\n\n<a target=\"_blank\" href=\"https://www.python.org/\"><img src=\"https://img.shields.io/badge/Python-FFD43B?style=for-the-badge&logo=python&logoColor=blue\"/></a>\n\n<a target=\"_blank\" href=\"https://choosealicense.com/licenses/mit/\"><img src=\"https://img.shields.io/pypi/l/laebelmaker.svg?maxAge=86400&style=flat-square\"/></a>\n<a target=\"_blank\" href=\"https://pypi.org/project/laebelmaker/\"><img src=\"https://img.shields.io/pypi/v/laebelmaker.svg?maxAge=86400&style=flat-square\"/></a>\n<a target=\"_blank\" href=\"https://pypi.org/project/laebelmaker/\"><img src=\"https://img.shields.io/pypi/dm/laebelmaker?style=flat-square\"/></a>\n<a target=\"_blank\" href=\"https://pypi.org/project/laebelmaker/\"><img src=\"https://img.shields.io/pypi/pyversions/laebelmaker.svg?maxAge=86400&style=flat-square\"/></a>\n<a target=\"_blank\" href=\"https://github.com/ivanbratovic/laebelmaker/actions/workflows/python-app.yml\"><img src=\"https://img.shields.io/github/actions/workflow/status/ivanbratovic/laebelmaker/python-app.yml?style=flat-square\"/></a>\n<a target=\"_blank\" href=\"https://github.com/ivanbratovic/laebelmaker\"><img src=\"https://img.shields.io/github/last-commit/ivanbratovic/laebelmaker?style=flat-square\" /></a>\n\n\nTool for generating Traefik labels. Written in Python.\n\n## Installation\n\nLaebelmaker is published on PyPI. You can use pip to install it:\n```\npython3 -m pip install --user laebelmaker\n```\n\nIt is recommended that you also install the `docker` module. You\ncan install both Laebelmaker and docker as its dependency with:\n```\npython3 -m pip install --user laebelmaker[docker]\n```\nThis will allow Laebelmaker to use metadata of Docker images\nto prevent redundant prompts from the user, e.g. when an image\nexposes a single port.\n\n## Usage\n\nLaebelmaker can be used to automatically generate Traefik labels\nfrom various sources, such as `docker-compose.yml` files, running\nDocker containers and user-given options.\n\nYou can always consult the help menu for all features with short\n(and hopefully clear) explanations:\n\n```\n$ laebelmaker --help\nusage: laebelmaker [-h] [-i] [-c NAME] [-f FORMAT] [FILE ...]\n\nGenerate Traefik labels\n\npositional arguments:\n  FILE                  Compose file to generate labels for\n\noptions:\n  -h, --help            show this help message and exit\n  -i, --interactive     use interactive mode\n  -c NAME, --container NAME\n                        generate labels for a given container on the system\n  -f FORMAT, --format FORMAT\n                        set output format, one of: [docker, none, yaml]\n```\n\n## Examples\n\n### CLI Interactive Mode\n\n```\n$ laebelmaker -i\nEnter value for 'deploy name': myapp\nEnter value for 'url': myapp.example.com\nEnter value for 'port' (integer): 25565\nEnter value for 'https redirection' (yes/No): no\n--START GENERATED LABELS FOR 'myapp'--\ntraefik.enable=true\ntraefik.http.routers.myapp.rule=Host(`myapp.example.com`)\ntraefik.http.services.myapp.loadbalancer.server.port=25565\n--END GENERATED LABELS FOR 'myapp'--\n```\n\n\n### With Compose YAML file\n\nInvoking laebelmaker on a Docker Compose YAML file, the program will\nprompt the user for different options, with the defaults given in\nparentheses. This example also modifies the output format with\n`-f yaml`, which means the labels are immediately ready to be used\nin a YAML file.\n\n```\n$ laebelmaker -f yaml examples/docker-compose-testapp.yml\nFound multiple services.\n 1. testapp\n 2. testapp-db\nService number to use (default 1): 1\nEnter value for 'url': testapp.example.com/api\nEnter value for 'https redirection' (yes/No): yes\nEnter value for 'web entrypoint': http\nEnter value for 'websecure entrypoint': https\nEnter value for 'tls resolver': letsencrypt\n--START GENERATED LABELS FOR 'testapp'--\n  - traefik.enable=true\n  - traefik.http.routers.testapp.rule=(Host(`testapp.example.com`) && PathPrefix(`/api`))\n  - traefik.http.routers.testapp.entrypoints=http\n  - traefik.http.routers.testapp-https.rule=(Host(`testapp.example.com`) && PathPrefix(`/api`))\n  - traefik.http.routers.testapp-https.entrypoints=https\n  - traefik.http.routers.testapp.middlewares=testapp-redir\n  - traefik.http.middlewares.testapp-redir.redirectscheme.scheme=https\n  - traefik.http.routers.testapp-https.tls=true\n  - traefik.http.routers.testapp-https.tls.certresolver=letsencrypt\n  - traefik.http.services.testapp.loadbalancer.server.port=80\n--END GENERATED LABELS FOR 'testapp'--\n```\n\nIf an invalid file is given, Laebelmaker should hopefully print a\nsensible error message.\n```\n$ laebelmaker examples/invalid-image-tag.yml\nPulling image:\n \u283f ubuntu:latestest Failed\nInvalid image tag: 'ubuntu:latestest' in 'examples/invalid-image-tag.yml'.\nFailed to produce output.\nTry running: laebelmaker --help\n```\n\n## To-do\n\n* [x] Generate Traefik labels using an interactive CLI\n* [x] Generate Traefik labels using command-line options\n* [x] Generate labels from existing service definitions (e.g. Docker Compose YAML files)\n* [x] Learn how to and publish this project to PyPi\n* [x] Add combined Rule types (with logical operators)\n* [x] Add automated tests\n* [ ] Increase code coverage for tests\n* [ ] Add support for TCP/UDP routers and services\n* [ ] Remove pyyaml as a hard dependency\n* [ ] Add local Traefik config as data source (e.g. for entrypoint and TLS resolver names)\n* [ ] Add Dockerfile as a data source\n* [ ] Add K8s YAML as a data source\n* [ ] Add Docker Swarm YAML as a data source\n* [ ] Add more sophisticated Rule parsing (e.g. from a given URL)\n\nSomething to think about:\n\n* [ ] Expand out of Traefik into a more general use-case\n* [ ] Compatibility for Windows machines\n\n## Guidelines for development\n\n* Ease of use is a priority\n* Use sensible defaults without asking, when possible\n* When defaults are not possible, offer the user a sensible prefilled value\n* The code should be as Pythonic as possible\n* Use type hints as much as possible to catch logical errors\n\n## Local development setup\n\nFor local development, a [virtual environment](https://docs.python.org/3/tutorial/venv.html)\nis highly recommended. The following section will assume you installed a virtual\nenvironment with the [`venv`](https://docs.python.org/3/library/venv.html) module:\n```\npython3 -m venv venv\n```\n\nAll requirements for development are given in `requirements-dev.txt`.\nInstall all of them before contributing. This is required for `pre-commit`.\nYou can use the following command to install the requirements:\n```\npython3 -m pip --require-virtualenv install -r requirements-dev.txt\n```\n\nBefore commiting, install pre-commit hooks for Git by running:\n```\npre-commit install\n```\n\nThis will run the following programs to verify a commit:\n\n* [Black](https://pypi.org/project/black) - code formatting\n* [MyPy](https://mypy.readthedocs.io/en/stable/) - static type checking\n* [PyTest](https://docs.pytest.org/en/7.2.x/) - unit tests\n* [PyLint](https://pypi.org/project/pylint/) - code linting\n\nYou can install the Laebelmaker project locally in\n[Development Mode](https://setuptools.pypa.io/en/latest/userguide/development_mode.html):\n```\npython3 -m pip install -e .\n```\nThe project will be installed in the virtual environment but will remain editable.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Generate traefik labels easily",
    "version": "0.4.1",
    "project_urls": {
        "Homepage": "https://github.com/ivanbratovic/laebelmaker"
    },
    "split_keywords": [
        "traefik",
        "label",
        "generate"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "72df93aa255718d2c22706050a7648ca4e0560ff78bc1fe92049f802b11d263e",
                "md5": "2c1dfe8bdb2c60313ac334f29aa6f831",
                "sha256": "4ff72e6a65a06d04bb2ef7946e36ed829109055245f8eb5f04bb87b3a9653e85"
            },
            "downloads": -1,
            "filename": "laebelmaker-0.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2c1dfe8bdb2c60313ac334f29aa6f831",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 15741,
            "upload_time": "2024-03-11T10:47:54",
            "upload_time_iso_8601": "2024-03-11T10:47:54.364328Z",
            "url": "https://files.pythonhosted.org/packages/72/df/93aa255718d2c22706050a7648ca4e0560ff78bc1fe92049f802b11d263e/laebelmaker-0.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ea945507d6b0f3dc7d0cdb8b92a8b19ca2c51ec86235599ce6690b4e0b11883d",
                "md5": "22943c3aa80b27011b4b968e8de38fe4",
                "sha256": "f4fb8e1cc9331a1a87f3d55303af009d2ee2cc761daa6350f4312a43bb2345cf"
            },
            "downloads": -1,
            "filename": "laebelmaker-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "22943c3aa80b27011b4b968e8de38fe4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 16244,
            "upload_time": "2024-03-11T10:47:56",
            "upload_time_iso_8601": "2024-03-11T10:47:56.009737Z",
            "url": "https://files.pythonhosted.org/packages/ea/94/5507d6b0f3dc7d0cdb8b92a8b19ca2c51ec86235599ce6690b4e0b11883d/laebelmaker-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-11 10:47:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ivanbratovic",
    "github_project": "laebelmaker",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "pyyaml",
            "specs": [
                [
                    "==",
                    "6.0.1"
                ]
            ]
        }
    ],
    "lcname": "laebelmaker"
}
        
Elapsed time: 0.20396s