FROM golang:1.9.4 as build
ENV GOPATH=/go/
RUN mkdir -p /go/src/github.com/openfaas/faas-netes/

WORKDIR /go/src/github.com/openfaas/faas-netes

COPY . .

RUN gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*") \
  && VERSION=$(git describe --all --exact-match `git rev-parse HEAD` | grep tags | sed 's/tags\///') \
  && GIT_COMMIT=$(git rev-list -1 HEAD) \
  && CGO_ENABLED=0 GOOS=linux go build --ldflags "-s -w \
    -X github.com/openfaas/faas-netes/version.GitCommit=${GIT_COMMIT}\
    -X github.com/openfaas/faas-netes/version.Version=${VERSION}" \
    -a -installsuffix cgo -o faas-netes .


FROM alpine:3.7
RUN apk --no-cache add ca-certificates
WORKDIR /root/

EXPOSE 8080
ENV http_proxy      ""
ENV https_proxy     ""

COPY --from=0 /go/src/github.com/openfaas/faas-netes/faas-netes    .

CMD ["./faas-netes"]
