Skip to content

Commit

Permalink
improve codacy badge (#21)
Browse files Browse the repository at this point in the history
* fixed codacy issues and added code climate badge
  • Loading branch information
dinuta authored Sep 5, 2020
1 parent b187d96 commit c144242
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ ENV TEMPLATES_DIR /templates
COPY entities/render.py $SCRIPTS_DIR/entities/render.py

RUN chmod +x $SCRIPTS_DIR/entities/render.py
RUN pip3 install jinja2-cli[yaml,toml,xml]
RUN pip3 install jinja2-cli[yaml,toml,xml]==0.7.0

ENTRYPOINT ["jinja2"]
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@
[![Build Status](https://travis-ci.org/dinuta/jinja2docker.svg?branch=master)](https://travis-ci.org/dinuta/jinja2docker)
[![Coverage Status](https://coveralls.io/repos/github/dinuta/jinja2docker/badge.svg?branch=master)](https://coveralls.io/github/dinuta/jinja2docker?branch=master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a9754bb39c4145c3818920509bc70a3e)](https://www.codacy.com/manual/dinuta/jinja2docker?utm_source=github.com&utm_medium=referral&utm_content=dinuta/jinja2docker&utm_campaign=Badge_Grade)
[![Maintainability](https://api.codeclimate.com/v1/badges/71ec25f732f6c9a753ce/maintainability)](https://codeclimate.com/github/dinuta/jinja2docker/maintainability)

## Docker Hub
https://hub.docker.com/r/dinutac/jinja2docker
[Docker Hub Image](https://hub.docker.com/r/dinutac/jinja2docker)

![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/dinutac/jinja2docker/2.1.6) ![MicroBadger Layers (tag)](https://img.shields.io/microbadger/layers/dinutac/jinja2docker/2.1.6) ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/dinutac/jinja2docker/2.1.6) ![](https://img.shields.io/docker/pulls/dinutac/jinja2docker.svg)

Steps:
* Mount the directory containing your template(s) to the container's **/templates** directory
* Mount the directory containing your variables file(s) directory **/variables**
* Pass needed env vars (any number)
* In your jinja2 template get OS environment variables plus your inserted environment vars with ```environ('your_env_var')```
* Mount the directory containing your template(s) to the container's **/templates** directory
* Mount the directory containing your variables file(s) directory **/variables**
* Pass needed env vars (any number)
* In your jinja2 template get OS environment variables plus your inserted environment vars with ```environ('your_env_var')```

## Supported formats (default)
Check [jinja2-cli](https://github.com/mattrobenolt/jinja2-cli) commands for all supported formats.

## Jinja2docker in action on katacoda
https://katacoda.com/dinuta/scenarios/jinja2docker
## Docker image in action on katacoda
[Katacoda scenario](https://katacoda.com/dinuta/scenarios/jinja2docker)

## Syntax

Expand Down Expand Up @@ -77,8 +79,8 @@ Path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
## Embedded custom render

If you want to use the custom embedded render you must override the entrypoint with ```/scripts/entities/render.py```. It supports:
- yaml
- json
* yaml
* json

Example:
```bash
Expand All @@ -91,6 +93,6 @@ dinutac/jinja2docker:latest json.j2 /variables/json.json
## Write your own custom render
If you want to write your own custom jinja2 render:

- Override the ```render.py``` file (you must use this file name) in **/scripts/entities/render.py** in order to execute your own logic.
- Verify the Dockerfile and add the needed python packages (requirements.txt).
* Override the ```render.py``` file (you must use this file name) in **/scripts/entities/render.py** in order to execute your own logic.
* Verify the Dockerfile and add the needed python packages (requirements.txt).

2 changes: 1 addition & 1 deletion entities/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, template_name=None, variables_path=None):
autoescape=True,
trim_blocks=True)

def yaml_filter(self, value):
def yaml_filter(value):
return yaml.dump(value, Dumper=yaml.RoundTripDumper, indent=4)

def rend_template(self):
Expand Down
14 changes: 9 additions & 5 deletions tests/render_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,26 @@ class RenderTestCase(unittest.TestCase):
def test_json(self):
template_name = "json.j2"
variables_path = "./inputs/variables/json.json"
r = Render(template_name=template_name, variables_path=variables_path)
render = Render(template_name=template_name, variables_path=variables_path)

rendered_data, data = RenderTestCase.get_data_and_rendered_data(render)

rendered_data = yaml.safe_load(r.rend_template())
with open(r.variables_path, closefd=True) as f:
data = yaml.safe_load(f)
self.assertEqual(rendered_data, data)

def test_yml(self):
template_name = "yml.j2"
variables_path = "./inputs/variables/yml.yml"
r = Render(template_name=template_name, variables_path=variables_path)

rendered_data, data = RenderTestCase.get_data_and_rendered_data(r)

self.assertEqual(rendered_data, data)

def get_data_and_rendered_data(r):
rendered_data = yaml.safe_load(r.rend_template())
with open(r.variables_path, closefd=True) as f:
data = yaml.safe_load(f)
self.assertEqual(rendered_data, data)
return rendered_data, data

def test_main_no_parameters(self):
try:
Expand Down

0 comments on commit c144242

Please sign in to comment.