{"id":13416475,"url":"https://github.com/ozankasikci/dockerfile-generator","last_synced_at":"2025-04-24T06:32:59.916Z","repository":{"id":41287822,"uuid":"202418110","full_name":"ozankasikci/dockerfile-generator","owner":"ozankasikci","description":"dfg - Generates dockerfiles based on various input channels. ","archived":false,"fork":false,"pushed_at":"2022-05-23T07:51:29.000Z","size":97,"stargazers_count":167,"open_issues_count":0,"forks_count":20,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-07-31T21:56:54.274Z","etag":null,"topics":["dfg","docker","dockerfile","dockerfile-generator"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ozankasikci.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-14T20:03:37.000Z","updated_at":"2024-07-22T15:26:02.000Z","dependencies_parsed_at":"2022-07-07T11:03:55.742Z","dependency_job_id":null,"html_url":"https://github.com/ozankasikci/dockerfile-generator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ozankasikci%2Fdockerfile-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ozankasikci%2Fdockerfile-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ozankasikci%2Fdockerfile-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ozankasikci%2Fdockerfile-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ozankasikci","download_url":"https://codeload.github.com/ozankasikci/dockerfile-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250579013,"owners_count":21453402,"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":["dfg","docker","dockerfile","dockerfile-generator"],"created_at":"2024-07-30T21:00:59.343Z","updated_at":"2025-04-24T06:32:59.547Z","avatar_url":"https://github.com/ozankasikci.png","language":"Go","funding_links":[],"categories":["Docker Images","DevOps Tools","Go","软件包","Software Packages","Go 工具","Building Images","Go Tools"],"sub_categories":["Dockerfile","devops 工具","DevOps Tools","代码分析","DevOps 工具"],"readme":"## dfg - Dockerfile Generator\n\n`dfg` is both a go library and an executable that produces valid Dockerfiles using various input channels.\n\n[![Build Status](https://travis-ci.org/ozankasikci/dockerfile-generator.svg?branch=master)](https://travis-ci.org/ozankasikci/dockerfile-generator)\n[![GoDoc](https://godoc.org/github.com/ozankasikci/dockerfile-generator?status.svg)](https://godoc.org/github.com/ozankasikci/dockerfile-generator)\n[![Coverage Status](https://coveralls.io/repos/github/ozankasikci/dockerfile-generator/badge.svg?branch=master)](https://coveralls.io/github/ozankasikci/dockerfile-generator?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/ozankasikci/dockerfile-generator)](https://goreportcard.com/report/github.com/ozankasikci/dockerfile-generator)\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go) \n\n## Table of Contents\n\n- [Overview](#overview)\n- [Installation](#installation)\n  * [Installing as an Executable](#installing-as-an-executable)\n  * [Installing as a Library](#installing-as-a-library)\n- [Getting Started](#getting-started)\n  * [Using dfg as an Executable](#using-dfg-as-an-executable)\n  * [Using dfg as a Library](#using-dfg-as-a-library)\n- [Examples](#examples)\n  * [YAML File Per Dockerfile Example](#single-yaml-file-per-dockerfile-example-expects-a-stages-key-on-top-level)\n  * [YAML File Target Field Example](#yaml-file-example-with-target-field-allows-using-any-field)\n  * [Library Usage Example](#library-usage-example)\n- [TODO](#todo)\n\n## Overview\n\n`dfg` is a Dockerfile generator that accepts input data from various sources, produces and redirects the generated Dockerfile to an output target such as a file or stdout.\n\nIt is especially useful for generating Dockerfile instructions conditionally since Dockerfile language has no control flow logic.\n\n## Installation\n#### Installing as an Executable\n\n* MacOS\n\n```shell\ncurl -o dfg -L https://github.com/ozankasikci/dockerfile-generator/releases/download/v1.0.0/dfg_v1.0.0_darwin_amd64\nchmod +x dfg \u0026\u0026 sudo mv dfg /usr/local/bin\n```\n\n* Linux\n\n```shell\ncurl -o dfg -L https://github.com/ozankasikci/dockerfile-generator/releases/download/v1.0.0/dfg_v1.0.0_linux_amd64\nchmod +x dfg \u0026\u0026 sudo mv dfg /usr/local/bin\n```\n\n* Windows\n\n```shell\ncurl -o dfg.exe -L https://github.com/ozankasikci/dockerfile-generator/releases/download/v1.0.0/dfg_v1.0.0_windows_amd64.exe\n```\n\n#### Installing as a Library\n\n`go get -u github.com/ozankasikci/dockerfile-generator`\n\n## Getting Started\n\n### Using dfg as an Executable\n\nAvailable commands:\n\n`dfg generate --input path/to/yaml --out Dockerfile` generates a file named `Dockerfile`\n\n`dfg generate --input path/to/yaml --target-field \".server.dockerfile\" --out Dockerfile` generates a file named `Dockerfile` reading the `.server.dockerfile` field of the YAML file.\n\n`dfg generate --help` lists available flags\n\n### Using dfg as a Library\n\nWhen using `dfg` as a go library, you need to pass a `[]dfg.Stage` slice as data.\nThis approach enables and encourages multi staged Dockerfiles.\nDockerfile instructions will be generated in the same order as in the `[]dfg.Instruction` slice.\n\nSome `Instruction`s accept a `runForm` field which specifies if the `Instruction` should be run in the `shell form` or the `exec form`.\nIf the `runForm` is not specified, it will be chosen based on [Dockerfile best practices](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/). \n\nFor detailed usage example please see [Library Usage Example](#library-usage-example)\n\n## Examples\n\n#### Single YAML File per Dockerfile Example (Expects a `stages` key on top level)\n```yaml\nstages:\n  final:\n    - from:\n        image: kstaken/apache2\n    - run:\n        runForm: shell\n        params:\n          - apt-get update \u0026\u0026\n          - apt-get install -y\n          - php5\n          - libapache2-mod-php5 \u0026\u0026\n          - apt-get clean \u0026\u0026\n          - rm -rf /var/lib/apt/lists/*\n    - cmd:\n        params:\n          - /usr/sbin/apache2\n          - -D\n          - FOREGROUND\n```\nUse dfg as binary:\n```shell\ndfg generate -i ./example-input-files/apache-php.yaml --stdout\n```\nOr as a library\n```go\ndata, err := dfg.NewDockerFileDataFromYamlFile(\"./example-input-files/apache-php.yaml\")\ntmpl := dfg.NewDockerfileTemplate(data)\nerr = tmpl.Render(output)\n```\n\n#### Output\n\n```dockerfile\nFROM kstaken/apache2\nRUN apt-get update \u0026\u0026 apt-get install -y php5 libapache2-mod-php5 \u0026\u0026 apt-get clean \u0026\u0026 rm -rf /var/lib/apt/lists/*\nCMD [\"/usr/sbin/apache2\", \"-D\", \"FOREGROUND\"]\n```\n\n#### YAML File Example With Target Field (Allows using any field)\n```yaml\nsomeConfig:\n  key: value\nserverConfig:\n  dockerfile:\n    stages:\n      final:\n        - from:\n            image: kstaken/apache2\n        - run:\n            runForm: shell\n            params:\n              - apt-get update \u0026\u0026\n              - apt-get clean \u0026\u0026\n              - rm -rf /var/lib/apt/lists/*\n```\nUse dfg as binary:\n```shell\ndfg generate -i ./example-input-files/test-input-with-target-key-6.yaml --target-field \".serverConfig.dockerfile\" --stdout\n```\nOr as a library\n```go\ndata, err := dfg.NewDockerFileDataFromYamlField(\"./example-input-files/test-input-with-target-key-6.yaml\", \".serverConfig.dockerfile\")\ntmpl := dfg.NewDockerfileTemplate(data)\nerr = tmpl.Render(output)\n```\n\n#### Output\n\n```dockerfile\nFROM kstaken/apache2\nRUN apt-get update \u0026\u0026 apt-get clean \u0026\u0026 rm -rf /var/lib/apt/lists/*\n```\n\n#### Library Usage Example\n\n```go\npackage main\n\nimport dfg \"github.com/ozankasikci/dockerfile-generator\"\n\nfunc main() {\n\tdata := \u0026dfg.DockerfileData{\n\t\tStages: []dfg.Stage{\n\t\t\t// Stage 1 - Builder Image\n\t\t\t// An instruction is just an interface, so you can pass custom structs as well\n\t\t\t[]dfg.Instruction{\n\t\t\t\tdfg.From{\n\t\t\t\t\tImage: \"golang:1.7.3\", As: \"builder\",\n\t\t\t\t},\n\t\t\t\tdfg.User{\n\t\t\t\t\tUser: \"ozan\",\n\t\t\t\t},\n\t\t\t\tdfg.Workdir{\n\t\t\t\t\tDir: \"/go/src/github.com/ozankasikci/dockerfile-generator/\",\n\t\t\t\t},\n\t\t\t\tdfg.RunCommand{\n\t\t\t\t\tParams: []string{\"go\", \"get\", \"-d\", \"-v\", \"golang.org/x/net/html\"},\n\t\t\t\t},\n\t\t\t\tdfg.CopyCommand{\n\t\t\t\t\tSources: []string{\"app.go\"}, Destination: \".\",\n\t\t\t\t},\n\t\t\t\tdfg.RunCommand{\n\t\t\t\t\tParams: []string{\"CGO_ENABLED=0\", \"GOOS=linux\", \"go\", \"build\", \"-a\", \"-installsuffix\", \"cgo\", \"-o\", \"app\", \".\"},\n\t\t\t\t},\n\t\t\t},\n\t\t\t// Stage 2 - Final Image\n\t\t\t[]dfg.Instruction{\n\t\t\t\tdfg.From{\n\t\t\t\t\tImage: \"alpine:latest\", As: \"final\",\n\t\t\t\t},\n\t\t\t\tdfg.RunCommand{\n\t\t\t\t\tParams: []string{\"apk\", \"--no-cache\", \"add\", \"ca-certificates\"},\n\t\t\t\t},\n\t\t\t\tdfg.User{\n\t\t\t\t\tUser: \"root\", Group: \"admin\",\n\t\t\t\t},\n\t\t\t\tdfg.Workdir{\n\t\t\t\t\tDir: \"/root/\",\n\t\t\t\t},\n\t\t\t\tdfg.CopyCommand{\n\t\t\t\t\tFrom: \"builder\", Sources: []string{\"/go/src/github.com/ozankasikci/dockerfile-generator/app\"}, Destination: \".\",\n\t\t\t\t},\n\t\t\t\tdfg.Cmd{\n\t\t\t\t\tParams: []string{\"./app\"},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t}\n\ttmpl := dfg.NewDockerfileTemplate(data)\n\t\n\t// write to a file\n\tfile, err := os.Create(\"Dockerfile\")\n\terr = tmpl.Render(file)\n\t\n\t// or write to stdout\n\terr = tmpl.Render(os.Stdout)\n}\n``` \n\n#### Output\n```Dockerfile\nFROM golang:1.7.3 as builder\nUSER ozan\nWORKDIR /go/src/github.com/ozankasikci/dockerfile-generator/\nRUN go get -d -v golang.org/x/net/html\nCOPY app.go .\nRUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .\n\nFROM alpine:latest as final\nRUN apk --no-cache add ca-certificates\nUSER root:admin\nWORKDIR /root/\nCOPY --from=builder /go/src/github.com/ozankasikci/dockerfile-generator/app .\nCMD [\"./app\"]\n```\n\n## TODO\n- [x] Add reading Dockerfile data from an existing yaml file support\n- [ ] Implement json file input channel\n- [ ] Implement stdin input channel\n- [ ] Implement toml file input channel\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fozankasikci%2Fdockerfile-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fozankasikci%2Fdockerfile-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fozankasikci%2Fdockerfile-generator/lists"}