|
| 1 | +# Docker |
| 2 | + |
| 3 | +The official jinja2-cli Docker image is available at `ghcr.io/mattrobenolt/jinja2-cli`. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +Pull the latest image: |
| 8 | + |
| 9 | +```bash |
| 10 | +docker pull ghcr.io/mattrobenolt/jinja2-cli:latest |
| 11 | +``` |
| 12 | + |
| 13 | +Or use a specific version: |
| 14 | + |
| 15 | +```bash |
| 16 | +docker pull ghcr.io/mattrobenolt/jinja2-cli:1.0.0 |
| 17 | +``` |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +### Basic Example |
| 22 | + |
| 23 | +Mount your template and data files, then pass them as arguments: |
| 24 | + |
| 25 | +```bash |
| 26 | +docker run --rm \ |
| 27 | + -v $PWD:/workspace \ |
| 28 | + ghcr.io/mattrobenolt/jinja2-cli:latest \ |
| 29 | + /workspace/template.j2 /workspace/data.json |
| 30 | +``` |
| 31 | + |
| 32 | +### Using stdin |
| 33 | + |
| 34 | +Pipe a template via stdin using stream mode: |
| 35 | + |
| 36 | +```bash |
| 37 | +echo 'Hello {{ name }}!' | docker run --rm -i \ |
| 38 | + ghcr.io/mattrobenolt/jinja2-cli:latest \ |
| 39 | + -S -D name=World |
| 40 | +``` |
| 41 | + |
| 42 | +### With environment variables |
| 43 | + |
| 44 | +Pass environment variables and access them in templates: |
| 45 | + |
| 46 | +```bash |
| 47 | +docker run --rm \ |
| 48 | + -v $PWD:/workspace \ |
| 49 | + -e DATABASE=mysql \ |
| 50 | + -e VERSION=1.0 \ |
| 51 | + ghcr.io/mattrobenolt/jinja2-cli:latest \ |
| 52 | + /workspace/config.j2 |
| 53 | +``` |
| 54 | + |
| 55 | +Template: |
| 56 | +```jinja2 |
| 57 | +database: {{ environ('DATABASE') }} |
| 58 | +version: {{ environ('VERSION') }} |
| 59 | +``` |
| 60 | + |
| 61 | +### Output to file |
| 62 | + |
| 63 | +Redirect output to a file on the host: |
| 64 | + |
| 65 | +```bash |
| 66 | +docker run --rm \ |
| 67 | + -v $PWD:/workspace \ |
| 68 | + ghcr.io/mattrobenolt/jinja2-cli:latest \ |
| 69 | + /workspace/template.j2 /workspace/data.yaml --format yaml \ |
| 70 | + > output.txt |
| 71 | +``` |
| 72 | + |
| 73 | +Or use the `-o` flag to write inside the container's filesystem: |
| 74 | + |
| 75 | +```bash |
| 76 | +docker run --rm \ |
| 77 | + -v $PWD:/workspace \ |
| 78 | + ghcr.io/mattrobenolt/jinja2-cli:latest \ |
| 79 | + /workspace/template.j2 /workspace/data.json \ |
| 80 | + -o /workspace/output.txt |
| 81 | +``` |
| 82 | + |
| 83 | +### Multiple data files |
| 84 | + |
| 85 | +Mount multiple data files and they'll be deep merged: |
| 86 | + |
| 87 | +```bash |
| 88 | +docker run --rm \ |
| 89 | + -v $PWD:/workspace \ |
| 90 | + ghcr.io/mattrobenolt/jinja2-cli:latest \ |
| 91 | + /workspace/template.j2 \ |
| 92 | + /workspace/base.json \ |
| 93 | + /workspace/override.yaml \ |
| 94 | + /workspace/production.json |
| 95 | +``` |
| 96 | + |
| 97 | +## Image Details |
| 98 | + |
| 99 | +- **Base**: Chainguard Wolfi (minimal, secure) |
| 100 | +- **Architectures**: `linux/amd64`, `linux/arm64` |
| 101 | +- **User**: Runs as non-root user |
| 102 | +- **Size**: ~90MB |
| 103 | +- **Includes**: All optional dependencies (yaml, toml, xml, hjson, json5) |
| 104 | + |
| 105 | +## Available Tags |
| 106 | + |
| 107 | +- `latest` - Latest stable release |
| 108 | +- `main` - Latest commit on main branch (development) |
| 109 | +- `1`, `1.0`, `1.0.0` - Semantic versioning tags |
| 110 | + |
| 111 | +## CI/CD Usage |
| 112 | + |
| 113 | +The image is useful in CI/CD pipelines for generating configuration files: |
| 114 | + |
| 115 | +### GitHub Actions |
| 116 | + |
| 117 | +```yaml |
| 118 | +- name: Generate config |
| 119 | + run: | |
| 120 | + docker run --rm \ |
| 121 | + -v ${{ github.workspace }}:/workspace \ |
| 122 | + ghcr.io/mattrobenolt/jinja2-cli:latest \ |
| 123 | + /workspace/config.j2 /workspace/vars.json \ |
| 124 | + -o /workspace/config.yml |
| 125 | +``` |
| 126 | +
|
| 127 | +### GitLab CI |
| 128 | +
|
| 129 | +```yaml |
| 130 | +generate-config: |
| 131 | + image: ghcr.io/mattrobenolt/jinja2-cli:latest |
| 132 | + script: |
| 133 | + - jinja2 template.j2 data.json -o config.yml |
| 134 | + artifacts: |
| 135 | + paths: |
| 136 | + - config.yml |
| 137 | +``` |
| 138 | +
|
| 139 | +## Tips |
| 140 | +
|
| 141 | +1. **Mount volumes** at `/workspace` or any path you prefer |
| 142 | +2. **Use absolute paths** for template and data files (e.g., `/workspace/file.j2`) |
| 143 | +3. **Stream mode** (`-S`) works great for piping templates via stdin |
| 144 | +4. **Environment variables** are accessible via `environ()` function in templates |
| 145 | +5. The image includes all optional format dependencies pre-installed |
0 commit comments