# The builder and linter for this repository
# Notice how we depend upon nothing twitch specific: just pulling the core golang docker image
FROM golang:1.12.5

# Do this first so this step is cached
RUN GO111MODULE=on go get honnef.co/go/tools/cmd/staticcheck@incr
# Go modules don't need to be in GOPATH.  Just build/test inside app
WORKDIR /app

# Local mac builds need to use an HTTP proxy to access the go module proxy
ARG HTTPS_PROXY
ENV HTTPS_PROXY=$HTTPS_PROXY
ENV HTTP_PROXY=$HTTPS_PROXY
# This is twitch's go module proxy
ENV GOPROXY http://www.production.goproxy.internal.justin.tv

# Add our code, build it, test it, etc
ADD . .
# Make sure our code builds
RUN go build ./...
# Make sure nobody hacked the module repository
RUN go mod verify
# Lint our code
RUN staticcheck ./...
# Run the unit tests with the race detector
RUN go test -race -v -cover -coverprofile=coverage.txt -covermode=atomic ./...
# Upload code coverage
RUN curl -s https://codecov.internal.justin.tv/bash | CODECOV_TOKEN=ghe bash -s - || true
