summaryrefslogtreecommitdiff
path: root/scripts/docker/Makefile
blob: 41334142151142ae102df24e8ca3eeee364947f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#/usr/bin/env

# 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

#####################################################################
# Some configurations you might override when calling this makefile #
#####################################################################

IMAGE_NAME           ?= "leap/soledad:1.0"
SOLEDAD_REMOTE       ?= "https://0xacab.org/leap/soledad.git"
SOLEDAD_BRANCH       ?= "develop"
SOLEDAD_PRELOAD_NUM  ?= "100"
SOLEDAD_PRELOAD_SIZE ?= "500"

##############################################
# Docker image generation (main make target) #
##############################################

all: image

image:
	docker build -t $(IMAGE_NAME) .

##################################################
# Run a Soledad Server inside a docker container #
##################################################

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=$(SOLEDAD_REMOTE)" \
	  --env="SOLEDAD_BRANCH=$(SOLEDAD_BRANCH)" \
	  --env="SOLEDAD_PRELOAD_NUM=$(SOLEDAD_PRELOAD_NUM)" \
	  --env="SOLEDAD_PRELOAD_SIZE=$(SOLEDAD_PRELOAD_SIZE)" \
	  --cidfile=$(CONTAINER_ID_FILE) \
	  --detach \
	  $(IMAGE_NAME) \
	  /usr/local/soledad/start-server.sh

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=$(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 all trial tests inside a docker container #
#################################################

run-trial-test:
	docker run -t -i \
	  --env="SOLEDAD_REMOTE=$(SOLEDAD_REMOTE)" \
	  --env="SOLEDAD_BRANCH=$(SOLEDAD_BRANCH)" \
	  $(IMAGE_NAME) \
	  /usr/local/soledad/start-trial-test.sh

############################################
# Performance tests and graphic generation #
############################################

run-perf:
	helper/run-test.sh perf

run-perf-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 \
	  --cidfile=$(CONTAINER_ID_FILE)-perf \
	  --env="SOLEDAD_REMOTE=$(SOLEDAD_REMOTE)" \
	  --env="SOLEDAD_BRANCH=$(SOLEDAD_BRANCH)" \
	  --env="SOLEDAD_PERF_REMOTE=https://0xacab.org/drebs/soledad-perf.git" \
	  --env="SOLEDAD_PERF_BRANCH=bug/ensure-events-server" \
	  --env="SOLEDAD_PRELOAD_NUM=$(SOLEDAD_PRELOAD_NUM)" \
	  --env="SOLEDAD_PRELOAD_SIZE=$(SOLEDAD_PRELOAD_SIZE)" \
	  --env="SOLEDAD_STATS=1" \
	  --env="SOLEDAD_SERVER_URL=http://$${server_ip}:2424" \
	  $(IMAGE_NAME) \
	  /usr/local/soledad/run-perf-test.sh

cp-perf-result:
	@if [ -z "$(CONTAINER_ID_FILE)" ]; then \
	  echo "Error: you have to pass a value to CONTAINER_ID_FILE."; \
	  exit 2; \
	fi
	perf_id=`cat $(CONTAINER_ID_FILE)-perf`; \
	docker cp $${perf_id}:/var/local/soledad-perf/out/sync-stats.png /tmp/; \
	docker cp $${perf_id}:/var/local/soledad-perf/out/series.log /tmp/

########################
# Other helper targets #
########################

run-shell: image
	docker run -t -i $(IMAGE_NAME) /bin/bash

rm-all-containers:
	containers=`docker ps -a | cut -d" " -f 1 | tail -n +2 | xargs`; \
	if [ ! -z ${containers} ]; then docker rm -f $${containers}; fi