Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dockerfile #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang:1.10 as builder
WORKDIR /go/src/github.com/tsg/gotpl
RUN go get -d -v gopkg.in/yaml.v2
RUN go get -d -v github.com/Masterminds/sprig
COPY tpl.go .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix gotpl -o gotpl .

FROM alpine
COPY --from=builder /go/src/github.com/tsg/gotpl/gotpl /usr/local/bin/gotpl
ENTRYPOINT ["/usr/local/bin/gotpl"]
18 changes: 15 additions & 3 deletions tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,30 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"text/template"

"github.com/Masterminds/sprig"
"gopkg.in/yaml.v2"
)

// Reads a YAML document from the values_in stream, uses it as values
// for the tpl_files templates and writes the executed templates to
// the out stream.
func ExecuteTemplates(values_in io.Reader, out io.Writer, tpl_files ...string) error {
tpl, err := template.ParseFiles(tpl_files...)
func ExecuteTemplates(values_in io.Reader, out io.Writer, tpl_files string) error {
var r io.Reader
r, err := os.Open(tpl_files)
if err != nil {
return err
}
templateData, err := ioutil.ReadAll(r)
if err != nil {
return fmt.Errorf("Could not read input: %v", err)
}

tpl, err := template.New("base").Funcs(sprig.TxtFuncMap()).Parse(string(templateData))
if err != nil {
return fmt.Errorf("Error parsing template(s): %v", err)
}
Expand All @@ -40,7 +52,7 @@ func ExecuteTemplates(values_in io.Reader, out io.Writer, tpl_files ...string) e
}

func main() {
err := ExecuteTemplates(os.Stdin, os.Stdout, os.Args[1:]...)
err := ExecuteTemplates(os.Stdin, os.Stdout, os.Args[1])
if err != nil {
log.Println(err)
os.Exit(1)
Expand Down