FROM golang:1.13.4 as build_and_test
MAINTAINER DS Team <ds@twitch.tv>
WORKDIR /go/src/code.justin.tv/extensions/configuration/services/main
COPY . .
RUN apt-get update && \
    apt-get install -y git ca-certificates
RUN go get github.com/axw/gocov/gocov && \
    go get github.com/t-yuki/gocov-xml
RUN gocov test ./... --short > coverage.json && \
    gocov-xml < coverage.json > coverage.xml
WORKDIR /go/src/code.justin.tv/extensions/configuration/services/main/cmd
RUN CGO_ENABLED=0 GOOS=linux go build -a -v -installsuffix cgo -o configuration . && \
    chmod 755 configuration

FROM busybox:latest as run
MAINTAINER DS Team <ds@twitch.tv>
EXPOSE 8000
WORKDIR /root/
COPY --from=build_and_test /etc/ssl/certs /etc/ssl/certs
COPY --from=build_and_test /go/src/code.justin.tv/extensions/configuration/services/main/cmd/configuration .
COPY --from=build_and_test /go/src/code.justin.tv/extensions/configuration/services/main/coverage.* ./
CMD ["./configuration"]
