From b544d50df24d37e4bc113324a735f70b44ec129c Mon Sep 17 00:00:00 2001 From: Peter Boothe Date: Fri, 12 Apr 2019 10:37:01 -0400 Subject: [PATCH 1/2] Add version to the build and convert travis to best practices --- .travis.yml | 50 +++++++++++++------------------------------------- Dockerfile | 19 ++++++++++++------- 2 files changed, 25 insertions(+), 44 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9b583a94..132b8e29 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ services: - docker go: - - 1.9.x + - 1.12 ########################################################################### before_install: @@ -49,8 +49,8 @@ install: - $TRAVIS_BUILD_DIR/travis/install_gcloud.sh kubectl # Install dependencies -- GO_IMPORTS=$(go list -f '{{join .Imports "\n"}}{{"\n"}}{{join .TestImports "\n"}}{{join .XTestImports "\n"}}' ./... | sort | uniq | grep -e / | grep -v m-lab/etl-gardener) -- go get -u -v -d $GO_IMPORTS +- cd $TRAVIS_BUILD_DIR +- go get -v -t ./... before_script: # Try removing boto config, recommended for datastore emulator. @@ -63,45 +63,21 @@ before_script: - $(gcloud beta emulators datastore env-init) script: -# To start, run all the non-integration tests. -- MODULES="cloud/bq cloud/tq cmd/gardener reproc rex state" -- for module in $MODULES; do - COVER_PKGS=${COVER_PKGS}./$module/..., ; - done -- COVER_PKGS=${COVER_PKGS::-1} # Trim the trailing comma -- EC=0 -# Note that for modules in subdirectories, this replaces separating slashes with _. -- for module in $MODULES; do - go test -v -coverpkg=$COVER_PKGS -coverprofile=${module//\//_}.cov github.com/m-lab/etl-gardener/$module ; - EC=$[ $EC || $? ] ; - done -- echo "summary status $EC" ; -- if [[ $EC != 0 ]]; then false; fi - - -# Rerun modules with integration tests. This means that some tests are repeated, but otherwise -# we lose some coverage. The corresponding cov files are overwritten, but that is OK since -# the non-integration tests are repeated. If we change the unit tests to NOT run when integration -# test tag is set, then we would need to have separate cov files. -# Note: we do not run integration tests from forked PRs b/c the SA is unavailable. -# Note that for modules in subdirectories, this replaces separating slashes with _. +# To start, run all the non-integration unit tests. +- cd $TRAVIS_BUILD_DIR +- go test -v -coverpkg=./... -coverprofile=_unit.cov ./... + +# Rerun modules with integration tests. This means that some tests are +# repeated, but otherwise we lose some coverage. - if [[ -n "$SERVICE_ACCOUNT_mlab_testing" ]] ; then - MODULES="cloud/bq cloud/tq cmd/gardener reproc rex state" ; - for module in $MODULES; do - go test -v -coverpkg=$COVER_PKGS -coverprofile=${module//\//_}.cov github.com/m-lab/etl-gardener/$module -tags=integration ; - EC=$[ $EC || $? ] ; + go test -v -coverpkg=./... -coverprofile=_integration.cov ./... -tags=integration ; done ; - echo "summary status $EC" ; - if [[ $EC != 0 ]]; then false; fi ; - fi -# Coveralls -# Run "unit tests" with coverage. -- $HOME/gopath/bin/gocovmerge *.cov > merge.cov -- $HOME/gopath/bin/goveralls -coverprofile=merge.cov -service=travis-ci +# Combine coverage of unit tests and integration tests and send the results to coveralls. +- $HOME/gopath/bin/gocovmerge _*.cov > _merge.cov +- $HOME/gopath/bin/goveralls -coverprofile=_merge.cov -service=travis-ci # Clean build and prepare for deployment -- cd $TRAVIS_BUILD_DIR - docker build . ################################################################################# diff --git a/Dockerfile b/Dockerfile index 2e75faa1..36f38627 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,21 @@ -FROM golang:alpine +FROM golang:1.12 as builder -RUN apk update && apk add bash git +ENV CGO_ENABLED 0 WORKDIR /go/src/github.com/m-lab/etl-gardener COPY . . -# List all of the go imports, excluding any in this repo, and run go get to import them. -RUN go get -u -v $(go list -f '{{join .Imports "\n"}}{{"\n"}}{{join .TestImports "\n"}}' ./... | sort | uniq | grep -v etl-gardener) +# Get the requirements and put the produced binaries in /go/bin +RUN go get -v -t ./... +RUN go install \ + -v \ + -ldflags "-X github.com/m-lab/go/prometheusx.GitShortCommit=$(git log -1 --format=%h)" \ + ./... -# Install all go executables. -RUN go install -v ./... +FROM alpine +COPY --from=builder /go/bin/gardener /bin/gardener EXPOSE 9090 8080 -CMD gardener \ No newline at end of file +WORKDIR / +ENTRYPOINT [ "/bin/gardener" ] From a7f66fee890dc2aa92e3f4a23bf208df4f1c9dc1 Mon Sep 17 00:00:00 2001 From: Peter Boothe Date: Fri, 12 Apr 2019 11:38:10 -0400 Subject: [PATCH 2/2] End if with fi, not done --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 132b8e29..4ef7924c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -71,7 +71,7 @@ script: # repeated, but otherwise we lose some coverage. - if [[ -n "$SERVICE_ACCOUNT_mlab_testing" ]] ; then go test -v -coverpkg=./... -coverprofile=_integration.cov ./... -tags=integration ; - done ; + fi # Combine coverage of unit tests and integration tests and send the results to coveralls. - $HOME/gopath/bin/gocovmerge _*.cov > _merge.cov