3261: Reduce dependency bloat: process templates one dir at a time.
[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 LIST_GENERATED_FILES = build_tools/list_generated_files
56
57 BUILD = build/.buildstamp
58
59 BASE_DEPS = base/Dockerfile config.yml $(BASE_GENERATED)
60
61 SLURM_DEPS = slurm/Dockerfile config.yml $(SLURM_GENERATED)
62
63 JOBS_DEPS = jobs/Dockerfile
64
65 JAVA_BWA_SAMTOOLS_DEPS = java-bwa-samtools/Dockerfile
66
67 API_DEPS = api/* config.yml $(API_GENERATED)
68
69 SHELL_DEPS = shell/* config.yml $(SHELL_GENERATED)
70
71 COMPUTE_DEPS = compute/* config.yml $(COMPUTE_GENERATED)
72
73 DOC_DEPS = doc/Dockerfile doc/apache2_vhost
74
75 WORKBENCH_DEPS = workbench/Dockerfile \
76                  config.yml \
77                  $(WORKBENCH_GENERATED)
78
79 KEEP_DEPS = keep/Dockerfile config.yml $(KEEP_GENERATED)
80
81 SSO_DEPS = config.yml $(SSO_GENERATED)
82
83 BCBIO_NEXTGEN_DEPS = bcbio-nextgen/Dockerfile
84
85 BASE_GENERATED = base/generated/arvados.tar.gz
86
87 COMPUTE_GENERATED_IN   = $(shell ls compute/*.in)
88 COMPUTE_GENERATED      = $(shell $(LIST_GENERATED_FILES) $(COMPUTE_GENERATED_IN))
89
90 KEEP_GENERATED_IN      = $(shell ls keep/*.in)
91 KEEP_GENERATED         = $(shell $(LIST_GENERATED_FILES) $(KEEP_GENERATED_IN))
92
93 API_GENERATED_IN       = $(shell ls api/*.in)
94 API_GENERATED          = $(shell $(LIST_GENERATED_FILES) $(API_GENERATED_IN))
95
96 SHELL_GENERATED_IN     = $(shell ls shell/*.in)
97 SHELL_GENERATED        = $(shell $(LIST_GENERATED_FILES) $(SHELL_GENERATED_IN))
98
99 SLURM_GENERATED_IN     = $(shell ls slurm/*.in)
100 SLURM_GENERATED        = $(shell $(LIST_GENERATED_FILES) $(SLURM_GENERATED_IN))
101
102 WORKBENCH_GENERATED_IN = $(shell ls workbench/*.in)
103 WORKBENCH_GENERATED    = $(shell $(LIST_GENERATED_FILES) $(WORKBENCH_GENERATED_IN))
104
105 SSO_GENERATED_IN       = $(shell ls sso/*.in)
106 SSO_GENERATED          = $(shell $(LIST_GENERATED_FILES) $(SSO_GENERATED_IN))
107
108 $(BUILD):
109         mkdir -p build
110         rsync -rlp --exclude=docker/ --exclude='**/log/*' --exclude='**/tmp/*' \
111                 --chmod=Da+rx,Fa+rX ../ build/
112         find build/ -name \*.gem -delete
113         cd build/services/fuse/ && python setup.py build
114         cd build/sdk/python/ && python setup.py build
115         cd build/sdk/cli && gem build arvados-cli.gemspec
116         cd build/sdk/ruby && gem build arvados.gemspec
117         touch build/.buildstamp
118
119 $(SLURM_GENERATED): $(BUILD)
120         $(CONFIG_RB) slurm
121         mkdir -p slurm/generated
122
123 $(BASE_GENERATED): $(BUILD)
124         $(CONFIG_RB) base
125         mkdir -p base/generated
126         tar -czf base/generated/arvados.tar.gz -C build .
127
128 $(API_GENERATED): $(API_GENERATED_IN)
129         $(CONFIG_RB) api
130
131 $(SHELL_GENERATED): $(SHELL_GENERATED_IN)
132         $(CONFIG_RB) shell
133
134 $(WORKBENCH_GENERATED): $(WORKBENCH_GENERATED_IN)
135         $(CONFIG_RB) workbench
136
137 $(COMPUTE_GENERATED): $(COMPUTE_GENERATED_IN)
138         $(CONFIG_RB) compute
139
140 $(SSO_GENERATED): $(SSO_GENERATED_IN)
141         $(CONFIG_RB) sso
142
143 $(KEEP_GENERATED): $(KEEP_GENERATED_IN)
144         $(CONFIG_RB) keep
145
146 # The docker build -q option suppresses verbose build output.
147 # Necessary to prevent failure on building warehouse; see
148 # https://github.com/dotcloud/docker/issues/3172
149 DOCKER_BUILD = $(DOCKER) build -q --rm=true
150
151 # ============================================================
152 # The main Arvados servers: api, doc, workbench, compute
153
154 api-image: passenger-image $(BUILD) $(API_DEPS)
155         @echo "Building api-image"
156         mkdir -p api/generated
157         tar -czf api/generated/api.tar.gz -C build/services api
158         chmod 755 api/generated/setup.sh
159         chmod 755 api/generated/setup-gitolite.sh
160         $(DOCKER_BUILD) -t arvados/api api
161         date >api-image
162
163 shell-image: base-image $(BUILD) $(SHELL_DEPS)
164         @echo "Building shell-image"
165         mkdir -p shell/generated
166         chmod 755 shell/generated/setup.sh
167         $(DOCKER_BUILD) -t arvados/shell shell
168         date >shell-image
169
170 compute-image: slurm-image $(BUILD) $(COMPUTE_DEPS)
171         @echo "Building compute-image"
172         chmod 755 compute/generated/setup.sh
173         $(DOCKER_BUILD) -t arvados/compute compute
174         date >compute-image
175
176 doc-image: base-image $(BUILD) $(DOC_DEPS)
177         @echo "Building doc-image"
178         mkdir -p doc/generated
179         tar -czf doc/generated/doc.tar.gz -C build doc
180         $(DOCKER_BUILD) -t arvados/doc doc
181         date >doc-image
182
183 keep-image: debian-arvados-image $(BUILD) $(KEEP_DEPS)
184         @echo "Building keep-image"
185         $(DOCKER_BUILD) -t arvados/keep keep
186         date >keep-image
187
188 jobs-image: base-image $(BUILD) $(JOBS_DEPS)
189         $(DOCKER_BUILD) -t arvados/jobs jobs
190         date >jobs-image
191
192 java-bwa-samtools-image: jobs-image $(BUILD) $(JAVA_BWA_SAMTOOLS_DEPS)
193         $(DOCKER_BUILD) -t arvados/jobs-java-bwa-samtools java-bwa-samtools
194         date >java-bwa-samtools-image
195
196 bcbio-nextgen-image: $(BUILD) $(BASE_GENERATED) $(BCBIO_NEXTGEN_DEPS)
197         rm -rf bcbio-nextgen/generated
198         cp -r base/generated bcbio-nextgen
199         $(DOCKER_BUILD) -t arvados/bcbio-nextgen bcbio-nextgen
200         date >bcbio-nextgen-image
201
202 workbench-image: passenger-image $(BUILD) $(WORKBENCH_DEPS)
203         @echo "Building workbench-image"
204         mkdir -p workbench/generated
205         tar -czf workbench/generated/workbench.tar.gz -C build/apps workbench
206         $(DOCKER_BUILD) -t arvados/workbench workbench
207         date >workbench-image
208
209 sso-image: passenger-image $(SSO_DEPS)
210         @echo "Building sso-image"
211         $(DOCKER_BUILD) -t arvados/sso sso
212         date >sso-image
213
214 # ============================================================
215 # The arvados/base image is the base Debian image plus packages
216 # that are dependencies for every Arvados service.
217
218 passenger-image: base-image
219         @echo "Building passenger-image"
220         $(DOCKER_BUILD) -t arvados/passenger passenger
221         date >passenger-image
222
223 slurm-image: base-image $(SLURM_DEPS)
224         @echo "Building slurm-image"
225         $(DOCKER_BUILD) -t arvados/slurm slurm
226         date >slurm-image
227
228 base-image: debian-arvados-image $(BASE_DEPS)
229         @echo "Building base-image"
230         $(DOCKER_BUILD) -t arvados/base base
231         date >base-image
232
233 debian-arvados-image:
234         @echo "Building debian-arvados-image"
235         ./mkimage-debootstrap.sh arvados/debian wheezy ftp://ftp.us.debian.org/debian/
236         date >debian-arvados-image
237
238 skydns-image:
239         @echo "Downloading skydns-image"
240         $(DOCKER) pull crosbymichael/skydns
241         date >skydns-image
242
243 skydock-image:
244         @echo "Downloading skydock-image"
245         $(DOCKER) pull crosbymichael/skydock
246         date >skydock-image