Skip to content

Commit

Permalink
renamed templates folder (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinuta authored Jun 16, 2020
1 parent a4406d3 commit 2bc15f2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,29 @@ script:

#override entrypoint for custom render
- docker run --rm --entrypoint /scripts/entities/render.py
-v $TRAVIS_BUILD_DIR/inputs/templates:/data
-v $TRAVIS_BUILD_DIR/inputs/templates:/templates
-v $TRAVIS_BUILD_DIR/inputs/variables:/variables -e TEMPLATE=standalone.j2
-e VARIABLES=variables.yml -e DATABASE=mysql56 -e IMAGE=latest dinutac/jinja2docker:latest

#default render is jinja2-cli
- docker run --rm
-e DATABASE=mysql56 -e IMAGE=latest
-v $TRAVIS_BUILD_DIR/inputs/templates:/data
-v $TRAVIS_BUILD_DIR/inputs/templates:/templates
-v $TRAVIS_BUILD_DIR/inputs/variables:/variables
dinutac/jinja2docker:latest
/data/standalone.j2 /variables/variables.yml --format=yml
/templates/standalone.j2 /variables/variables.yml --format=yml

- docker run --rm
-v $TRAVIS_BUILD_DIR/inputs/templates:/data
-v $TRAVIS_BUILD_DIR/inputs/templates:/templates
-v $TRAVIS_BUILD_DIR/inputs/variables:/variables
dinutac/jinja2docker:latest
/data/json.j2 /variables/json.json --format=json
/templates/json.j2 /variables/json.json --format=json

- docker run --rm
-v $TRAVIS_BUILD_DIR/inputs/templates:/data
-v $TRAVIS_BUILD_DIR/inputs/templates:/templates
-v $TRAVIS_BUILD_DIR/inputs/variables:/variables
dinutac/jinja2docker:latest
/data/yml.j2 /variables/yml.yml --format=yaml
/templates/yml.j2 /variables/yml.yml --format=yaml

deploy:
- provider: script
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ RUN pip3 install pip==20.1.1 setuptools==47.1.1 --no-cache
RUN apk add --no-cache build-base sshpass

# Create folders
RUN mkdir /data/
RUN mkdir /templates/
RUN mkdir /variables/

# Expose some volumes
VOLUME ["/data"]
VOLUME ["/templates"]
VOLUME ["/variables"]

# Set needed env vars
ENV SCRIPTS_DIR /scripts
ENV TEMPLATES_DIR /data
ENV TEMPLATES_DIR /templates
ENV VARS_DIR /variables
ENV TEMPLATE docker-compose.j2
ENV VARIABLES variables.yml
Expand All @@ -28,7 +28,7 @@ COPY requirements.txt $SCRIPTS_DIR/requirements.txt
RUN chmod +x $SCRIPTS_DIR/entities/render.py
RUN chmod +x $SCRIPTS_DIR/main_flask.py

WORKDIR /data
WORKDIR /templates

RUN pip3 install -r $SCRIPTS_DIR/requirements.txt

Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ https://hub.docker.com/r/dinutac/jinja2docker
[![](https://images.microbadger.com/badges/image/dinutac/jinja2docker.svg)](https://microbadger.com/images/dinutac/jinja2docker "Get your own image badge on microbadger.com") [![](https://images.microbadger.com/badges/version/dinutac/jinja2docker.svg)](https://microbadger.com/images/dinutac/jinja2docker "Get your own version badge on microbadger.com") ![](https://img.shields.io/docker/pulls/dinutac/jinja2docker.svg)

Steps:
* Mount the directory containing your template(s) to the container's **/data** directory
* 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')```
Expand All @@ -23,27 +23,27 @@ Check [jinja2-cli](https://github.com/mattrobenolt/jinja2-cli) commands for all

```bash
docker run --rm \
-v **TEMPLATE_FOLDER**:/data \
-v **TEMPLATE_FOLDER**:/templates \
-v **VARIABLES_FOLDER**:/variables \
-e CUSTOM_ENV_VAR=**VALUE** \
dinutac/jinja2docker:latest /data/json.j2 /variables/json.json --format=json > **OUTPUT_FILE**
dinutac/jinja2docker:latest /templates/json.j2 /variables/json.json --format=json > **OUTPUT_FILE**
```

Example 1:
```bash
docker run --rm
-v $PWD\inputs\templates:/data
-v $PWD\inputs\templates:/templates
-v $PWD\inputs\variables:/variables \
-e DATABASE=mysql56 -e IMAGE=latest \
dinutac/jinja2docker:latest /data/standalone.j2 /variables/variables.yml --format=yaml > docker-compose.yml
dinutac/jinja2docker:latest /templates/standalone.j2 /variables/variables.yml --format=yaml > docker-compose.yml
```

Example 2:
```bash
docker run --rm
-v $PWD\inputs\templates:/data
-v $PWD\inputs\templates:/templates
-v $PWD\inputs\variables:/variables
dinutac/jinja2docker:latest /data/json.j2 /variables/json.json --format=json
dinutac/jinja2docker:latest /templates/json.j2 /variables/json.json --format=json
```

## Templating example
Expand Down Expand Up @@ -81,7 +81,7 @@ If you want to use the custom embedded render you must override the entrypoint w
Example:
```bash
docker run --rm --entrypoint /scripts/entities/render.py
-v $TRAVIS_BUILD_DIR/inputs/templates:/data
-v $TRAVIS_BUILD_DIR/inputs/templates:/templates
-v $TRAVIS_BUILD_DIR/inputs/variables:/variables -e TEMPLATE=standalone.j2
-e VARIABLES=variables.yml -e DATABASE=mysql56 -e IMAGE=latest dinutac/jinja2docker:latest
```
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
environment:
limit: 'sky' #example env var inserted. you can read it with environ('limit')
volumes:
- ./inputs/templates:/data
- ./inputs/templates:/templates
- ./inputs/variables:/variables
- ./:/home/dev/scripts/
ports:
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/flask_rest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_env_endpoint(self):
body = response.json()
self.assertGreaterEqual(len(body), 7)
self.assertEqual(body.get('VARS_DIR'), "/variables")
self.assertEqual(body.get('TEMPLATES_DIR'), "/data")
self.assertEqual(body.get('TEMPLATES_DIR'), "/templates")

@parameterized.expand([
("json.j2", "json.json"),
Expand Down

0 comments on commit 2bc15f2

Please sign in to comment.