Fix Dockerfile
parent
2ad8a708b7
commit
b69b96c7e9
16
Dockerfile
16
Dockerfile
|
@ -1,18 +1,26 @@
|
||||||
|
ARG name="email-collector"
|
||||||
|
ARG repo="github.com/productionwentdown/${name}"
|
||||||
|
|
||||||
|
|
||||||
FROM golang:1.10-alpine as go
|
FROM golang:1.10-alpine as go
|
||||||
|
|
||||||
ARG repo=github.com/productionwentdown/email-collector
|
ARG name
|
||||||
|
ARG repo
|
||||||
|
|
||||||
WORKDIR /go/src/${repo}
|
WORKDIR /go/src/${repo}
|
||||||
COPY . .
|
COPY . .
|
||||||
ENV CGO_ENABLED=0
|
ENV CGO_ENABLED=0
|
||||||
ENV GOOS=linux
|
ENV GOOS=linux
|
||||||
ENV GOARCH=amd64
|
ENV GOARCH=amd64
|
||||||
RUN go build -ldflags '-extldflags "-static"' -o email-collector
|
RUN go build -ldflags '-extldflags "-static"' -o ${name}
|
||||||
|
|
||||||
|
|
||||||
FROM scratch
|
FROM alpine:3.7
|
||||||
|
|
||||||
|
ARG name
|
||||||
|
ARG repo
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
COPY --from=go /go/src/${repo}/email-collector email-collector
|
COPY --from=go /go/src/${repo}/${name} /${name}
|
||||||
|
|
||||||
ENTRYPOINT ["/email-collector"]
|
ENTRYPOINT ["/email-collector"]
|
||||||
|
|
|
@ -2,6 +2,7 @@ package main // import "github.com/productionwentdown/email-collector"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -12,10 +13,18 @@ import (
|
||||||
"github.com/productionwentdown/email-collector/checkmail"
|
"github.com/productionwentdown/email-collector/checkmail"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var filename string
|
||||||
|
var listen string
|
||||||
|
var redirect string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.StringVar(&filename, "file", "list.csv", "file to append records to")
|
||||||
|
flag.StringVar(&listen, "listen", ":8080", "address to listen to")
|
||||||
|
flag.StringVar(&redirect, "redirect", "/subscribed", "path to redirect to upon success")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
csvMutex := &sync.Mutex{}
|
csvMutex := &sync.Mutex{}
|
||||||
csvFile, err := os.OpenFile("list.csv", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
csvFile, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||||
defer csvFile.Close()
|
defer csvFile.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -49,10 +58,10 @@ func main() {
|
||||||
csvWriter.Write([]string{email, time.Now().String()})
|
csvWriter.Write([]string{email, time.Now().String()})
|
||||||
csvWriter.Flush()
|
csvWriter.Flush()
|
||||||
csvMutex.Unlock()
|
csvMutex.Unlock()
|
||||||
w.Header().Add("Location", "/subscribed")
|
w.Header().Add("Location", redirect)
|
||||||
w.WriteHeader(303)
|
w.WriteHeader(303)
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
log.Fatal(http.ListenAndServe(listen, nil))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue