docker-jinja - dj
- Forked from https://github.com/Grokzen/docker-jinja
Extend your dockerfiles with Jinja2 syntax and logic.
Create new filter and functions for Jinja with simple datasource files.
Installation
Install from pypi with pip install docker-jinja
To install in development mode, first navigate to root of project and then run pip install -r dev-requirements.txt; pip install -e .. It is recommended to install inside a virtualenv to avoid conflicts with dependencies.
Quickstart guide
Create a Dockerfile.jinja that contains all regular Dockerfile build steps and the jinja syntax. For exapmle:
$ cat Dockerfile.jinja
FROM {{ OS }}
MAINTAINER {{ MAINTAINER }}
ARG {{ ARG1 }}
Run dj command. For example:
dj --dockerfile Dockerfile.jinja --outfile Dockerfile --env OS=ubuntu:12.04 --env MAINTAINER=Grokzen --env ARG1=foobar --config test-config.json
And you will get the output:
FROM ubuntu:12.04
MAINTAINER Grokzen
ARG foobar
Configuration files
It is possible to create predefined configuration files with settings, enviroment variables and datasources.
dj tries to load the following configuration files in the following order:
- /etc/dj.yaml
- /etc/dj.json
- ~/.dj.yaml
- ~/.dj.json
- $CWD + '.dj.yaml'
- $CWD + '.dj.json'
YAML is the file format to prefer but json is also supported.
Currently it is not possible to automatically load a config file next to the source Dockerfile.
Datasources
If you want to extend the Jinja syntax with additional filters and global functions you have the datasource pattern to help you.
A datasource file is a python script that can contain any code you want so you can extend dj to be capable to perform any task you want.
You can tell dj to load a datasource file in multiple ways.
- In any config file create a key
datasourceswith a list of strings paths pointing to all files thatdjshould import. (Must be absolute path) - Point to a file with cli key -s/--datasource and
djwill load that file. (Relative paths is supported) - Add a python file to contrib folder and it will auto load during execution.
Global functions ################
A global function is a regular python function that you can call from jinja. These functions can be used to perform any usefull task you require.
To create a global function you define a method within a datasource and its name should starts with _global_ and then follow by the name you want to use in your Dockerfile.
For example if you have the following code:
def _global_foo():
return "bar"
You can call it from jinja with:
RUN echo '{{ foo() }}'
and it will render into
RUN echo 'bar'
Filter functions ################
To create a new filter function you define a method within a datasource and its name should starts with _filter_ and then follow by the name you want to use in your Dockerfile.
For example if you have the following code
def _filter_bar(arg):
return arg.upper()
You can call it from jinja with:
RUN echo '{{ "opa"|bar }}'
and it will render into
RUN echo 'OPA'
Other rendering engines
Currently only Jinja2 is supported as rendering engine
Supported python version
- 3.10
Contribute
Open an Issue on github describing the problem you have.
If you have a fix for the problem or want to add something to contrib library, open a PR with your fix. The PR must contain some test to verify that it work if it is a bugfix or new feature. All tests in all supported python environments must pass on TravisCI before a PR will be accepted.
All PR:s should have their commits squashed to a single commit.
License
See LICENSE file. (MIT)
Metadata
Release files for docker-jinja3 0.0.0.post3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| docker-jinja3-0.0.0.post3.tar.gz | 10.6 kB | Without provenance | Details for docker-jinja3-0.0.0.post3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| docker_jinja3-0.0.0.post3-py3-none-any.whl | Python 3 | none | any | Details for docker_jinja3-0.0.0.post3-py3-none-any.whl |
Total release size: 20.8 kB
Release files / docker-jinja3-0.0.0.post3.tar.gz
| Download URL | docker-jinja3-0.0.0.post3.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3ae933a5037d48db86fc1b400d0e646c755d3e8e6dfa57e4924e378d02781e08
|
|
BLAKE2b-256 checksum How to use checksums |
e9981dd2bb79b8525d99c6d5d08b5931239c2f81b57fa78cc4df00e3f485a936
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.6
|
Release files / docker_jinja3-0.0.0.post3-py3-none-any.whl
| Download URL | docker_jinja3-0.0.0.post3-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c7635e206bbd85189388f54930883f0d7d58e5f7df4163b4a737db26a9f59ea1
|
|
BLAKE2b-256 checksum How to use checksums |
bf28d57d5490d78ae165a7d682e2ddf2adcf1276673e79c08a96e61f78e0d190
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.6
|
Security for docker-jinja3 0.0.0.post3
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.