Building and testing a Go project requires to setup a machine with Go and maybe tools like: cross compile, test coverage, glide, generating junit report, etc. Building and running test coverage requires scripts. base-go-build Docker image contains all, so all you need to do in order to build or test your go project in running a docker container as follow:
docker run --rm -v "$PWD":$PROJECT_PATH -w $PROJECT_PATH gaiadocker/base-go-build /go/script/go_build.sh $PROJECT_NAME
docker run --rm -v "$PWD":$PROJECT_PATH -w $PROJECT_PATH gaiadocker/base-go-build /go/script/coverage.sh
The test coverage script running on all projects' folders and generates, inside .cover folder, junit and coverage reports for each folder, and a combine coverage report of all projects' tests.
docker run --rm -v "$PWD":$PROJECT_PATH -w $PROJECT_PATH gaiadocker/base-go-build /go/script/github-release.sh github_api_token=TOKEN owner=gaia-docker repo=base-go-build tag=v0.1.0 filename=./build.zip
If you are using CircleCI for building and testing your go project, see follow circle.yml which using base-go-build docker image:
machine:
environment:
PROJECT_NAME: tugbot
PROJECT_PATH: /go/src/github.com/gaia-docker/$PROJECT_NAME
BUILDER_IMAGE_NAME: gaiadocker/base-go-build:10-master
dependencies:
override:
# run go build in a docker container
- docker run --rm -v "$PWD":$PROJECT_PATH -w $PROJECT_PATH $BUILDER_IMAGE_NAME /go/script/go_build.sh $PROJECT_NAME
test:
override:
# run tugbot tests and generate junit.xml reports
- docker run --rm -v "$PWD":$PROJECT_PATH -w $PROJECT_PATH $BUILDER_IMAGE_NAME /go/script/coverage.sh
post:
# copy test results
- cp .cover/*_tests.xml $CIRCLE_TEST_REPORTS
# deploy test coverage results to codecov
- bash <(curl -s https://codecov.io/bash) -f .cover/cover.out
general:
artifacts:
- .dist
- .cover
It's better to mention docker image tag name: gaiadocker/base-go-build:TAG - in case you have an old version of this image locally and build and push it on another computer, docker run command in the example will still use the old version. Also, you may want to use a specific version of Go.