Add ca-certs
parent
233a0b0631
commit
4911e597db
|
@ -4,6 +4,7 @@ ARG repo="github.com/productionwentdown/${name}"
|
||||||
|
|
||||||
FROM golang:1.10-alpine as go
|
FROM golang:1.10-alpine as go
|
||||||
|
|
||||||
|
RUN apk add --no-cache ca-certificates
|
||||||
ARG name
|
ARG name
|
||||||
ARG repo
|
ARG repo
|
||||||
|
|
||||||
|
@ -15,12 +16,13 @@ ENV GOARCH=amd64
|
||||||
RUN go build -ldflags '-extldflags "-static"' -o ${name}
|
RUN go build -ldflags '-extldflags "-static"' -o ${name}
|
||||||
|
|
||||||
|
|
||||||
FROM alpine:3.7
|
FROM scratch
|
||||||
|
|
||||||
ARG name
|
ARG name
|
||||||
ARG repo
|
ARG repo
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
COPY --from=go /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||||
COPY --from=go /go/src/${repo}/${name} /${name}
|
COPY --from=go /go/src/${repo}/${name} /${name}
|
||||||
|
|
||||||
ENTRYPOINT ["/email-collector"]
|
ENTRYPOINT ["/email-collector"]
|
||||||
|
|
|
@ -40,22 +40,19 @@ func main() {
|
||||||
err := r.ParseForm()
|
err := r.ParseForm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
w.WriteHeader(400)
|
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||||
w.Write([]byte("An error occurred. Please try again"))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
email := r.Form.Get("email")
|
email := r.Form.Get("email")
|
||||||
if err := checkmail.ValidateFormat(email); err != nil {
|
if err := checkmail.ValidateFormat(email); err != nil {
|
||||||
log.Println(email, err)
|
log.Println(email, err)
|
||||||
w.WriteHeader(400)
|
http.Error(w, "Email is not valid", http.StatusBadRequest)
|
||||||
w.Write([]byte("Email is not valid"))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = checkmail.ValidateHost(email)
|
err = checkmail.ValidateHost(email)
|
||||||
if _, ok := err.(checkmail.SmtpError); !ok && err != nil {
|
if _, ok := err.(checkmail.SmtpError); !ok && err != nil {
|
||||||
log.Println(email, err)
|
log.Println(email, err)
|
||||||
w.WriteHeader(400)
|
http.Error(w, "Email is not valid", http.StatusBadRequest)
|
||||||
w.Write([]byte("Email is not valid"))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Println(email, "success")
|
log.Println(email, "success")
|
||||||
|
@ -70,20 +67,20 @@ func main() {
|
||||||
payload, err := json.Marshal(object)
|
payload, err := json.Marshal(object)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("json.Marshal failed, not supposed to happen!")
|
log.Println("json.Marshal failed, not supposed to happen!")
|
||||||
w.WriteHeader(500)
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp, err := http.Post(slack, "application/json", bytes.NewBuffer(payload))
|
resp, err := http.Post(slack, "application/json", bytes.NewBuffer(payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
w.WriteHeader(500)
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
log.Println(body)
|
log.Println(body)
|
||||||
w.WriteHeader(500)
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue