3235: Merge branch 'master' into 3235-top-nav-site-search
[arvados.git] / docker / build_tools / Makefile
1 # This is the 'shell hack'. Call make with DUMP=1 to see the effect.
2 ifdef DUMP
3 OLD_SHELL := $(SHELL)
4 SHELL = $(warning [$@])$(OLD_SHELL) -x
5 endif
6
7 all: skydns-image skydock-image api-image compute-image doc-image workbench-image keep-image sso-image shell-image
8
9 IMAGE_FILES := $(shell ls *-image 2>/dev/null |grep -v debian-arvados-image)
10 GENERATED_FILES := $(shell ls */generated/* 2>/dev/null)
11 GENERATED_DIRS := $(shell ls */generated 2>/dev/null)
12
13 # `make clean' removes the files generated in the build directory
14 # but does not remove any docker images generated in previous builds
15 clean:
16         @echo "make clean"
17         -@rm -rf build
18         +@[ "$(IMAGE_FILES)$(GENERATED_FILES)" = "" ] || rm $(IMAGE_FILES) $(GENERATED_FILES) 2>/dev/null
19         +@[ "$(GENERATED_DIRS)" = "" ] || rmdir */generated 2>/dev/null
20
21 DEBIAN_IMAGE := $(shell $(DOCKER) images -q arvados/debian |head -n1)
22
23 REALCLEAN_CONTAINERS := $(shell $(DOCKER) ps -a |grep -e arvados -e api_server -e keep_server -e doc_server -e workbench_server |cut -f 1 -d' ')
24 REALCLEAN_IMAGES := $(shell $(DOCKER) images -q arvados/* |grep -v $(DEBIAN_IMAGE) 2>/dev/null)
25 DEEPCLEAN_IMAGES := $(shell $(DOCKER) images -q arvados/*)
26 SKYDNS_CONTAINERS := $(shell $(DOCKER) ps -a |grep -e crosbymichael/skydns -e crosbymichael/skydock |cut -f 1 -d' ')
27 SKYDNS_IMAGES := $(shell $(DOCKER) images -q crosbymichael/skyd*)
28
29 # `make realclean' will also remove the Arvados docker images (but not the
30 # arvados/debian image) and force subsequent makes to build the entire chain
31 # from the ground up
32 realclean: clean
33         @echo "make realclean"
34         +@[ "`$(DOCKER) ps -q`" = '' ] || $(DOCKER) stop `$(DOCKER) ps -q`
35         +@[ "$(REALCLEAN_CONTAINERS)" = '' ] || $(DOCKER) rm $(REALCLEAN_CONTAINERS)
36         +@[ "$(REALCLEAN_IMAGES)" = '' ] || $(DOCKER) rmi $(REALCLEAN_IMAGES)
37
38 # `make deepclean' will remove all Arvados docker images and the skydns/skydock
39 # images and force subsequent makes to build the entire chain from the ground up
40 deepclean: clean
41         @echo "make deepclean"
42         -@rm -f debian-arvados-image 2>/dev/null
43         +@[ "`$(DOCKER) ps -q`" = '' ] || $(DOCKER) stop `$(DOCKER) ps -q`
44         +@[ "$(REALCLEAN_CONTAINERS)" = '' ] || $(DOCKER) rm $(REALCLEAN_CONTAINERS)
45         +@[ "$(DEEPCLEAN_IMAGES)" = '' ] || $(DOCKER) rmi $(DEEPCLEAN_IMAGES)
46         +@[ "$(SKYDNS_CONTAINERS)" = '' ] || $(DOCKER) rm $(SKYDNS_CONTAINERS)
47         +@[ "$(SKYDNS_IMAGES)" = '' ] || $(DOCKER) rmi $(SKYDNS_IMAGES)
48
49 # ============================================================
50 # Dependencies for */generated files which are prerequisites
51 # for building docker images.
52
53 CONFIG_RB = build_tools/config.rb
54
55 BUILD = build/.buildstamp
56
57 BASE_DEPS = base/Dockerfile $(BASE_GENERATED)
58
59 SLURM_DEPS = slurm/Dockerfile $(SLURM_GENERATED)
60
61 JOBS_DEPS = jobs/Dockerfile
62
63 JAVA_BWA_SAMTOOLS_DEPS = java-bwa-samtools/Dockerfile
64
65 API_DEPS = api/* $(API_GENERATED)
66
67 SHELL_DEPS = shell/* $(SHELL_GENERATED)
68
69 COMPUTE_DEPS = compute/* $(COMPUTE_GENERATED)
70
71 DOC_DEPS = doc/Dockerfile doc/apache2_vhost
72
73 WORKBENCH_DEPS = workbench/Dockerfile \
74                  $(WORKBENCH_GENERATED)
75
76 KEEP_DEPS = keep/Dockerfile
77
78 SSO_DEPS = $(SSO_GENERATED)
79
80 BCBIO_NEXTGEN_DEPS = bcbio-nextgen/Dockerfile
81
82 BASE_GENERATED = base/generated/arvados.tar.gz
83
84 SLURM_GENERATED = slurm/generated/*
85
86 COMPUTE_GENERATED = compute/generated/setup.sh
87
88 COMPUTE_GENERATED_IN = compute/setup.sh.in
89
90 API_GENERATED = \
91         api/generated/arvados-clients.yml \
92         api/generated/apache2_vhost \
93         api/generated/config_databases.sh \
94         api/generated/database.yml \
95         api/generated/omniauth.rb \
96         api/generated/application.yml \
97         api/generated/setup.sh \
98         api/generated/setup-gitolite.sh \
99         api/generated/slurm.conf \
100         api/generated/superuser_token
101
102 API_GENERATED_IN = \
103         api/arvados-clients.yml.in \
104         api/apache2_vhost.in \
105         api/config_databases.sh.in \
106         api/database.yml.in \
107         api/omniauth.rb.in \
108         api/application.yml.in \
109         api/setup.sh.in \
110         api/setup-gitolite.sh.in \
111         api/slurm.conf.in \
112         api/superuser_token.in
113
114 SHELL_GENERATED = \
115         shell/generated/setup.sh \
116         shell/generated/superuser_token
117
118 SHELL_GENERATED_IN = \
119         shell/setup.sh.in \
120         shell/superuser_token.in
121
122 SLURM_GENERATED = \
123         slurm/generated/slurm.conf
124
125 SLURM_GENERATED_IN = \
126         slurm/slurm.conf.in
127
128 WORKBENCH_GENERATED = \
129         workbench/generated/apache2_vhost \
130         workbench/generated/application.yml
131
132 WORKBENCH_GENERATED_IN = \
133         workbench/apache2_vhost.in \
134         workbench/application.yml.in
135
136 SSO_GENERATED = \
137         sso/generated/apache2_vhost \
138         sso/generated/seeds.rb \
139         sso/generated/secret_token.rb
140
141 SSO_GENERATED_IN = \
142         sso/apache2_vhost.in \
143         sso/seeds.rb.in \
144         sso/secret_token.rb.in
145
146 $(BUILD):
147         mkdir -p build
148         rsync -rlp --exclude=docker/ --exclude='**/log/*' --exclude='**/tmp/*' \
149                 --chmod=Da+rx,Fa+rX ../ build/
150         find build/ -name \*.gem -delete
151         cd build/services/fuse/ && python setup.py build
152         cd build/sdk/python/ && python setup.py build
153         cd build/sdk/cli && gem build arvados-cli.gemspec
154         cd build/sdk/ruby && gem build arvados.gemspec
155         touch build/.buildstamp
156
157 $(SLURM_GENERATED): config.yml $(BUILD)
158         $(CONFIG_RB)
159         mkdir -p slurm/generated
160
161 $(BASE_GENERATED): config.yml $(BUILD)
162         $(CONFIG_RB)
163         mkdir -p base/generated
164         tar -czf base/generated/arvados.tar.gz -C build .
165
166 $(API_GENERATED): config.yml $(API_GENERATED_IN)
167         $(CONFIG_RB)
168
169 $(SHELL_GENERATED): config.yml $(SHELL_GENERATED_IN)
170         $(CONFIG_RB)
171
172 $(WORKBENCH_GENERATED): config.yml $(WORKBENCH_GENERATED_IN)
173         $(CONFIG_RB)
174
175 $(COMPUTE_GENERATED): config.yml $(COMPUTE_GENERATED_IN)
176
177 $(WAREHOUSE_GENERATED): config.yml $(WAREHOUSE_GENERATED_IN)
178         $(CONFIG_RB)
179
180 $(SSO_GENERATED): config.yml $(SSO_GENERATED_IN)
181         $(CONFIG_RB)
182
183 # The docker build -q option suppresses verbose build output.
184 # Necessary to prevent failure on building warehouse; see
185 # https://github.com/dotcloud/docker/issues/3172
186 DOCKER_BUILD = $(DOCKER) build -q --rm=true
187
188 # ============================================================
189 # The main Arvados servers: api, doc, workbench, warehouse
190
191 api-image: passenger-image $(BUILD) $(API_DEPS)
192         @echo "Building api-image"
193         mkdir -p api/generated
194         tar -czf api/generated/api.tar.gz -C build/services api
195         chmod 755 api/generated/setup.sh
196         chmod 755 api/generated/setup-gitolite.sh
197         $(DOCKER_BUILD) -t arvados/api api
198         date >api-image
199
200 shell-image: base-image $(BUILD) $(SHELL_DEPS)
201         @echo "Building shell-image"
202         mkdir -p shell/generated
203         chmod 755 shell/generated/setup.sh
204         $(DOCKER_BUILD) -t arvados/shell shell
205         date >shell-image
206
207 compute-image: slurm-image $(BUILD) $(COMPUTE_DEPS)
208         @echo "Building compute-image"
209         chmod 755 compute/generated/setup.sh
210         $(DOCKER_BUILD) -t arvados/compute compute
211         date >compute-image
212
213 doc-image: base-image $(BUILD) $(DOC_DEPS)
214         @echo "Building doc-image"
215         mkdir -p doc/generated
216         tar -czf doc/generated/doc.tar.gz -C build doc
217         $(DOCKER_BUILD) -t arvados/doc doc
218         date >doc-image
219
220 keep-image: debian-arvados-image $(BUILD) $(KEEP_DEPS)
221         @echo "Building keep-image"
222         $(DOCKER_BUILD) -t arvados/keep keep
223         date >keep-image
224
225 jobs-image: base-image $(BUILD) $(JOBS_DEPS)
226         $(DOCKER_BUILD) -t arvados/jobs jobs
227         date >jobs-image
228
229 java-bwa-samtools-image: jobs-image $(BUILD) $(JAVA_BWA_SAMTOOLS_DEPS)
230         $(DOCKER_BUILD) -t arvados/jobs-java-bwa-samtools java-bwa-samtools
231         date >java-bwa-samtools-image
232
233 bcbio-nextgen-image: $(BUILD) $(BASE_GENERATED) $(BCBIO_NEXTGEN_DEPS)
234         rm -rf bcbio-nextgen/generated
235         cp -r base/generated bcbio-nextgen
236         $(DOCKER_BUILD) -t arvados/bcbio-nextgen bcbio-nextgen
237         date >bcbio-nextgen-image
238
239 workbench-image: passenger-image $(BUILD) $(WORKBENCH_DEPS)
240         @echo "Building workbench-image"
241         mkdir -p workbench/generated
242         tar -czf workbench/generated/workbench.tar.gz -C build/apps workbench
243         $(DOCKER_BUILD) -t arvados/workbench workbench
244         date >workbench-image
245
246 warehouse-image: base-image $(WAREHOUSE_DEPS)
247         $(DOCKER_BUILD) -t arvados/warehouse warehouse
248         date >warehouse-image
249
250 sso-image: passenger-image $(SSO_DEPS)
251         @echo "Building sso-image"
252         $(DOCKER_BUILD) -t arvados/sso sso
253         date >sso-image
254
255 # ============================================================
256 # The arvados/base image is the base Debian image plus packages
257 # that are dependencies for every Arvados service.
258
259 passenger-image: base-image
260         @echo "Building passenger-image"
261         $(DOCKER_BUILD) -t arvados/passenger passenger
262         date >passenger-image
263
264 slurm-image: base-image $(SLURM_DEPS)
265         @echo "Building slurm-image"
266         $(DOCKER_BUILD) -t arvados/slurm slurm
267         date >slurm-image
268
269 base-image: debian-arvados-image $(BASE_DEPS)
270         @echo "Building base-image"
271         $(DOCKER_BUILD) -t arvados/base base
272         date >base-image
273
274 debian-arvados-image:
275         @echo "Building debian-arvados-image"
276         ./mkimage-debootstrap.sh arvados/debian wheezy ftp://ftp.us.debian.org/debian/
277         date >debian-arvados-image
278
279 skydns-image:
280         @echo "Downloading skydns-image"
281         $(DOCKER) pull crosbymichael/skydns
282         date >skydns-image
283
284 skydock-image:
285         @echo "Downloading skydock-image"
286         $(DOCKER) pull crosbymichael/skydock
287         date >skydock-image