From a6fd458d40b1c2b87ed4e722151e9cf7efe9e5c3 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Mon, 17 Sep 2018 12:05:34 +0200 Subject: [PATCH] Read parameters from ENV Signed-off-by: Knut Ahlers --- Dockerfile | 8 +++++--- main.go | 11 ++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9378a5c..f942142 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,18 @@ FROM golang:alpine as builder -ADD . /go/src/github.com/Luzifer/tex-api +COPY . /go/src/github.com/Luzifer/tex-api WORKDIR /go/src/github.com/Luzifer/tex-api RUN set -ex \ && apk add --update git \ && go install -ldflags "-X main.version=$(git describe --tags || git rev-parse --short HEAD || echo dev)" -FROM alpine:latest +FROM alpine:3.8 LABEL maintainer "Knut Ahlers " +ENV SCRIPT=/usr/local/bin/tex-build.sh + RUN set -ex \ && apk --no-cache add \ bash \ @@ -24,6 +26,6 @@ EXPOSE 3000 VOLUME ["/storage"] ENTRYPOINT ["/usr/local/bin/tex-api"] -CMD ["--script", "/usr/local/bin/tex-build.sh"] +CMD ["--"] # vim: set ft=Dockerfile: diff --git a/main.go b/main.go index 8ec603a..50c1354 100644 --- a/main.go +++ b/main.go @@ -22,10 +22,10 @@ import ( var ( cfg = struct { - ExecutionScript string `flag:"script" default:"/go/src/github.com/Luzifer/tex-api/tex-build.sh" description:"Script to execute (needs to generate output directory)"` - Listen string `flag:"listen" default:":3000" description:"IP/Port to listen on"` - StorageDir string `flag:"storage-dir" default:"/storage" description:"Where to store uploaded ZIPs and resulting files"` - VersionAndExit bool `flag:"version" default:"false" description:"Prints current version and exits"` + Script string `flag:"script" default:"tex-build.sh" description:"Script to execute (needs to generate output directory)"` + Listen string `flag:"listen" default:":3000" description:"IP/Port to listen on"` + StorageDir string `flag:"storage-dir" default:"/storage" description:"Where to store uploaded ZIPs and resulting files"` + VersionAndExit bool `flag:"version" default:"false" description:"Prints current version and exits"` }{} version = "dev" @@ -96,6 +96,7 @@ func urlMust(u *url.URL, err error) *url.URL { } func init() { + rconfig.AutoEnv(true) if err := rconfig.Parse(&cfg); err != nil { log.WithError(err).Fatal("Unable to parse commandline options") } @@ -276,7 +277,7 @@ func jobProcessor(uid uuid.UUID) { return } - cmd := exec.Command("/bin/bash", cfg.ExecutionScript) // #nosec G204 + cmd := exec.Command("/bin/bash", cfg.Script) // #nosec G204 cmd.Dir = processingDir cmd.Stderr = log.StandardLogger().WriterLevel(log.ErrorLevel)