From fc393b39c94dd81b3732ea327462bc8e00c6f372 Mon Sep 17 00:00:00 2001 From: Soedarsono Date: Wed, 27 Mar 2019 12:47:16 +0800 Subject: [PATCH] Update Golang support files --- golang/1.12/alpine3.9/Dockerfile | 27 ++++++--- golang/1.12/alpine3.9/bin/ci-lint | 36 ++++++++++++ golang/1.12/alpine3.9/bin/ci-security-scan | 48 ++++++++++++++++ golang/1.12/alpine3.9/bin/ci-test | 57 +++++++++++++++++++ golang/1.12/alpine3.9/bin/go-ast-scanner | 13 +++++ .../1.12/alpine3.9/bin/go-test-coverage-lint | 25 ++++++++ golang/1.12/alpine3.9/go-ast-scanner | 4 -- golang/1.12/alpine3.9/go-test-coverage-lint | 56 ------------------ 8 files changed, 197 insertions(+), 69 deletions(-) create mode 100755 golang/1.12/alpine3.9/bin/ci-lint create mode 100755 golang/1.12/alpine3.9/bin/ci-security-scan create mode 100755 golang/1.12/alpine3.9/bin/ci-test create mode 100755 golang/1.12/alpine3.9/bin/go-ast-scanner create mode 100755 golang/1.12/alpine3.9/bin/go-test-coverage-lint delete mode 100755 golang/1.12/alpine3.9/go-ast-scanner delete mode 100755 golang/1.12/alpine3.9/go-test-coverage-lint diff --git a/golang/1.12/alpine3.9/Dockerfile b/golang/1.12/alpine3.9/Dockerfile index 540709e..cf0bb01 100644 --- a/golang/1.12/alpine3.9/Dockerfile +++ b/golang/1.12/alpine3.9/Dockerfile @@ -3,15 +3,24 @@ FROM golang:1.12-alpine3.9 ENV GOOS linux ENV GOARCH amd64 ENV CGO_ENABLED 0 +ENV GOROOT /usr/local/go + +ARG GOTESTSUM_VERSION=0.3.4 +ARG GOLANGCILINT_VERSION=1.15.0 +ARG GOSEC_VERSION=1.3.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/... + && wget -O /tmp/gotestsum.tar.gz https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_linux_amd64.tar.gz \ + && wget -O /tmp/golangci-lint.tar.gz https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCILINT_VERSION}/golangci-lint-${GOLANGCILINT_VERSION}-linux-amd64.tar.gz \ + && wget -O /tmp/gosec.tar.gz https://github.com/securego/gosec/releases/download/${GOSEC_VERSION}/gosec_${GOSEC_VERSION}_linux_amd64.tar.gz \ + && tar -C /tmp -xzf /tmp/gotestsum.tar.gz \ + && tar -C /tmp -xzf /tmp/golangci-lint.tar.gz \ + && tar -C /tmp -xzf /tmp/gosec.tar.gz \ + && cp /tmp/gotestsum /usr/local/bin \ + && cp /tmp/golangci-lint*/golangci-lint /usr/local/bin \ + && cp /tmp/gosec /usr/local/bin \ + && rm -rf /tmp/* \ + && go get github.com/t-yuki/gocover-cobertura \ + github.com/moexmen/gas-report-filter -COPY go-test-coverage-lint go-ast-scanner /usr/local/bin/ +COPY bin/ /usr/local/bin/ diff --git a/golang/1.12/alpine3.9/bin/ci-lint b/golang/1.12/alpine3.9/bin/ci-lint new file mode 100755 index 0000000..4725678 --- /dev/null +++ b/golang/1.12/alpine3.9/bin/ci-lint @@ -0,0 +1,36 @@ +#!/bin/bash + +set -e + +usage() { + echo "usage: ci-lint [--out checkstyle.xml] go-pkg" +} + +while [[ "$1" == -* ]]; do + case $1 in + -o|--out) + shift + OUTFILE=$1 + shift + ;; + *) + usage + exit 1 + esac +done + +if [ -z "$OUTFILE" ]; then + OUTFILE=checkstyle.xml +fi + +if [ "$#" -eq 0 ]; then + PKG=./... +else + PKG=${@:1} +fi + +set +e + +golangci-lint run --enable golint \ + --enable misspell \ + --out-format checkstyle $PKG > $OUTFILE diff --git a/golang/1.12/alpine3.9/bin/ci-security-scan b/golang/1.12/alpine3.9/bin/ci-security-scan new file mode 100755 index 0000000..6e6d383 --- /dev/null +++ b/golang/1.12/alpine3.9/bin/ci-security-scan @@ -0,0 +1,48 @@ +#!/bin/bash + +set -e + +usage() { + echo "usage: ci-security-scan [--out security.xml] [--excludes exclusion] [--whitelist whitelist] go-pkg" +} + +while [[ "$1" == -* ]]; do + case $1 in + -o|--out) + shift + OUTFILE=$1 + shift + ;; + -e|--excludes|-exclude) + shift + EXCLUDES=$1 + shift + ;; + -w|--whitelist) + shift + WHITELISTFILE=$1 + shift + ;; + *) + usage + exit 1 + esac +done + +if [ -z "$OUTFILE" ]; then + OUTFILE=security.xml +fi + +if [ -z "$WHITELISTFILE" ]; then + WHITELISTFILE=whitelist.json +fi + +if [ "$#" -eq 0 ]; then + PKG=./... +else + PKG=${@:1} +fi + +set +e + +gosec -exclude=$EXCLUDES -fmt=junit-xml $PKG | gas-report-filter -whitelist $WHITELISTFILE > $OUTFILE diff --git a/golang/1.12/alpine3.9/bin/ci-test b/golang/1.12/alpine3.9/bin/ci-test new file mode 100755 index 0000000..a3324b7 --- /dev/null +++ b/golang/1.12/alpine3.9/bin/ci-test @@ -0,0 +1,57 @@ +#!/bin/bash + +set -e + +usage() { + echo "usage: ci-test [--out test.xml] [--cover coverage.xml] [--html coverage.html] go-pkg" +} + +while [[ "$1" == -* ]]; do + case $1 in + -o|--out) + shift + OUTFILE=$1 + shift + ;; + -c|--cover) + shift + COVERFILE=$1 + shift + ;; + -h|--html) + shift + HTMLFILE=$1 + shift + ;; + *) + usage + exit 1 + esac +done + +if [ -z "$OUTFILE" ]; then + OUTFILE=test.xml +fi + +if [ -z "$COVERFILE" ]; then + COVERFILE=coverage.xml +fi + +if [ -z "$HTMLFILE" ]; then + HTMLFILE=coverage.html +fi + +if [ "$#" -eq 0 ]; then + PKG=./... +else + PKG=${@:1} +fi + +set +e + +gotestsum --junitfile $OUTFILE -- -coverprofile=${COVERFILE}.out $PKG +code=$? +gocover-cobertura < ${COVERFILE}.out > $COVERFILE +go tool cover -html=${COVERFILE}.out -o $HTMLFILE +rm ${COVERFILE}.out +exit $code diff --git a/golang/1.12/alpine3.9/bin/go-ast-scanner b/golang/1.12/alpine3.9/bin/go-ast-scanner new file mode 100755 index 0000000..88d74a2 --- /dev/null +++ b/golang/1.12/alpine3.9/bin/go-ast-scanner @@ -0,0 +1,13 @@ +#!/bin/bash + +echo "*******************************************" +echo "WARNING: This function in deprecated. Please use ci-security-scan instead" +echo "*******************************************" + +mkdir -p /log + +if [ ! -z $GLOBAL_WHITELIST ]; then + EXCLUDES="--excludes $GLOBAL_WHITELIST" +fi + +ci-security-scan $EXCLUDES --out /log/report.xml ./... diff --git a/golang/1.12/alpine3.9/bin/go-test-coverage-lint b/golang/1.12/alpine3.9/bin/go-test-coverage-lint new file mode 100755 index 0000000..759ce69 --- /dev/null +++ b/golang/1.12/alpine3.9/bin/go-test-coverage-lint @@ -0,0 +1,25 @@ +#!/bin/bash + +if [ "$#" -eq 0 ]; then + PKG=./... +else + PKG=${@:1} +fi + +echo "*******************************************" +echo "WARNING: This function in deprecated. Please use ci-test/ci-lint instead" +echo "*******************************************" +echo + +function test-coverage { + ci-test --out /log/test.xml --cover /log/coverage.xml --html /log/coverage.html ./... +} + +function linters { + ci-lint --out /log/checkstyle.xml ./... +} + +mkdir -p /log +linters +test-coverage +exit $? diff --git a/golang/1.12/alpine3.9/go-ast-scanner b/golang/1.12/alpine3.9/go-ast-scanner deleted file mode 100755 index 104a27e..0000000 --- a/golang/1.12/alpine3.9/go-ast-scanner +++ /dev/null @@ -1,4 +0,0 @@ -#!/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 deleted file mode 100755 index a09b6e9..0000000 --- a/golang/1.12/alpine3.9/go-test-coverage-lint +++ /dev/null @@ -1,56 +0,0 @@ -#!/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 $?