{"id":13446690,"url":"https://github.com/Falldog/dcinja","last_synced_at":"2025-03-21T16:32:43.024Z","repository":{"id":51602048,"uuid":"322065153","full_name":"Falldog/dcinja","owner":"Falldog","description":"The smallest binary size of template engine, born for docker image","archived":false,"fork":false,"pushed_at":"2024-06-25T11:24:45.000Z","size":217,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-28T11:43:13.318Z","etag":null,"topics":["command-line-tool","configuration","docker","template","template-engine"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Falldog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-16T18:14:10.000Z","updated_at":"2024-09-22T06:22:17.000Z","dependencies_parsed_at":"2024-10-28T11:27:15.787Z","dependency_job_id":"8a157318-873c-4e16-aa88-f9e9ea0bed38","html_url":"https://github.com/Falldog/dcinja","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Falldog%2Fdcinja","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Falldog%2Fdcinja/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Falldog%2Fdcinja/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Falldog%2Fdcinja/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Falldog","download_url":"https://codeload.github.com/Falldog/dcinja/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244829609,"owners_count":20517342,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line-tool","configuration","docker","template","template-engine"],"created_at":"2024-07-31T05:00:57.072Z","updated_at":"2025-03-21T16:32:42.628Z","avatar_url":"https://github.com/Falldog.png","language":"C++","readme":"# dcinja\n\n`dcinja` is the smallest binary size template engine, designed specifically for Docker images.\n\n\u003c!-- TOC --\u003e\n* [Overview](#overview)\n* [Why dcinja?](#why-dcinja)\n* [Dependency library](#dependency-library)\n* [Binary size](#binary-size)\n* [Command line usage](#command-line-usage)\n* [Template document](#template-document)\n* [Example](#example)\n* [Real docker example](#real-docker-example)\n* [Integration from release build](#integration-from-release-build)\n* [Troubleshooting](#troubleshooting)\n\u003c!-- TOC --\u003e\n\n\n## Overview\n`dcinja` leverages the powerful inja template engine, encapsulated within a Docker command-line binary. \nIt offers a dynamic configuration generator for Docker containers, making it an excellent alternative \nto `envsubst`.\n\nUnlike `envsubst`, which has limitations in style and usage, `dcinja` provides a more robust solution \nfor generating various types of configurations. \n\n## Why dcinja?\nFor building Docker images, a smaller execution binary size is often preferable. Compiled with a C++ \ncompiler, the dcinja binary is only 500KB ~ 600KB, making it highly suitable for dynamically generating \nconfiguration files at runtime within containers.\n\n\n## Dependency library\n`dcinja` is built upon robust, well-maintained C++ libraries, ensuring stability and performance:\n* [inja](https://github.com/pantor/inja)\n* [cxxopts](https://github.com/jarro2783/cxxopts)\n* [nlohmann/json](https://github.com/nlohmann/json)\n\nAll dependencies are statically linked into the dcinja binary, meaning you do not need to install \nany of these libraries separately. This makes dcinja easy to use and integrate into your Docker images \nwithout additional setup.\n\n## Binary size\narch | os      | dcinja size  | embedded libstdc++ \n-----|:--------|:------------:|--------------------\nlinux-amd64 | Ubuntu 16+, Debian stretch+ | 591KB | Y\nalpine | alpine 3.9+ | 586KB | N (libstdc++.so 1.3MB+)\n\n## Command line usage\nReference repo docker example to build `dcinja` and copy to `/bin/` as system command in docker image.\n\n\nhelp description\n```\n  dcinja [OPTION...]\n\n  -h, --help               print help\n  -w, --cwd arg            change current working dir\n  -s, --src arg            source template file path\n  -d, --dest arg           dest template file path\n  -e, --defines arg        define environment parameters, read system env when not assigned value, ex: `-e NAME=FOO -e NUM=1 -e MY_ENV`\n      --force-system-envs  force to use system envs as final value\n  -j, --json arg           define json content, ex: `-j {\"NAME\": \"FOO\"} -j {\"PHONE\": \"123\"}`\n  -f, --json-file arg      load json content from file, ex: `-f p1.json -f p2.json`\n  -v, --verbose            verbose mode\n```\n\n## Template document\n[inja - document tutorial](https://github.com/pantor/inja#tutorial), It's compatible with [Jinja2](https://palletsprojects.com/p/jinja/).\n\n* variables `{{ ... }}`\n* statements `{% ... %}`\n    * for loop `{% for key in data %} ... {% endfor %}`\n    * condition `{% if value \u003e= 1 %} ... {% else if value \u003e= 0 %} ... {% endif %}`\n    * include `{% include \"xxx.template\" %}`\n    * assignment  `{% set name=\"test\" %}`\n* functions\n    * upper `{{ upper(\"name\") }}`\n    * length `{{ length(data_list) }}`\n    * ...\n* comments  `{# ... #}`\n\n\n## Example\ninput template from STDIN, output template to STDOUT\n```\n$ echo \"TEST Name: {{ name }}\" | dcinja -j '{\"name\": \"Foo\"}'\n\u003e\u003e\u003e TEST Name: Foo\n```\n\ninput template from file, output template to file\n```\n$ dcinja -j '{\"name\": \"Foo\"}' -s input.template -d output.template\n```\n\ninput json from file\n```\n$ dcinja -f param.json -s input.template -d output.template\n```\n\ndefine env from command line or system env\n```\n$ dcinja -e name=Foo -s input.template -d output.template\nor\n$ export name=Foo\n$ dcinja -e name -s input.template -d output.template\n```\n\nparameter context priority:\n`-e` \u003e\u003e `-j` \u003e\u003e `-f`\n1. `-f`: json file\n2. `-j`: json content defiend in command line\n3. `-e`: environment parameter defeind in command line or system\n4. `--force-system-envs`: force to use system envs as final value\n```\n$ cat name.json\n\u003e\u003e\u003e {\"name\": \"P1\"}\n$ echo \"Name: {{ name }}\" | dcinja -f name.json\n\u003e\u003e\u003e Name: P1\n$ echo \"Name: {{ name }}\" | dcinja -j '{\"name\": \"P2\"}' -e name=P3 -f name.json\n\u003e\u003e\u003e Name: P3\n```\n\n## Real docker example\n* nginx, dynamic generate nginx.conf and index.html by entrypoint. [Example Link](example/nginx__dynamic__entrypoint/README.md).\n* nginx, dynamic generate nginx.conf and header in Dockerfile. [Example Link](example/nginx__dynamic__in_docker/README.md).\n* nginx, generate nginx.conf and header in Dockerfile at build time. [Example Link](example/nginx__static__in_docker/README.md).\n\n\n## Integration from release build\nDockerfile example, download `dcinja` into docker image /bin/ as command. Copy the `dcinja` executable file via \ndocker `COPY --from` command.\n\n**ubuntu**\n\n```\nFROM ubuntu:latest\nCOPY --from=falldog/dcinja:latest /app/dcinja /bin\n\n# testing, check dcinja working normal\nRUN dcinja -h \\\n        \u0026\u0026 echo \"Normal: {{ name }}\" | dcinja -j '{\"name\": \"TEST\"}'\n# ...\n```\n\n**alpine**\n\nNeed to install `libstdc++` package.\n\n```\nFROM alpine:latest\nRUN apk --no-cache add libstdc++\nCOPY --from=falldog/dcinja:latest-alpine /app/dcinja /bin\n\n# testing, check dcinja working normal\nRUN dcinja -h \\\n        \u0026\u0026 echo \"Normal: {{ name }}\" | dcinja -j '{\"name\": \"TEST\"}'\n# ...\n```\n\n## Troubleshooting\nThe binary size build by c++ compiler, it's platform sensitive, the minimum c++ compiler support is C++11. It will dependent with `libstdc++.so`. \n\nldd result at ubuntu 18.04\n```\n$ ldd dcinja\n\tlinux-vdso.so.1 (0x00007ffe933a9000)\n\tlibstdc++.so.6 =\u003e /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f376bc40000)\n\tlibm.so.6 =\u003e /lib/x86_64-linux-gnu/libm.so.6 (0x00007f376b8a2000)\n\tlibgcc_s.so.1 =\u003e /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f376b68a000)\n\tlibc.so.6 =\u003e /lib/x86_64-linux-gnu/libc.so.6 (0x00007f376b299000)\n\t/lib64/ld-linux-x86-64.so.2 (0x00007f376c220000)\n```\n\nNeed to make sure your environment have the correct c++ runtime on\n* Ubuntu\n```\napt-get update\napt-get install libstdc++\n```\n(Only support ubuntu 16.04+)\n\n* Alpine\n```\napk add libstdc++\n```\n","funding_links":[],"categories":["Container Operations","C++"],"sub_categories":["User Interface"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFalldog%2Fdcinja","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFalldog%2Fdcinja","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFalldog%2Fdcinja/lists"}