summaryrefslogtreecommitdiff
path: root/scripts/docker/Makefile
blob: 1bb57757c450507cddc669b597412874634987b9 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#/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-perf 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
MEMORY               ?= 512m

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

all: soledad-image couchdb-image

soledad-image:
	docker build -t $(IMAGE_NAME) .

couchdb-image:
	(cd couchdb/ && make)

##################################################
# 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 \
	  --memory="$(MEMORY)" \
	  --cpuset-cpus=0 \
	  --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/run-server.sh # --drop-to-shell

run-client-bootstrap:
	@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 \
	  --memory="$(MEMORY)" \
	  --env="SOLEDAD_REMOTE=$(SOLEDAD_REMOTE)" \
	  --env="SOLEDAD_BRANCH=$(SOLEDAD_BRANCH)" \
	  --env="SOLEDAD_SERVER_URL=http://$${server_ip}:2424" \
	  $(IMAGE_NAME) \
	  /usr/local/soledad/run-client-bootstrap.sh

#################################################
# Run all tests inside a docker container       #
#################################################

run-tox:
	name=$$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 5 | head -n 1); \
	docker run -d --name $${name} leap/couchdb; \
	docker run -t -i \
	  --memory="$(MEMORY)" \
	  --env="SOLEDAD_REMOTE=$(SOLEDAD_REMOTE)" \
	  --env="SOLEDAD_BRANCH=$(SOLEDAD_BRANCH)" \
	  --env="COUCH_URL=http://$${name}:5984" \
	  --link $${name} \
	  $(IMAGE_NAME) \
	  /usr/local/soledad/run-tox.sh

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

run-perf:
	name=$$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 5 | head -n 1); \
	docker run -d --name $${name} leap/couchdb; \
	docker run -t -i \
	  --memory="$(MEMORY)" \
	  --env="SOLEDAD_REMOTE=$(SOLEDAD_REMOTE)" \
	  --env="SOLEDAD_BRANCH=$(SOLEDAD_BRANCH)" \
	  --env="SOLEDAD_PRELOAD_NUM=$(SOLEDAD_PRELOAD_NUM)" \
	  --env="COUCH_URL=http://$${name}:5984" \
	  --link $${name} \
	  $(IMAGE_NAME) \
	  /usr/local/soledad/run-perf.sh

run-client-perf:
	@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 \
	  --memory="$(MEMORY)" \
	  --cpuset-cpus=1 \
	  --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" \
	  --env="SOLEDAD_LOG=1" \
	  $(IMAGE_NAME) \
	  /usr/local/soledad/run-client-perf.sh # --drop-to-shell

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: soledad-image
	docker run -t -i \
	  --memory="$(MEMORY)" \
	  $(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