# 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 golang.org/x/lint/golint@959b441ac422379a43da2230f62be024250818b0
RUN GO111MODULE=on go get github.com/kisielk/errcheck@v1.2.0
RUN GO111MODULE=on go get honnef.co/go/tools/cmd/staticcheck@0a11fc526260d1bcd0686bd3c9bd1167895aeea9
# 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 off
ENV GOFLAGS -mod=vendor

# Add our code, build it, test it, etc
ADD . .
# Make sure our code builds
RUN go build ./...

# This is commented out as there is no great way to verify vendored module code, https://github.com/golang/go/issues/27348 aims to address this
## Make sure nobody hacked the module repository
# RUN go mod verify

# Lint our code
RUN go vet ./...
RUN golint -set_exit_status $(go list ./... | grep -v /vendor/)
RUN errcheck -asserts -blank ./...
RUN staticcheck ./...
# Run the unit tests with the race detector
RUN go test -race -cover -coverprofile=coverage.txt -covermode=atomic ./...
# Upload code coverage
RUN curl -s https://codecov.internal.justin.tv/bash | CODECOV_TOKEN=ghe bash -s - || true
