summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scripts/docker/Makefile42
-rwxr-xr-xscripts/docker/helper/run-tests.sh44
2 files changed, 77 insertions, 9 deletions
diff --git a/scripts/docker/Makefile b/scripts/docker/Makefile
index 5e5b345e..9b9ab8f7 100644
--- a/scripts/docker/Makefile
+++ b/scripts/docker/Makefile
@@ -1,31 +1,57 @@
#/usr/bin/env
-IMAGE_NAME = "leap/soledad:1.0"
+# This makefile is intended to aid on running soledad docker images for
+# specific purposes, as running a server, a client or tests.
+#
+# In order to communicate the IP address of one container to another, we make
+# use of a file containing the container id. You have to explicitelly pass the
+# CONTAINER_ID_FILE variable when invoking some of the targets below.
+#
+# Example usage:
+#
+# make run-server CONTAINER_ID_FILE=/tmp/container-id.txt
+# make run-client-test CONTAINER_ID_FILE=/tmp/container-id.txt
+
+
+IMAGE_NAME ?= "leap/soledad:1.0"
+SOLEDAD_REMOTE ?= "https://0xacab.org/leap/soledad.git"
+SOLEDAD_BRANCH ?= "develop"
+
all: image
image:
docker build -t $(IMAGE_NAME) .
-run-server: image
- rm -f $(CONTAINER_ID_FILE)
+run-server:
+ @if [ -z "$(CONTAINER_ID_FILE)" ]; then \
+ echo "Error: you have to pass a value to CONTAINER_ID_FILE."; \
+ exit 2; \
+ fi
docker run \
- --env="SOLEDAD_REMOTE=https://0xacab.org/leap/soledad.git" \
- --env="SOLEDAD_BRANCH=develop" \
+ --env="SOLEDAD_REMOTE=$(SOLEDAD_REMOTE)" \
+ --env="SOLEDAD_BRANCH=$(SOLEDAD_BRANCH)" \
--cidfile=$(CONTAINER_ID_FILE) \
--detach \
$(IMAGE_NAME) \
/usr/local/soledad/start-server.sh
-run-client-test: image
+run-client-test:
+ @if [ -z "$(CONTAINER_ID_FILE)" ]; then \
+ echo "Error: you have to pass a value to CONTAINER_ID_FILE."; \
+ exit 2; \
+ fi
container_id=`cat $(CONTAINER_ID_FILE)`; \
server_ip=`./helper/get-container-ip.sh $${container_id}`; \
docker run -t -i \
- --env="SOLEDAD_REMOTE=https://0xacab.org/leap/soledad.git" \
- --env="SOLEDAD_BRANCH=develop" \
+ --env="SOLEDAD_REMOTE=$(SOLEDAD_REMOTE)" \
+ --env="SOLEDAD_BRANCH=$(SOLEDAD_BRANCH)" \
--env="SOLEDAD_SERVER_URL=http://$${server_ip}:2424" \
$(IMAGE_NAME) \
/usr/local/soledad/start-client-test.sh
+run-shell: image
+ docker run -t -i $(IMAGE_NAME) /bin/bash
+
rm-all-containers:
docker ps -a | cut -d" " -f 1 | tail -n +2 | xargs docker rm -f
diff --git a/scripts/docker/helper/run-tests.sh b/scripts/docker/helper/run-tests.sh
index cee90f6b..bcd7a565 100755
--- a/scripts/docker/helper/run-tests.sh
+++ b/scripts/docker/helper/run-tests.sh
@@ -1,6 +1,48 @@
#!/bin/sh
+# Run 2 docker images, one with soledad server and another with a soledad
+# client running the tests.
+#
+# After launching the server, the script waits for TIMEOUT seconds for it to
+# come up. If we fail to detect the server, the script exits with nonzero
+# status.
+
+
+# seconds to wait before giving up waiting from server
+TIMEOUT=20
+
+# some info from this script
+SCRIPT=$(readlink -f "$0")
+SCRIPTPATH=$(dirname "$SCRIPT")
+
+# run the server
tempfile=`mktemp -u`
make run-server CONTAINER_ID_FILE=${tempfile}
-sleep 5
+
+# get server container info
+container_id=`cat ${tempfile}`
+server_ip=`${SCRIPTPATH}/get-container-ip.sh ${container_id}`
+
+# wait for server until timeout
+start=`date +%s`
+elapsed=0
+
+while [ ${elapsed} -lt ${TIMEOUT} ]; do
+ result=`curl http://${server_ip}:2424`
+ if [ ${?} -eq 0 ]; then
+ break
+ else
+ sleep 1
+ fi
+ now=`date +%s`
+ elapsed=`expr ${now} - ${start}`
+done
+
+# exit with an error code if timed out waiting for server
+if [ ${elapsed} -ge ${TIMEOUT} ]; then
+ echo "Error: server unreacheble at ${server_ip} after ${TIMEOUT} seconds."
+ exit 1
+fi
+
+# run the client
make run-client-test CONTAINER_ID_FILE=${tempfile}