Merge branch '6090-docker-use-local-sso' closes #6138
[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 #shell-image
8 all: skydns-image skydock-image api-image compute-image doc-image workbench-image keep-image keep-proxy-image sso-image
9
10 IMAGE_FILES := $(shell ls *-image 2>/dev/null |grep -v -E 'debian-arvados-image|skydns-image|skydock-image')
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)" = "" ] || rm -f $(IMAGE_FILES) 2>/dev/null
19         +@[ "$(GENERATED_DIRS)" = "" ] || rm -rf */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 keep_proxy_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         -@rm -f skydns-image skydock-image 2>/dev/null
44         +@[ "`$(DOCKER) ps -q`" = '' ] || $(DOCKER) stop `$(DOCKER) ps -q`
45         +@[ "$(REALCLEAN_CONTAINERS)" = '' ] || $(DOCKER) rm $(REALCLEAN_CONTAINERS)
46         +@[ "$(DEEPCLEAN_IMAGES)" = '' ] || $(DOCKER) rmi $(DEEPCLEAN_IMAGES)
47         +@[ "$(SKYDNS_CONTAINERS)" = '' ] || $(DOCKER) rm $(SKYDNS_CONTAINERS)
48         +@[ "$(SKYDNS_IMAGES)" = '' ] || $(DOCKER) rmi $(SKYDNS_IMAGES)
49
50 # ============================================================
51 # Dependencies for */generated files which are prerequisites
52 # for building docker images.
53
54 CONFIG_RB = build_tools/config.rb
55
56 BUILD = build/.buildstamp
57
58 BASE_DEPS = base/Dockerfile config.yml $(BASE_GENERATED)
59
60 SLURM_DEPS = slurm/Dockerfile config.yml $(SLURM_GENERATED)
61
62 JOBS_DEPS = jobs/Dockerfile
63
64 ARV_WEB_DEPS = arv-web/Dockerfile arv-web/apache2_foreground.sh arv-web/apache2_vhost
65
66 JAVA_BWA_SAMTOOLS_DEPS = java-bwa-samtools/Dockerfile
67
68 API_DEPS = api/* config.yml $(API_GENERATED)
69
70 SHELL_DEPS = shell/* config.yml $(SHELL_GENERATED)
71
72 COMPUTE_DEPS = compute/* config.yml $(COMPUTE_GENERATED)
73
74 DOC_DEPS = doc/Dockerfile $(DOC_GENERATED)
75
76 WORKBENCH_DEPS = workbench/Dockerfile \
77                  config.yml \
78                  $(WORKBENCH_GENERATED)
79
80 KEEP_DEPS = keep/Dockerfile config.yml $(KEEP_GENERATED)
81
82 KEEP_PROXY_DEPS = keepproxy/Dockerfile config.yml $(KEEP_PROXY_GENERATED)
83
84 SSO_DEPS = config.yml $(SSO_GENERATED)
85
86 BCBIO_NEXTGEN_DEPS = bcbio-nextgen/Dockerfile
87
88 BASE_GENERATED = base/generated/arvados.tar.gz
89
90 COMPUTE_GENERATED_IN   = compute/*.in
91 COMPUTE_GENERATED      = compute/generated/*
92
93 KEEP_GENERATED_IN      = keep/*.in
94 KEEP_GENERATED         = keep/generated/*
95
96 KEEP_PROXY_GENERATED_IN      = keepproxy/*.in
97 KEEP_PROXY_GENERATED         = keepproxy/generated/*
98
99 API_GENERATED_IN       = api/*.in
100 API_GENERATED          = api/generated/*
101
102 SHELL_GENERATED_IN     = shell/*.in
103 SHELL_GENERATED        = shell/generated/*
104
105 SLURM_GENERATED_IN     = slurm/*.in
106 SLURM_GENERATED        = slurm/generated/*
107
108 WORKBENCH_GENERATED_IN = workbench/*.in
109 WORKBENCH_GENERATED    = workbench/generated/*
110
111 SSO_GENERATED_IN       = sso/*.in
112 SSO_GENERATED          = sso/generated/*
113
114 DOC_GENERATED_IN       = doc/*.in
115 DOC_GENERATED          = doc/generated/*
116
117 KEEP_DEPS += keep/generated/bin/keepproxy
118 KEEP_DEPS += keep/generated/bin/keepstore
119 keep/generated/bin/%: $(wildcard build/services/%/*.go)
120         mkdir -p keep/generated/src/git.curoverse.com
121         ln -sfn ../../../../.. keep/generated/src/git.curoverse.com/arvados.git
122         GOPATH=$(shell pwd)/keep/generated go get $(@:keep/generated/bin/%=git.curoverse.com/arvados.git/services/%)
123
124 KEEP_PROXY_DEPS += keepproxy/generated/bin/keepproxy
125 keepproxy/generated/bin/%: $(wildcard build/services/%/*.go)
126         mkdir -p keepproxy/generated/src/git.curoverse.com
127         ln -sfn ../../../../.. keepproxy/generated/src/git.curoverse.com/arvados.git
128         GOPATH=$(shell pwd)/keepproxy/generated go get $(@:keepproxy/generated/bin/%=git.curoverse.com/arvados.git/services/%)
129
130 $(BUILD):
131         mkdir -p build
132         rsync -rlp --exclude=docker/ --exclude='**/log/*' --exclude='**/tmp/*' \
133                 --chmod=Da+rx,Fa+rX ../ build/
134         find build/ -name \*.gem -delete
135         cd build/services/fuse/ && python setup.py build
136         cd build/sdk/python/ && python setup.py build
137         cd build/sdk/cli && gem build arvados-cli.gemspec
138         cd build/sdk/ruby && gem build arvados.gemspec
139         touch build/.buildstamp
140
141 $(SLURM_GENERATED): $(BUILD)
142         $(CONFIG_RB) slurm
143         mkdir -p slurm/generated
144
145 $(BASE_GENERATED): $(BUILD)
146         $(CONFIG_RB) base
147         mkdir -p base/generated
148         tar -czf base/generated/arvados.tar.gz -C build .
149
150 $(API_GENERATED): $(API_GENERATED_IN)
151         $(CONFIG_RB) api
152
153 $(SHELL_GENERATED): $(SHELL_GENERATED_IN)
154         $(CONFIG_RB) shell
155
156 $(WORKBENCH_GENERATED): $(WORKBENCH_GENERATED_IN)
157         $(CONFIG_RB) workbench
158
159 $(COMPUTE_GENERATED): $(COMPUTE_GENERATED_IN)
160         $(CONFIG_RB) compute
161
162 $(SSO_GENERATED): $(SSO_GENERATED_IN)
163         $(CONFIG_RB) sso
164
165 $(DOC_GENERATED): $(DOC_GENERATED_IN)
166         $(CONFIG_RB) doc
167
168 $(KEEP_GENERATED): $(KEEP_GENERATED_IN)
169         $(CONFIG_RB) keep
170
171 $(KEEP_PROXY_GENERATED): $(KEEP_PROXY_GENERATED_IN)
172         $(CONFIG_RB) keepproxy
173
174 DOCKER_BUILD = $(DOCKER) build --rm=true
175
176 # ============================================================
177 # The main Arvados servers: api, doc, workbench, compute
178
179 api-image: passenger-image $(BUILD) $(API_DEPS)
180         @echo "Building api-image"
181         mkdir -p api/generated
182         tar -czf api/generated/api.tar.gz -C build/services api
183         $(DOCKER_BUILD) -t arvados/api api
184         date >api-image
185
186 shell-image: base-image $(BUILD) $(SHELL_DEPS)
187         @echo "Building shell-image"
188         mkdir -p shell/generated
189         $(DOCKER_BUILD) -t arvados/shell shell
190         date >shell-image
191
192 compute-image: slurm-image $(BUILD) $(COMPUTE_DEPS)
193         @echo "Building compute-image"
194         $(DOCKER_BUILD) -t arvados/compute compute
195         date >compute-image
196
197 doc-image: base-image $(BUILD) $(DOC_DEPS)
198         @echo "Building doc-image"
199         mkdir -p doc/generated
200         tar -czf doc/generated/doc.tar.gz -C build doc
201         $(DOCKER_BUILD) -t arvados/doc doc
202         date >doc-image
203
204 keep-image: debian-arvados-image $(BUILD) $(KEEP_DEPS)
205         @echo "Building keep-image"
206         $(DOCKER_BUILD) -t arvados/keep keep
207         date >keep-image
208
209 keep-proxy-image: debian-arvados-image $(BUILD) $(KEEP_PROXY_DEPS)
210         @echo "Building keep-proxy-image"
211         $(DOCKER_BUILD) -t arvados/keepproxy keepproxy
212         date >keep-proxy-image
213
214 jobs-image: base-image $(BUILD) $(JOBS_DEPS)
215         $(DOCKER_BUILD) -t arvados/jobs jobs
216         date >jobs-image
217
218 java-bwa-samtools-image: jobs-image $(BUILD) $(JAVA_BWA_SAMTOOLS_DEPS)
219         $(DOCKER_BUILD) -t arvados/jobs-java-bwa-samtools java-bwa-samtools
220         date >java-bwa-samtools-image
221
222 bcbio-nextgen-image: $(BUILD) $(BASE_GENERATED) $(BCBIO_NEXTGEN_DEPS)
223         rm -rf bcbio-nextgen/generated
224         cp -r base/generated bcbio-nextgen
225         $(DOCKER_BUILD) -t arvados/bcbio-nextgen bcbio-nextgen
226         date >bcbio-nextgen-image
227
228 workbench-image: passenger-image $(BUILD) $(WORKBENCH_DEPS)
229         @echo "Building workbench-image"
230         mkdir -p workbench/generated
231         tar -czf workbench/generated/workbench.tar.gz -C build/apps workbench
232         $(DOCKER_BUILD) -t arvados/workbench workbench
233         date >workbench-image
234
235 sso-image: passenger-image $(SSO_DEPS)
236         @echo "Building sso-image"
237         $(DOCKER_BUILD) -t arvados/sso sso
238         date >sso-image
239
240 arv-web-image: passenger-image $(ARV_WEB_DEPS)
241         $(DOCKER_BUILD) -t arvados/arv-web arv-web
242         date >arv-web-image
243
244 # ============================================================
245 # The arvados/base image is the base Debian image plus packages
246 # that are dependencies for every Arvados service.
247
248 passenger-image: base-image
249         @echo "Building passenger-image"
250         $(DOCKER_BUILD) -t arvados/passenger passenger
251         date >passenger-image
252
253 slurm-image: base-image $(SLURM_DEPS)
254         @echo "Building slurm-image"
255         $(DOCKER_BUILD) -t arvados/slurm slurm
256         date >slurm-image
257
258 base-image: debian-arvados-image $(BASE_DEPS)
259         @echo "Building base-image"
260         $(DOCKER_BUILD) -t arvados/base base
261         date >base-image
262
263 debian-arvados-image:
264         @echo "Building debian-arvados-image"
265         ./mkimage-debootstrap.sh arvados/debian wheezy ftp://ftp.us.debian.org/debian/
266         date >debian-arvados-image
267
268 skydns-image:
269         @echo "Downloading skydns-image"
270         $(DOCKER) pull crosbymichael/skydns
271         date >skydns-image
272
273 skydock-image:
274         @echo "Downloading skydock-image"
275         $(DOCKER) pull crosbymichael/skydock
276         date >skydock-image