# 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

# This is twitch's go module proxy
# Note: A regular go build will not work since you need to use the tunnel to set
#       this build arg.  You can use tgoproxy for that.  See the Makefile for
#       an example
ARG GOPROXY=http://jtv.goproxy.twitch.a2z.com
ENV GOPROXY=$GOPROXY

# 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

# Add our code, build it, test it, etc
ADD . .
# Make sure our code builds
RUN go build -mod=readonly ./...
# Make sure nobody hacked the module repository
RUN go mod verify
# Lint our code
RUN go vet ./...
RUN golint -set_exit_status ./...
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
