From 29ec4c06e4358457fadd5d672cd9657d77e6d460 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Mon, 14 Dec 2015 22:59:00 +0100 Subject: [PATCH] test/ipfs-test-lib: add docker support We have to do something special for CircleCI in docker_exec() because "docker exec" doesn't work on CircleCi: https://circleci.com/docs/docker#docker-exec We indeed get "Unsupported: Exec is not supported by the lxc driver" with CircleCi, when using "docker exec". License: MIT Signed-off-by: Christian Couder --- circle.yml | 1 + test/ipfs-test-lib.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/circle.yml b/circle.yml index a431e520b..13f2ad543 100644 --- a/circle.yml +++ b/circle.yml @@ -3,6 +3,7 @@ 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 diff --git a/test/ipfs-test-lib.sh b/test/ipfs-test-lib.sh index b05287c2e..8ba04e8ee 100644 --- a/test/ipfs-test-lib.sh +++ b/test/ipfs-test-lib.sh @@ -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" +}