Skip to content

Commit

Permalink
Merge pull request #147 from m-lab/commit-hash
Browse files Browse the repository at this point in the history
Add version to the build and convert travis to best practices
  • Loading branch information
pboothe authored Apr 12, 2019
2 parents a9fcac8 + a7f66fe commit 71ba783
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 44 deletions.
50 changes: 13 additions & 37 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
- docker

go:
- 1.9.x
- 1.12

###########################################################################
before_install:
Expand Down Expand Up @@ -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.
Expand All @@ -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 || $? ] ;
done ;
echo "summary status $EC" ;
if [[ $EC != 0 ]]; then false; fi ;
go test -v -coverpkg=./... -coverprofile=_integration.cov ./... -tags=integration ;
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 .

#################################################################################
Expand Down
19 changes: 12 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
WORKDIR /
ENTRYPOINT [ "/bin/gardener" ]

0 comments on commit 71ba783

Please sign in to comment.