Generate traefik labels easily
Project description
Laebelmaker
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
- Generate Traefik labels using an interactive CLI
- Generate Traefik labels using command-line options
- Generate labels from existing service definitions (e.g. Docker Compose YAML files)
- Learn how to and publish this project to PyPi
- Add combined Rule types (with logical operators)
- 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
is highly recommended. The following section will assume you installed a virtual
environment with the venv
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:
You can install the Laebelmaker project locally in Development Mode:
python3 -m pip install -e .
The project will be installed in the virtual environment but will remain editable.
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
Built Distribution
File details
Details for the file laebelmaker-0.4.1.tar.gz
.
File metadata
- Download URL: laebelmaker-0.4.1.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4fb8e1cc9331a1a87f3d55303af009d2ee2cc761daa6350f4312a43bb2345cf |
|
MD5 | 22943c3aa80b27011b4b968e8de38fe4 |
|
BLAKE2b-256 | ea945507d6b0f3dc7d0cdb8b92a8b19ca2c51ec86235599ce6690b4e0b11883d |
File details
Details for the file laebelmaker-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: laebelmaker-0.4.1-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ff72e6a65a06d04bb2ef7946e36ed829109055245f8eb5f04bb87b3a9653e85 |
|
MD5 | 2c1dfe8bdb2c60313ac334f29aa6f831 |
|
BLAKE2b-256 | 72df93aa255718d2c22706050a7648ca4e0560ff78bc1fe92049f802b11d263e |