Public | Automated Build

Last pushed: 10 days ago
Short Description
Jinja2 is a modern and designer-friendly templating language for Python.
Full Description

pinterb/jinja2

pinterb/jinja2 is a docker image that bundles the following:

  • jinja2: A modern and designer-friendly templating language for Python, modelled after Django’s templates.

Usage

As an example, say I want to generate some json from the following jinja2 template:

{
{%- if do_for_fun %}
    "extra_token": "{{ extra_token | default('dummy_value') }}",
{%- endif %}
    "datacenter": "{{ datacenter }}",
    "acl_ttl": "{{ acl_ttl }}"
}

If I run my jinja2 container to render my some.json file:

docker run -i \
    -v ${MY_TEMPLATE_DIR}:/data \
    -e TEMPLATE=some.json.j2 \
    -e "PGID=$(id -g)" -e "PUID=$(id -u)" \
    pinterb/jinja2:0.0.16 datacenter='msp' acl_ttl='30m' > ${PWD}/some.json

The rendered output would be:

{
    "datacenter": "msp",
    "acl_ttl": "30m"
}

Additionally, if you want to write your rendered output to the same directory as your template, just specify the file name by setting the OUT_FILE environment variable:

docker run -i \
    -v ${MY_TEMPLATE_DIR}:/data \
    -v ${MY_OUTPUT_DIR}:/out \
    -e TEMPLATE=some.json.j2 \
    -e OUT_FILE=/out/some.json \
    -e "PGID=$(id -g)" -e "PUID=$(id -u)" \
    pinterb/jinja2:0.0.16 datacenter='msp' acl_ttl='30m'

The key things to remember are:

  • Mount the directory containing your template(s) to the container's /data directory
  • Set the container's environment variable TEMPLATE to the name of your template file
  • The template values are passed in as space delimited name=value pairs
  • Loaded extensions: jinja2.ext.autoescape, jinja2.ext.do, jinja2.ext.loopcontrols, jinja2.ext.with_
  • autoescape is set to True
  • YMMV!!!

Misc. Info

  • Latest version: 0.0.16
  • Built on: 2016-11-28T15:42:49Z
  • Base image: pinterb/base:alpine (dockerfile)
  • Dockerfile
Docker Pull Command
Owner
pinterb
Source Repository

Comments (0)