{"id":26275681,"url":"https://github.com/bossm8/dockerfile-templater","last_synced_at":"2025-10-24T01:35:49.849Z","repository":{"id":175263715,"uuid":"653577943","full_name":"bossm8/dockerfile-templater","owner":"bossm8","description":"GO utility to generate Dockerfiles in different variants from yml data","archived":false,"fork":false,"pushed_at":"2025-03-17T17:20:05.000Z","size":5569,"stargazers_count":17,"open_issues_count":1,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T01:31:45.577Z","etag":null,"topics":["docker","docker-template","dockerfile","dockerfile-generator","dockerfile-templating","go-template","template"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bossm8.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":"2023-06-14T10:15:16.000Z","updated_at":"2025-03-18T15:22:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"8a410797-369d-410d-b03a-c5b5e6086f5f","html_url":"https://github.com/bossm8/dockerfile-templater","commit_stats":null,"previous_names":["bossm8/dockerfile-templater"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bossm8%2Fdockerfile-templater","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bossm8%2Fdockerfile-templater/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bossm8%2Fdockerfile-templater/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bossm8%2Fdockerfile-templater/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bossm8","download_url":"https://codeload.github.com/bossm8/dockerfile-templater/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252720259,"owners_count":21793737,"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":["docker","docker-template","dockerfile","dockerfile-generator","dockerfile-templating","go-template","template"],"created_at":"2025-03-14T10:17:30.207Z","updated_at":"2025-10-24T01:35:49.778Z","avatar_url":"https://github.com/bossm8.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dockerfile Templater\n\nSimple GO utility to generate Dockerfiles from a template accepting yml data.\n\n## Introduction\n\nThis utility helps deduplicating code by generating multiple Dockerfiles \nfrom a single template. Making multi-variant image builds easier and faster.\n\nThe templater is able to generate Dockerfiles in different variants from a \n[go templated](https://pkg.go.dev/text/template) Dockerfile (the templater includes\n[sprig](https://github.com/Masterminds/sprig) to provide more template\nfunctionality). The data passed to the template is read from a yml configuration\nfile ([variants](#variants-yml)). To make things more dynamic, the variants file\ncan itself be a template and accept data from an additional yml file ([variants\nconfiguration](#variants-yml-config)).  Read below to get more information about\neach file and their required format.\n\n## Usage\n\n### Template Functions\n\nThe templater includes [sprig](https://github.com/Masterminds/sprig) (which is also\nincluded in [helm](https://helm.sh/docs/chart_template_guide/functions_and_pipelines/))\nto extend the limited set of [go template functions](https://pkg.go.dev/text/template#hdr-Functions).\n\nAdditionally it also brings the following custom functions:\n\n- `toYaml`\n    Paste yaml structures into templates:\n    ```yaml\n    values: {{ toYaml .data | nindent 2 }}\n    ```\n\n### Variants YML\n\nFlag: `--variants.def`\n\nThe main template configuration which will ultimately be passed to the Dockerfile\ntemplate.\n\nIt **must** contain the following structure:\n\n```yaml\nvariants:\n    - name: \u003cunique variant name\u003e\n      image:\n        name: \u003cname which you will use for the image\u003e\n        tag: \u003ctag which you will use for the image\u003e\n      \u003ccustom content free of constraints\u003e\n```\n\n#### Plain\n\nIf you do not provide an additional variants configuration file (`--variants.cfg`)\nthe variants file (`--variants.def`) is expected to be a valid yml file. There will\nbe no processing and the data read from the file is directly passed to the\nDockerfile template.\n\n#### Templated\n\nAs mentioned, the variants can itself be templated, this enables a high\nflexibility such as different combinations of package versions and reduces\nconfiguration duplications.  When the flag `--variants.cfg` is supplied, this\nfile will be interpreted as a template itself and be processed with the contents\nof the variants configuration before it will be fed into the Dockerfile\ntemplate.\n\n### Variants YML Config\n\nFlag: `--variants.cfg`\n\nSupplying this file is optional but may help reducing configuration and duplication\nin the variants itself. This file has no constraints on it's content except that\nit must be a valid yml file.\n\n### Dockerfile\n\nFlag: `--dockerfile.tpl`\n\nThe templated Dockerfile which accepts the configuration of the variants yml. It\nmust be a valid go template.\n\n#### Template Directory\n\nFlag: `--dockerfile.tpldir`\n\nAn optional directory which contains\n[includable templates](https://pkg.go.dev/text/template#hdr-Associated_templates) for your\ntemplated Dockerfile. Files in this directory which end in `.tpl` can then be\nincluded in your main Dockerfile template (or in the includes itself).\nThis flag can be used multiple times to include multiple directories.\n\n#### Additional Variables / Variable Overrides\n\nFlag: `--dockerfile.var`\n\nAdditional variables or variable overrides to apply before rendering a Dockerfile.\nThere are three different cases which may occur:\n\n1. Override a variable on a single variant only. In this case the variable needs to be prefixed with the variants.name.\n\n    `--dockerfile.var \u003cVARIANT_NAME\u003e:\u003cKEY_PATH\u003e=value`\n2. Override a variable on all variants. Here the variant name must be omitted.\n    \n    `--dockerfile.var \u003cKEY_PATH\u003e=value`\n3. Add a new variable. The same rules as mentioned above apply.\n\nExamples:\n\n- Override the image tag of a variant named xy:\n\n    `--dockerfile.var xy:image.tag=latest`\n- Override the image name for all variants:\n\n    `--dockerfile.var image.name=myimage`\n- Add new elements with env:\n\n    `DTPL_DOCKERFILE_VAR='{\"dev.debug\": true, \"dev.verbose\": true}' dockerfile-templater (...)`\n\nNotes:\n - You may add new hierarchy elements, they will be created on the fly\n - Existing key: value elements cannot be converted into a hierarchy\n\n### Output\n\nFlag: `--out.dir`\n\nThe generated Dockerfiles are written to the specified directory when rendered.\n\n### Output Name Format\n\nFlag: `--out.fmt`\n\nDockerfiles are written with the specified naming scheme to the output directory.\nThe format takes a go template string that can contain variables defined in the variants.\n\nThe default format (`Dockerfile.{{ .image.name }}.{{ .image.tag }}`) allows you to \nbuild the images like this for example (assuming no dots in the name/tag):\n\n```bash\nfor DF in $(find dockerfiles -type f); do\n    NAME=$(echo ${DF} | awk -F '.' '{print $2}')\n    TAG=$(echo ${DF} | awk -F '.' '{print $3}')\n    docker build . -f ${DF} -t ${NAME}:${TAG}\ndone\n```\n\n### Verbosity\n\nThere are two additional flags which control the verbosity of the templater:\n\n- `--verbose`: Print debug messages\n- `--debug`: Debug the handled yml structures, this may help debugging the\n            yml syntax, especially if the variants file is a template itself.\n            This flag must be used in conjunction with `--verbose`.\n\n### Configuration File / Environment\n\nAs an alternative to commandline flags you may also provide the relevant flags\nwith either a configuration file (`--config`) or environment variables prefixed\nwith `DTPL` and dots replaced with underscores.\n\nExample for `--dockerfile.tpldir`:\n\nCLI usage:\n```bash\n(..) --dockerfile.tpldir some/dir --dockerfile.tpldir other/dir\n```\n\nConfiguration file:\n```yml\ndockerfile:\n    tpldir:\n        - some/dir\n        - other/dir\n```\n\nEnvironment variable:\n```bash\nexport DTPL_DOCKERFILE_TPLDIR=\"some/dir other/dir\"\n```\n\nNotes: \n - For the flag `dockerfile.var` the environment variable must be specified as json:\n    \n    `DTPL_DOCKERFILE_VAR='{\"key1\": \"value1\"}'`\n\n### Docker\n\nThere are currently two flavours of the dockerized templater, `latest` and\n`debug`.  Similar to the containers from\n[kaniko](https://github.com/GoogleContainerTools/kaniko), the `debug` variant is\nbased on a busybox image and can thus be used with an interactive shell.\n\n#### Latest\n\nThis image is built from scratch and contains the templater only. \nExample usage:\n\n```bash\ndocker run -it --rm \\\n           --user $(id -u):$(id -g) \\\n           -v ${PWD}:${PWD} -w ${PWD} \\\n       ghcr.io/bossm8/dockerfile-templater:latest \\\n           --dockerfile.tpl Dockerfile.tpl \\\n           --variants.def variants.yml \\\n           --variants.cfg variants.cfg.yml\n```\n\n#### Debug\n\nThe debug image can be used to generate Dockerfiles in pipelines for example.\nBelow is an example GitLab CI/CD pipeline configuration:\n\n```yaml\nstages:\n    - pre-build\n    - build\n\ngenerate-dockerfiles:\n    stage: pre-build\n    image: \n        name: ghcr.io/bossm8/dockerfile-templater:debug\n        entrypoint: [\"\"]\n    script:\n        - templater\n            --dockerfile.tpl Dockerfile.tpl\n            --variants.def variants.yml\n            --variants.cfg variants.cfg.yml\n            --out.dir ${CI_PROJECT_DIR}/dockerfiles\n    artifacts:\n        paths:\n            - dockerfiles\n\nbuild-images:\n    stage: build\n    image: \n        name: gcr.io/kaniko-project/executor:debug\n        entrypoint: [\"\"]\n    script:\n        - |\n            for DF in $(find dockerfiles -type f); do\n                NAME=$(echo ${DF} | awk -F '.' '{print $2}')\n                TAG=$(echo ${DF} | awk -F '.' '{print $3}')\n                /kaniko/executor \\\n                    --cleanup \\\n                    --dockerfile ${DF} \\\n                    --destination ${NAME}:${TAG}\n            done\n    needs:\n        - job: generate-dockerfiles\n          artifacts: true\n```\n\n### Binary\n\nFind binaries for your OS in the [releases](https://github.com/bossm8/dockerfile-templater/releases).\n\n## Examples\n\nThe `examples` directory, as well as the `pkg/docker` (which is used to build\nthe templater image with github workflows) contain some basic example files which\ncan be used with the templater.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbossm8%2Fdockerfile-templater","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbossm8%2Fdockerfile-templater","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbossm8%2Fdockerfile-templater/lists"}