Add files for testing builds in docker (#161)
* Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis
This commit is contained in:
parent
5f6607935b
commit
0cbbc69777
@ -3,6 +3,9 @@ language: go
|
||||
go:
|
||||
- 1.10.x
|
||||
|
||||
services:
|
||||
- redis
|
||||
|
||||
before_install:
|
||||
- source scripts/travis-deps.sh
|
||||
|
||||
|
6
Jenkinsfile
vendored
6
Jenkinsfile
vendored
@ -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()
|
||||
}
|
||||
|
||||
|
13
Makefile
13
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
|
||||
|
9
docker-compose.yaml
Normal file
9
docker-compose.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
version: '3'
|
||||
services:
|
||||
test:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: test/Dockerfile
|
||||
network_mode: service:test-redis
|
||||
test-redis:
|
||||
image: redis
|
@ -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)
|
||||
}
|
||||
|
15
test/Dockerfile
Normal file
15
test/Dockerfile
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user