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