diff --git a/golang/1.12/alpine3.9/Dockerfile b/golang/1.12/alpine3.9/Dockerfile new file mode 100644 index 0000000..540709e --- /dev/null +++ b/golang/1.12/alpine3.9/Dockerfile @@ -0,0 +1,17 @@ +FROM golang:1.12-alpine3.9 + +ENV GOOS linux +ENV GOARCH amd64 +ENV CGO_ENABLED 0 + +RUN apk --no-cache add build-base git bash \ + && go get -v -u github.com/stretchr/testify \ + github.com/tebeka/go2xunit \ + github.com/t-yuki/gocover-cobertura \ + gopkg.in/alecthomas/gometalinter.v2 \ + github.com/moexmen/gas-report-filter \ + && gometalinter.v2 --install \ + # Needs to be installed last to override outdated version in gometalinter + && go get github.com/securego/gosec/cmd/gosec/... + +COPY go-test-coverage-lint go-ast-scanner /usr/local/bin/ diff --git a/golang/1.12/alpine3.9/go-ast-scanner b/golang/1.12/alpine3.9/go-ast-scanner new file mode 100755 index 0000000..104a27e --- /dev/null +++ b/golang/1.12/alpine3.9/go-ast-scanner @@ -0,0 +1,4 @@ +#!/bin/bash + +mkdir -p /log +gosec -exclude=$GLOBAL_WHITELIST -fmt=junit-xml ./... | gas-report-filter -whitelist whitelist.json > /log/report.xml diff --git a/golang/1.12/alpine3.9/go-test-coverage-lint b/golang/1.12/alpine3.9/go-test-coverage-lint new file mode 100755 index 0000000..a09b6e9 --- /dev/null +++ b/golang/1.12/alpine3.9/go-test-coverage-lint @@ -0,0 +1,56 @@ +#!/bin/bash + +mkdir -p /log + +if [ "$#" -eq 0 ]; then + PKG=./... +else + PKG=${@:1} +fi + +function test-coverage { + echo "***********" + echo "* go test *" + echo "***********" + + # Capture the test result + set -o pipefail + go test -v $PKG | go2xunit > /log/test.xml + code=$? + set +o pipefail + + mkdir -p /log/coverage + echo "mode: count" > /log/coverage/coverage.out + + # Generate coverage for our source files + for x in $(go list $PKG | grep -v /vendor/); do + file=/log/coverage/$(echo $x | tr / -) + go test -covermode=count -coverprofile=$file "$x" + tail -n +2 $file >> /log/coverage/coverage.out + done + + go tool cover -html=/log/coverage/coverage.out -o /log/coverage/index.html + gocover-cobertura < /log/coverage/coverage.out > /log/coverage.xml + + exit $code +} + +function linters { + echo "************************" + echo "* Running gometalinter *" + echo "************************" + gometalinter.v2 --checkstyle \ + --deadline=60s \ + --disable-all \ + --enable=errcheck \ + --enable=golint \ + --enable=megacheck \ + --enable=misspell \ + --enable=vet \ + --vendor \ + $PKG > /log/checkstyle.xml +} + +linters +test-coverage +exit $?