Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

Commit

Permalink
Update Golang support files
Browse files Browse the repository at this point in the history
  • Loading branch information
soedar committed Mar 28, 2019
1 parent 9786593 commit fc393b3
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 69 deletions.
27 changes: 18 additions & 9 deletions golang/1.12/alpine3.9/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
36 changes: 36 additions & 0 deletions golang/1.12/alpine3.9/bin/ci-lint
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions golang/1.12/alpine3.9/bin/ci-security-scan
Original file line number Diff line number Diff line change
@@ -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
57 changes: 57 additions & 0 deletions golang/1.12/alpine3.9/bin/ci-test
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions golang/1.12/alpine3.9/bin/go-ast-scanner
Original file line number Diff line number Diff line change
@@ -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 ./...
25 changes: 25 additions & 0 deletions golang/1.12/alpine3.9/bin/go-test-coverage-lint
Original file line number Diff line number Diff line change
@@ -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 $?
4 changes: 0 additions & 4 deletions golang/1.12/alpine3.9/go-ast-scanner

This file was deleted.

56 changes: 0 additions & 56 deletions golang/1.12/alpine3.9/go-test-coverage-lint

This file was deleted.

0 comments on commit fc393b3

Please sign in to comment.