mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 10:56:47 +00:00
Run testing and linting in a Dockerfile.
This simplifies the use of travis significantly and should speed things up as parts of the setup are now done once when the docker image is created. Tests may be run locally (no docker) by using the 'local' arg to run_tests.sh.
This commit is contained in:
parent
e7b128a672
commit
9987b02983
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@ -0,0 +1,2 @@
|
||||
*~
|
||||
vendor
|
||||
24
.travis.yml
24
.travis.yml
@ -1,15 +1,13 @@
|
||||
dist: trusty
|
||||
sudo: required
|
||||
|
||||
language: go
|
||||
go:
|
||||
- 1.7.x
|
||||
- 1.8.x
|
||||
sudo: false
|
||||
install:
|
||||
- go get -v github.com/Masterminds/glide
|
||||
- glide install
|
||||
- go install -v . ./cmd/...
|
||||
- go get -v github.com/alecthomas/gometalinter
|
||||
- gometalinter --install
|
||||
|
||||
services:
|
||||
- docker
|
||||
|
||||
env:
|
||||
- GOVERSION = 1.7
|
||||
- GOVERSION = 1.8
|
||||
|
||||
script:
|
||||
- export PATH=$PATH:$HOME/gopath/bin
|
||||
- ./goclean.sh
|
||||
- ./run_tests.sh $GOVERSION
|
||||
|
||||
51
Dockerfile-1.7
Normal file
51
Dockerfile-1.7
Normal file
@ -0,0 +1,51 @@
|
||||
#decred-golang-builder-1.7
|
||||
FROM golang:1.7.6
|
||||
|
||||
LABEL description="Decred golang builder image"
|
||||
LABEL version="1.0"
|
||||
LABEL maintainer "john@netpurgatory.com"
|
||||
|
||||
ENV TERM linux
|
||||
ENV USER build
|
||||
|
||||
# create user
|
||||
RUN adduser --disabled-password --gecos '' build
|
||||
|
||||
# update base distro & install build tooling
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -qy rsync
|
||||
|
||||
# create directory for build artifacts, adjust user permissions
|
||||
RUN mkdir /release && \
|
||||
chown $USER /release
|
||||
|
||||
# create directory to get source from
|
||||
RUN mkdir /src && \
|
||||
chown $USER /src && \
|
||||
mkdir -p /go/src/github.com/decred/dcrd && \
|
||||
mkdir -p /go/src/github.com/decred/dcrwallet && \
|
||||
mkdir -p /go/src/github.com/decred/dcrctl && \
|
||||
mkdir -p /go/src/github.com/decred/dcrrpcclient && \
|
||||
chown -R $USER /go/src/github.com/decred
|
||||
|
||||
# switch user
|
||||
USER $USER
|
||||
ENV HOME /home/$USER
|
||||
|
||||
#Get deps
|
||||
ENV GLIDE_TAG v0.12.3
|
||||
ENV GOMETALINTER_TAG v1.2.1
|
||||
|
||||
WORKDIR /go/src
|
||||
RUN go get -v github.com/Masterminds/glide && \
|
||||
cd /go/src/github.com/Masterminds/glide && \
|
||||
git checkout $GLIDE_TAG && \
|
||||
make build && \
|
||||
mv glide `which glide` && \
|
||||
go get -v github.com/alecthomas/gometalinter && \
|
||||
cd /go/src/github.com/alecthomas/gometalinter && \
|
||||
git checkout $GOMETALINTER_TAG && \
|
||||
go install && \
|
||||
gometalinter --install
|
||||
51
Dockerfile-1.8
Normal file
51
Dockerfile-1.8
Normal file
@ -0,0 +1,51 @@
|
||||
#decred-golang-builder-1.8
|
||||
FROM golang:1.8.3
|
||||
|
||||
LABEL description="Decred golang builder image"
|
||||
LABEL version="1.0"
|
||||
LABEL maintainer "john@netpurgatory.com"
|
||||
|
||||
ENV TERM linux
|
||||
ENV USER build
|
||||
|
||||
# create user
|
||||
RUN adduser --disabled-password --gecos '' build
|
||||
|
||||
# update base distro & install build tooling
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -qy rsync
|
||||
|
||||
# create directory for build artifacts, adjust user permissions
|
||||
RUN mkdir /release && \
|
||||
chown $USER /release
|
||||
|
||||
# create directory to get source from
|
||||
RUN mkdir /src && \
|
||||
chown $USER /src && \
|
||||
mkdir -p /go/src/github.com/decred/dcrd && \
|
||||
mkdir -p /go/src/github.com/decred/dcrwallet && \
|
||||
mkdir -p /go/src/github.com/decred/dcrctl && \
|
||||
mkdir -p /go/src/github.com/decred/dcrrpcclient && \
|
||||
chown -R $USER /go/src/github.com/decred
|
||||
|
||||
# switch user
|
||||
USER $USER
|
||||
ENV HOME /home/$USER
|
||||
|
||||
#Get deps
|
||||
ENV GLIDE_TAG v0.12.3
|
||||
ENV GOMETALINTER_TAG v1.2.1
|
||||
|
||||
WORKDIR /go/src
|
||||
RUN go get -v github.com/Masterminds/glide && \
|
||||
cd /go/src/github.com/Masterminds/glide && \
|
||||
git checkout $GLIDE_TAG && \
|
||||
make build && \
|
||||
mv glide `which glide` && \
|
||||
go get -v github.com/alecthomas/gometalinter && \
|
||||
cd /go/src/github.com/alecthomas/gometalinter && \
|
||||
git checkout $GOMETALINTER_TAG && \
|
||||
go install && \
|
||||
gometalinter --install
|
||||
29
README.md
29
README.md
@ -82,7 +82,34 @@ go install $(glide nv)
|
||||
For more information about decred and how to set up your software please go to
|
||||
our docs page at [docs.decred.org](https://docs.decred.org/getting-started/beginner-guide/).
|
||||
|
||||
## Contact
|
||||
## Docker
|
||||
|
||||
All tests and linters may be run in a docker container using the script `run_tests.sh`. This script defaults to using the current supported version of go. You can run it with the major version of go you would like to use as the only arguement to test a previous on a previous version of go (generally decred supports the current version of go and the previous one).
|
||||
|
||||
```
|
||||
./run_tests.sh 1.7
|
||||
```
|
||||
|
||||
To run the tests locally without docker:
|
||||
|
||||
```
|
||||
./run_tests.sh local
|
||||
```
|
||||
|
||||
### Updating docker go versions
|
||||
|
||||
When a new minor version of go is released, the docker images must be updated and rebuilt to support it. For example, when go1.8.3 was released, the file `Dockerfile-1.8` was edited by changing `FROM golang:1.8.2` to `FROM golang:1.8.3`. Then the image was rebuilt and pushed to docker hub:
|
||||
```
|
||||
GOVERSION=1.8
|
||||
DOCKER_IMAGE_TAG=decred-golang-builder-$GOVERSION
|
||||
docker build -t $DOCKER_IMAGE_TAG -f ./Dockerfile-$GOVERSION .
|
||||
docker tag $DOCKER_IMAGE_TAG decred/$DOCKER_IMAGE_TAG
|
||||
docker push decred/$DOCKER_IMAGE_TAG
|
||||
```
|
||||
|
||||
For a new major version, a new file `Dockerfile-VERSION` must be created and then the previous steps can be followed. That new version must be added to the travis build matrix to run the tests in travis.
|
||||
|
||||
## Contact
|
||||
|
||||
If you have any further questions you can find us at:
|
||||
|
||||
|
||||
35
goclean.sh
35
goclean.sh
@ -1,35 +0,0 @@
|
||||
#!/bin/bash
|
||||
# The script does automatic checking on a Go package and its sub-packages, including:
|
||||
# 1. gofmt (http://golang.org/cmd/gofmt/)
|
||||
# 2. go vet (http://golang.org/cmd/vet)
|
||||
# 3. unconvert (https://github.com/mdempsky/unconvert)
|
||||
# 4. race detector (http://blog.golang.org/race-detector)
|
||||
# 5. test coverage (http://blog.golang.org/cover)
|
||||
|
||||
# gometalinter (github.com/alecthomas/gometalinter) is used to run each each
|
||||
# static checker.
|
||||
set -ex
|
||||
|
||||
# Make sure glide is installed and $GOPATH/bin is in your path.
|
||||
# $ go get -u github.com/Masterminds/glide
|
||||
# $ glide install
|
||||
if [ ! -x "$(type -p glide)" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make sure gometalinter is installed and $GOPATH/bin is in your path.
|
||||
# $ go get -v github.com/alecthomas/gometalinter"
|
||||
# $ gometalinter --install"
|
||||
if [ ! -x "$(type -p gometalinter)" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Automatic checks
|
||||
test -z "$(gometalinter --disable-all \
|
||||
--enable=gofmt \
|
||||
--enable=vet \
|
||||
--enable=unconvert \
|
||||
--vendor \
|
||||
--deadline=10m . 2>&1 | tee /dev/stderr)"
|
||||
|
||||
env GORACE="halt_on_error=1" go test -short -race $(glide novendor)
|
||||
50
run_tests.sh
Executable file
50
run_tests.sh
Executable file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
# The script does automatic checking on a Go package and its sub-packages,
|
||||
# including:
|
||||
# 1. gofmt (http://golang.org/cmd/gofmt/)
|
||||
# 2. go vet (http://golang.org/cmd/vet)
|
||||
# 3. unconvert (https://github.com/mdempsky/unconvert)
|
||||
# 4. race detector (http://blog.golang.org/race-detector)
|
||||
|
||||
# gometalinter (github.com/alecthomas/gometalinter) is used to run each each
|
||||
# static checker.
|
||||
|
||||
# To run on docker on windows, symlink /mnt/c to /c and then execute the script
|
||||
# from the repo path under /c. See:
|
||||
# https://github.com/Microsoft/BashOnWindows/issues/1854
|
||||
# for more details.
|
||||
|
||||
#Default GOVERSION
|
||||
GOVERSION=${1:-1.8}
|
||||
REPO=dcrd
|
||||
|
||||
TESTCMD="test -z \"\$(gometalinter --disable-all \
|
||||
--enable=gofmt \
|
||||
--enable=vet \
|
||||
--enable=unconvert \
|
||||
--vendor \
|
||||
--deadline=10m . | tee /dev/stderr)\"&& \
|
||||
env GORACE='halt_on_error=1' go test -short -race \$(glide novendor)"
|
||||
|
||||
if [ $GOVERSION == "local" ]; then
|
||||
eval $TESTCMD
|
||||
exit
|
||||
fi
|
||||
|
||||
DOCKER_IMAGE_TAG=decred-golang-builder-$GOVERSION
|
||||
|
||||
docker pull decred/$DOCKER_IMAGE_TAG
|
||||
|
||||
docker run --rm -it -v $(pwd):/src decred/$DOCKER_IMAGE_TAG /bin/bash -c "\
|
||||
rsync -ra --filter=':- .gitignore' \
|
||||
/src/ /go/src/github.com/decred/$REPO/ && \
|
||||
cd github.com/decred/$REPO/ && \
|
||||
glide install && \
|
||||
go install \$(glide novendor) && \
|
||||
$TESTCMD
|
||||
"
|
||||
|
||||
echo "------------------------------------------"
|
||||
echo "Tests complete."
|
||||
Loading…
Reference in New Issue
Block a user