diff --git a/.travis.yml b/.travis.yml index b1298a05f..5ea6f24ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,9 @@ language: go go: - 1.10.x +services: + - redis + before_install: - source scripts/travis-deps.sh diff --git a/Jenkinsfile b/Jenkinsfile index f2200385d..4c2f2a206 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,7 +6,7 @@ node('node') { } stage('Build Images') { - sh 'make images push-images' + sh 'make test-docker images' } stage('Deploy') { @@ -14,7 +14,7 @@ node('node') { echo 'Skipping deploy stage' return } - sh 'make deploy-images' + sh 'make push-images' } } @@ -35,7 +35,7 @@ node('node') { finally { stage('Cleanup') { - sh 'make clean-images' + sh 'make test-docker-clean clean-images' deleteDir() } diff --git a/Makefile b/Makefile index d6717c078..1a0641485 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,9 @@ TAG := $$(git rev-parse --short HEAD) GO_VERSION := 1.10 +COMPOSE_PROJECT_NAME := ${TAG}-$(shell git rev-parse --abbrev-ref HEAD) +GO_DIRS := $(shell go list ./... | grep -v storj.io/storj/examples) + lint: check-copyrights @echo "Running ${@}" @@ -16,9 +19,8 @@ lint: check-copyrights --enable=goconst \ --exclude=".*\.pb\.go" \ --exclude=".*_test.go" \ - --exclude="./vendor/*" \ --exclude="examples/*" \ - ./... + ${GO_DIRS} check-copyrights: @echo "Running ${@}" @@ -78,6 +80,13 @@ clean-local: # cleanup docker network docker network rm test-net || true +test-docker: + docker-compose up -d --remove-orphans test + docker-compose run test make test + +test-docker-clean: + -docker-compose down --rmi all + images: docker build --build-arg VERSION=${GO_VERSION} -t storjlabs/overlay:${TAG}-${GO_VERSION} -f cmd/overlay/Dockerfile . docker tag storjlabs/overlay:${TAG}-${GO_VERSION} storjlabs/overlay:latest diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 000000000..2f973cb1f --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,9 @@ +version: '3' +services: + test: + build: + context: . + dockerfile: test/Dockerfile + network_mode: service:test-redis + test-redis: + image: redis diff --git a/internal/test/storage.go b/internal/test/storage.go index 770f103fe..0e97311e3 100644 --- a/internal/test/storage.go +++ b/internal/test/storage.go @@ -4,10 +4,12 @@ package test import ( + "bytes" "crypto/rand" "encoding/hex" "flag" "log" + "net" "os" "os/exec" "path/filepath" @@ -165,7 +167,25 @@ func EnsureRedis(t *testing.T) (_ RedisDone) { redisRefs[index] = true if testRedis.started != true { - testRedis.start(t) + conn, err := net.Dial("tcp", "127.0.0.1:6379") + if err != nil { + testRedis.start(t) + } else { + testRedis.started = true + n, err := conn.Write([]byte("*1\r\n$8\r\nflushall\r\n")) + if err != nil { + log.Fatalf("Failed to request flush of existing redis keys: error %s\n", err) + } + b := make([]byte, 5) + n, err = conn.Read(b) + if err != nil { + log.Fatalf("Failed to flush existing redis keys: error %s\n", err) + } + if n != len(b) || !bytes.Equal(b, []byte("+OK\r\n")) { + log.Fatalf("Failed to flush existing redis keys: Unexpected response %s\n", b) + } + conn.Close() + } } return func() { @@ -222,6 +242,9 @@ func (r *RedisServer) start(t *testing.T) { func (r *RedisServer) stop() { r.started = false + if r.cmd == nil { + return + } if err := r.cmd.Process.Kill(); err != nil { log.Printf("Failed to kill process: %s\n", err) } diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 000000000..c7bcb3e94 --- /dev/null +++ b/test/Dockerfile @@ -0,0 +1,15 @@ +FROM golang:1.10-alpine + +RUN apk -U add make git bash gcc musl-dev + +RUN cd / \ + && rm -rf /go \ + && git clone --recursive https://github.com/storj/storj-vendor.git /go \ + && cd /go \ + && ./setup.sh + +COPY . /go/src/storj.io/storj + +WORKDIR /go/src/storj.io/storj + +RUN make build-dev-deps