Skip to content

Commit

Permalink
Merge pull request #2064 from ipfs/ipfs-volume
Browse files Browse the repository at this point in the history
Docker image volume fix and Sharness tests
  • Loading branch information
whyrusleeping committed Jan 10, 2016
2 parents 453d30a + 3916e73 commit dc4f5af
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 4 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Expand Up @@ -16,4 +16,9 @@ env:
script:
- make $TEST_SUITE

sudo: false #docker containers for CI
# For docker containers

sudo: required

services:
- docker
3 changes: 1 addition & 2 deletions Dockerfile
Expand Up @@ -7,8 +7,6 @@ ENV VERSION master
EXPOSE 4001 5001 8080
# 4001 = Swarm, 5001 = API, 8080 = HTTP transport

VOLUME /data/ipfs

ADD bin/container_daemon /usr/local/bin/start_ipfs
ADD bin/container_shacheck /usr/local/bin/shacheck

Expand All @@ -24,6 +22,7 @@ RUN adduser -D -h /data -u 1000 ipfs \
&& apk del wget zip curl

USER ipfs
VOLUME /data/ipfs

ENTRYPOINT ["/usr/local/bin/start_ipfs"]

Expand Down
3 changes: 3 additions & 0 deletions circle.yml
Expand Up @@ -3,10 +3,13 @@ machine:
TEST_NO_FUSE: 1
TEST_VERBOSE: 1
TRAVIS: 1
CIRCLE: 1
post:
- sudo rm -rf /usr/local/go
- if [ ! -e go1.5.linux-amd64.tar.gz ]; then curl -o go1.5.linux-amd64.tar.gz https://storage.googleapis.com/golang/go1.5.linux-amd64.tar.gz; fi
- sudo tar -C /usr/local -xzf go1.5.linux-amd64.tar.gz
services:
- docker

dependencies:
pre:
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/swarm/dial_test.go
Expand Up @@ -89,7 +89,7 @@ func TestSimultDials(t *testing.T) {

func newSilentPeer(t *testing.T) (peer.ID, ma.Multiaddr, net.Listener) {
dst := testutil.RandPeerIDFatal(t)
lst, err := net.Listen("tcp", ":0")
lst, err := net.Listen("tcp4", "0.0.0.0:0")
if err != nil {
t.Fatal(err)
}
Expand Down
27 changes: 27 additions & 0 deletions test/ipfs-test-lib.sh
Expand Up @@ -35,3 +35,30 @@ shellquote() {
done
printf '\n'
}

# Docker

# This takes a directory, that should contain a Dockerfile, as argument
docker_build() {
docker build --rm "$1"
}

# This takes an image as argument and writes a docker ID on stdout
docker_run() {
docker run -it -d -p 8080:8080 -p 4001:4001 -p 5001:5001 "$1"
}

# This takes a docker ID and a command as arguments
docker_exec() {
if test "$CIRCLE" = 1
then
sudo lxc-attach -n "$(docker inspect --format '{{.Id}}' $1)" -- /bin/bash -c "$2"
else
docker exec -i "$1" /bin/bash -c "$2"
fi
}

# This takes a docker ID as argument
docker_stop() {
docker stop "$1"
}
1 change: 1 addition & 0 deletions test/sharness/lib/test-lib.sh
Expand Up @@ -41,6 +41,7 @@ SHARNESS_LIB="lib/sharness/sharness.sh"
# grab + output options
test "$TEST_NO_FUSE" != 1 && test_set_prereq FUSE
test "$TEST_EXPENSIVE" = 1 && test_set_prereq EXPENSIVE
type docker && test_set_prereq DOCKER

if test "$TEST_VERBOSE" = 1; then
echo '# TEST_VERBOSE='"$TEST_VERBOSE"
Expand Down
63 changes: 63 additions & 0 deletions test/sharness/t0300-docker-image.sh
@@ -0,0 +1,63 @@
#!/bin/sh
#
# Copyright (c) 2015 Christian Couder
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test docker image"

. lib/test-lib.sh

# if in travis CI on OSX, docker is not available
if ! test_have_prereq DOCKER; then
skip_all='skipping docker tests, docker not available'

test_done
fi

test_expect_success "'docker --version' works" '
docker --version >actual
'

test_expect_success "'docker --version' output looks good" '
egrep "^Docker version" actual
'

test_expect_success "current user is in the 'docker' group" '
groups | egrep "\bdocker\b"
'

TEST_TRASH_DIR=$(pwd)
TEST_SCRIPTS_DIR=$(dirname "$TEST_TRASH_DIR")
TEST_TESTS_DIR=$(dirname "$TEST_SCRIPTS_DIR")
APP_ROOT_DIR=$(dirname "$TEST_TESTS_DIR")

test_expect_success "docker image build succeeds" '
docker_build "$APP_ROOT_DIR" >actual
'

test_expect_success "docker image build output looks good" '
SUCCESS_LINE=$(egrep "^Successfully built" actual) &&
IMAGE_ID=$(expr "$SUCCESS_LINE" : "^Successfully built \(.*\)") ||
test_fsh cat actual
'

test_expect_success "docker image runs" '
DOC_ID=$(docker_run "$IMAGE_ID")
'

test_expect_success "simple command can be run in docker container" '
docker_exec "$DOC_ID" "echo Hello Worlds" >actual
'

test_expect_success "simple command output looks good" '
echo "Hello Worlds" >expected &&
test_cmp expected actual
'

test_expect_success "stop docker container" '
docker_stop "$DOC_ID"
'

test_done

0 comments on commit dc4f5af

Please sign in to comment.