Merge "Cherry-pick of L2GW environment file"
[apex.git] / build / Makefile
1 ##############################################################################
2 # Copyright (c) 2016 Red Hat Inc.
3 # dradez@redhat.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 export USE_MASTER = ""
11 export CENTDNLD = http://mirrors.cat.pdx.edu/centos/7.4.1708/isos/x86_64/CentOS-7-x86_64-DVD-1708.iso
12 export RELEASE = "0"
13
14 export RPM_DIST = $(shell rpm -E %dist)
15
16 export NETVPP_VERS := $(shell grep Version $(shell pwd)/rpm_specs/networking-vpp.spec | head -n 1 | awk '{ print $$2 }')
17 export NETVPP_REPO := $(shell awk -F\= '/^netvpp_repo/ {print $$2}' variables.sh )
18 export NETVPP_BRANCH := $(shell awk -F\= '/^netvpp_branch/ {print $$2}' variables.sh )
19 export NETVPP_COMMIT := $(shell git ls-remote $(NETVPP_REPO) $(NETVPP_BRANCH) | awk '{print substr($$1,1,7)}')
20
21 export RELRPMVERS = $(shell grep Version $(shell pwd)/rpm_specs/opnfv-apex-release.spec | head -n 1 | awk '{ print $$2 }')
22 export RPMVERS = $(shell grep Version $(shell pwd)/rpm_specs/opnfv-apex.spec | head -n 1 | awk '{ print $$2 }')
23
24 export BUILD_ROOT = $(shell pwd)
25 export BUILD_DIR = $(shell dirname $$(pwd))/.build
26 export CACHE_DIR = $(shell dirname $$(pwd))/.cache
27 export PATCHES_DIR = $(BUILD_ROOT)/patches
28 export QUAGGA_BUILD_DIR = $(BUILD_DIR)/quagga_build_dir
29 export QUAGGA_RPMS_DIR = $(QUAGGA_BUILD_DIR)/rpmbuild
30 export RPM_DIR_ARGS = -D '_topdir $(BUILD_DIR)' -D '_builddir $(BUILD_DIR)' -D '_sourcedir $(BUILD_DIR)' -D '_rpmdir $(BUILD_DIR)' -D '_specdir $(BUILD_DIR)' -D '_srcrpmdir $(BUILD_DIR)'
31
32 export RPMREL = $(BUILD_DIR)/noarch/opnfv-apex-release-$(RPMVERS)-$(shell echo ${RELEASE} | tr -d '_-').noarch.rpm
33 export RPMCOM = $(BUILD_DIR)/noarch/python34-opnfv-apex-$(RPMVERS)-$(shell echo ${RELEASE} | tr -d '_-').noarch.rpm
34 export RPMUDR = $(BUILD_DIR)/noarch/opnfv-apex-undercloud-$(RPMVERS)-$(shell echo ${RELEASE} | tr -d '_-').noarch.rpm
35 export RPMODL = $(BUILD_DIR)/noarch/opnfv-apex-$(RPMVERS)-$(shell echo ${RELEASE} | tr -d '_-').noarch.rpm
36 export RPMONO = $(BUILD_DIR)/noarch/opnfv-apex-onos-$(RPMVERS)-$(shell echo ${RELEASE} | tr -d '_-').noarch.rpm
37 export ISO = $(BUILD_DIR)/release/OPNFV-CentOS-7-x86_64-${RELEASE}.iso
38 export CENTISO = $(BUILD_DIR)/$(shell basename $(CENTDNLD))
39
40 .PHONY: all
41 all: iso
42
43 .PHONY: clean
44 clean:
45         rm -rf $(BUILD_DIR)
46
47 .PHONY: clean-cache
48 clean-cache:
49         rm -rf $(CACHE_DIR)
50
51 .PHONY: images
52 images: undercloud overcloud-full overcloud-opendaylight
53
54 .PHONY: rpms
55 rpms: images common-rpm undercloud-rpm opendaylight-rpm
56
57 .PHONY: rpms-check
58 rpms-check: release-rpm-check common-rpm-check undercloud-rpm-check opendaylight-rpm-check
59
60 .PHONY: rpms-clean
61 rpms-clean:
62         rm -rf $(BUILD_DIR)/noarch
63         rm -rf $(BUILD_DIR)/BUILDROOT
64
65 $(BUILD_DIR)/opnfv-apex-release.tar.gz:
66         mkdir -p $(BUILD_DIR)
67         pushd ../ && git archive --format=tar.gz --prefix=opnfv-apex-release-$(RELRPMVERS)/ HEAD > $(BUILD_DIR)/opnfv-apex-release.tar.gz
68
69 .PHONY: release-rpm-check
70 release-rpm-check: $(BUILD_DIR)/opnfv-apex-release.tar.gz
71         rpmbuild --clean -bi -bl rpm_specs/opnfv-apex-release.spec $(RPM_DIR_ARGS) -D "_release $(shell echo $(RELEASE) | tr -d '_-')"
72
73 .PHONY: release-rpm
74 release-rpm: $(BUILD_DIR)/opnfv-apex-release.tar.gz $(RPMREL)
75
76 $(RPMREL):
77         @echo "Building the Apex Release RPM"
78         # build the release RPM
79         rpmbuild --clean -ba rpm_specs/opnfv-apex-release.spec $(RPM_DIR_ARGS) -D "_release $(shell echo $(RELEASE) | tr -d '_-')"
80
81 $(BUILD_DIR)/opnfv-apex-common.tar.gz:
82         pushd ../ && git archive --format=tar.gz --prefix=opnfv-apex-$(RPMVERS)/ HEAD > $(BUILD_DIR)/opnfv-apex-common.tar.gz
83
84 .PHONY: common-rpm-check
85 common-rpm-check: $(BUILD_DIR)/opnfv-apex-common.tar.gz
86         rpmbuild --clean -bi -bl rpm_specs/opnfv-apex-common.spec $(RPM_DIR_ARGS) -D "_release $(shell echo $(RELEASE) | tr -d '_-')"
87
88 .PHONY: common-rpm
89 common-rpm: $(BUILD_DIR)/opnfv-apex-common.tar.gz $(RPMCOM)
90
91 $(RPMCOM):
92         @echo "Building the Apex Common RPM"
93         # build the common RPM
94         rpmbuild --clean -ba rpm_specs/opnfv-apex-common.spec $(RPM_DIR_ARGS) -D "_release $(shell echo $(RELEASE) | tr -d '_-')"
95
96 ##################
97 #  PYTHON TESTS  #
98 ##################
99
100 .PHONY: python-tests
101 python-tests:
102         tox -e py35
103
104 #######################
105 #  PYTHON PEP8 CHECK  #
106 #######################
107
108 .PHONY: python-pep8-check
109 python-pep8-check:
110         tox -e pep8
111
112 #############
113 #  YAMLLINT #
114 #############
115
116 .PHONY: yamllint
117 yamllint:
118         @echo "Running yamllint against all .yaml files"
119         cd ../ && yamllint $(shell cd ../ && git ls-tree -r HEAD --name-only | grep 'yaml$$')
120 #############
121 #  RPMLINT  #
122 #############
123
124 .PHONY: rpmlint
125 rpmlint:
126         @echo "Running rpmlint against all RPM spec files"
127         rpmlint rpm_specs/*.spec
128
129 ##################
130 # NETWORKING-VPP #
131 ##################
132
133 $(BUILD_DIR)/python-networking-vpp.tar.gz:
134         @echo "Preparing the networking-vpp RPM prerequisites"
135         git clone $(NETVPP_REPO) -b $(NETVPP_BRANCH) $(BUILD_DIR)/python-networking-vpp-$(NETVPP_VERS)
136         tar czf $(BUILD_DIR)/python-networking-vpp.tar.gz -C $(BUILD_DIR) python-networking-vpp-$(NETVPP_VERS)
137
138 .PHONY: networking-vpp-rpm
139 networking-vpp-rpm: $(BUILD_DIR)/noarch/python-networking-vpp-*.noarch.rpm
140
141 $(BUILD_DIR)/noarch/python-networking-vpp-*.noarch.rpm: $(BUILD_DIR)/python-networking-vpp.tar.gz
142         @echo "Building the Networking VPP RPM"
143         rpmbuild --clean -ba --target noarch rpm_specs/networking-vpp.spec $(RPM_DIR_ARGS) -D 'git .git$(NETVPP_COMMIT)'
144
145 ###############
146 #  UNDERCLOUD #
147 ###############
148
149 .PHONY: undercloud
150 undercloud: $(BUILD_DIR)/undercloud.qcow2
151
152 $(BUILD_DIR)/undercloud.qcow2:
153         @echo "Building the Apex Undercloud Image"
154         @./undercloud.sh
155
156 $(BUILD_DIR)/opnfv-apex-undercloud.tar.gz: $(BUILD_DIR)/undercloud.qcow2
157         @echo "Preparing the Apex Undercloud RPM prerequisites"
158         pushd ../ && git archive --format=tar --prefix=opnfv-apex-undercloud-$(RPMVERS)/ HEAD > $(BUILD_DIR)/opnfv-apex-undercloud.tar
159         tar -rf $(BUILD_DIR)/opnfv-apex-undercloud.tar \
160                --xform="s:.*undercloud.qcow2:opnfv-apex-undercloud-$(RPMVERS)/build/undercloud.qcow2:" $(BUILD_DIR)/undercloud.qcow2
161         gzip -f $(BUILD_DIR)/opnfv-apex-undercloud.tar
162
163 .PHONY: undercloud-rpm-check
164 undercloud-rpm-check: $(BUILD_DIR)/opnfv-apex-undercloud.tar.gz
165         rpmbuild --clean -bi -bl rpm_specs/opnfv-apex-undercloud.spec $(RPM_DIR_ARGS) -D "_release $(shell echo $(RELEASE) | tr -d '_-')"
166
167 .PHONY: undercloud-rpm
168 undercloud-rpm: $(BUILD_DIR)/opnfv-apex-undercloud.tar.gz $(RPMUDR)
169
170 $(RPMUDR):
171         @echo "Building the Apex Undercloud RPM"
172         rpmbuild --clean -ba rpm_specs/opnfv-apex-undercloud.spec $(RPM_DIR_ARGS) -D "_release $(shell echo $(RELEASE) | tr -d '_-')"
173
174 ###############
175 #  OVERCLOUD  #
176 ###############
177
178 .PHONY: overcloud-full
179 overcloud-full: $(BUILD_DIR)/overcloud-full.qcow2
180
181 $(BUILD_DIR)/overcloud-full.qcow2: $(BUILD_DIR)/noarch/python-networking-vpp-*.noarch.rpm
182         @echo "Building the Apex Base Overcloud Image"
183         @./overcloud-full.sh
184
185 ###############
186 #    ODL      #
187 ###############
188
189 .PHONY: overcloud-opendaylight
190 overcloud-opendaylight: $(BUILD_DIR)/overcloud-full-opendaylight.qcow2
191
192 $(BUILD_DIR)/overcloud-full-opendaylight.qcow2: $(BUILD_DIR)/overcloud-full.qcow2
193         @echo "Building the Apex OpenDaylight Overcloud Image"
194         @./overcloud-opendaylight.sh
195
196 $(BUILD_DIR)/opnfv-apex.tar.gz: $(BUILD_DIR)/overcloud-full-opendaylight.qcow2
197         tar -czf $(BUILD_DIR)/opnfv-apex.tar.gz --xform="s:.*/:opnfv-apex-$(RPMVERS)/build/:" $(BUILD_DIR)/overcloud-full-opendaylight.qcow2 $(BUILD_DIR)/overcloud-full.initrd $(BUILD_DIR)/overcloud-full.vmlinuz
198
199 .PHONY: opendaylight-rpm-check
200 opendaylight-rpm-check: $(BUILD_DIR)/opnfv-apex.tar.gz
201         rpmbuild --clean -bi -bl rpm_specs/opnfv-apex.spec $(RPM_DIR_ARGS) -D "_release $(shell echo $(RELEASE) | tr -d '_-')"
202
203 .PHONY: opendaylight-rpm
204 opendaylight-rpm: $(BUILD_DIR)/opnfv-apex.tar.gz $(RPMODL)
205
206 $(RPMODL):
207         @echo "Building the Apex OpenDaylight RPM"
208         # build the overcloud RPM
209         rpmbuild --clean -ba rpm_specs/opnfv-apex.spec $(RPM_DIR_ARGS) -D "_release $(shell echo $(RELEASE) | tr -d '_-')"
210
211 ###############
212 #    ONOS     #
213 ###############
214
215 .PHONY: overcloud-onos
216 overcloud-onos: $(BUILD_DIR)/overcloud-full-onos.qcow2
217
218 $(BUILD_DIR)/overcloud-full-onos.qcow2: $(BUILD_DIR)/overcloud-full.qcow2
219         @echo "Building the Apex ONOS Overcloud Image"
220         @./overcloud-onos.sh
221
222 $(BUILD_DIR)/opnfv-apex-onos.tar.gz: $(BUILD_DIR)/overcloud-full-onos.qcow2
223         tar -czf $(BUILD_DIR)/opnfv-apex-onos.tar.gz --xform="s:.*/:opnfv-apex-onos-$(RPMVERS)/build/:" $(BUILD_DIR)/overcloud-full-onos.qcow2
224
225 .PHONY: onos-rpm-check
226 onos-rpm-check: $(BUILD_DIR)/opnfv-apex-onos.tar.gz
227         rpmbuild --clean -bi -bl rpm_specs/opnfv-apex-onos.spec $(RPM_DIR_ARGS) -D "_release $(shell echo $(RELEASE) | tr -d '_-')"
228
229 .PHONY: onos-rpm
230 onos-rpm: $(BUILD_DIR)/opnfv-apex-onos.tar.gz $(RPMONO)
231
232 $(RPMONO):
233         @echo "Building the Apex ONOS RPM"
234         # build the overcloud RPM
235         rpmbuild --clean -ba rpm_specs/opnfv-apex-onos.spec $(RPM_DIR_ARGS) -D "_release $(shell echo $(RELEASE) | tr -d '_-')"
236
237 ###############
238 #    ISO      #
239 ###############
240
241 $(CENTISO):
242         curl $(CENTDNLD) -z $(CENTISO) -o $(CENTISO) --verbose --silent --location
243
244 iso-clean:
245         @rm -Rf $(BUILD_DIR)/centos
246         @rm -Rf $(BUILD_DIR)/release
247         @rm -f $(ISO)
248
249 .PHONY: mount-centiso umount-centiso
250 mount-centiso: $(CENTISO)
251         @echo "Mounting CentOS ISO in $(CENTDIR)"
252         @mkdir -p $(CENTDIR)
253         @fuseiso $(CENTISO) $(CENTDIR)
254
255 umount-centiso:
256         @set +e
257         @echo "Unmounting CentOS ISO from $(CENTDIR)"
258         @fusermount -u $(CENTDIR)
259         @rmdir $(CENTDIR)
260         @set -e
261
262 .PHONY: iso
263 iso:    iso-clean images rpms $(CENTISO)
264         @echo "Building the Apex ISO"
265         @mkdir $(BUILD_DIR)/centos $(BUILD_DIR)/release
266         cd $(BUILD_DIR)/centos && bsdtar -xf ../$(shell basename $(CENTISO))
267         # modify the installer iso's contents
268         @chmod -R u+w $(BUILD_DIR)/centos
269         @cp -f isolinux.cfg $(BUILD_DIR)/centos/isolinux/isolinux.cfg
270         @ln $(RPMCOM) $(BUILD_DIR)/centos/Packages
271         @ln $(RPMUDR) $(BUILD_DIR)/centos/Packages
272         @ln $(RPMODL) $(BUILD_DIR)/centos/Packages
273         # add packages to the centos packages
274         cd $(BUILD_DIR)/centos/Packages && yumdownloader openvswitch jq python34 python34-libs python34-PyYAML python34-setuptools
275         cd $(BUILD_DIR)/centos/Packages && yumdownloader python34-jinja2 python34-markupsafe ansible python34-six python34-cffi
276         cd $(BUILD_DIR)/centos/Packages && yumdownloader ipxe-roms-qemu python34-idna python34-pycparser python-crypto python-httplib2
277         cd $(BUILD_DIR)/centos/Packages && yumdownloader python-jinja2 python-keyczar python-paramiko sshpass python-ecdsa python34-ply
278         cd $(BUILD_DIR)/centos/Packages && yumdownloader libvirt-python python-lxml python-passlib python2-jmespath
279         cd $(BUILD_DIR)/centos/Packages && yumdownloader python34-urllib3 python34-pysocks python34-requests python34-chardet
280         cd $(BUILD_DIR)/centos/Packages && curl -O http://artifacts.opnfv.org/apex/dependencies/python3-ipmi-0.3.0-1.noarch.rpm
281         cd $(BUILD_DIR)/centos/Packages && curl -O http://artifacts.opnfv.org/apex/dependencies/python34-asn1crypto-0.22.0-1.el7.centos.noarch.rpm
282         cd $(BUILD_DIR)/centos/Packages && curl -O http://artifacts.opnfv.org/apex/dependencies/python34-cryptography-2.0.3-1.el7.centos.x86_64.rpm
283         cd $(BUILD_DIR)/centos/Packages && curl -O http://artifacts.opnfv.org/apex/dependencies/python34-iptables-0.12.0-1.el7.centos.x86_64.rpm
284         cd $(BUILD_DIR)/centos/Packages && curl -O http://artifacts.opnfv.org/apex/dependencies/python34-libvirt-3.6.0-1.el7.centos.x86_64.rpm
285         cd $(BUILD_DIR)/centos/Packages && curl -O http://artifacts.opnfv.org/apex/dependencies/python34-pbr-3.1.1-1.el7.centos.x86_64.rpm
286         cd $(BUILD_DIR)/centos/Packages && curl -O http://artifacts.opnfv.org/apex/dependencies/python34-PrettyTable-0.7.2-1.el7.centos.noarch.rpm
287         cd $(BUILD_DIR)/centos/Packages && curl -O http://artifacts.opnfv.org/apex/dependencies/python34-pycrypto-2.6.1-1.el7.centos.x86_64.rpm
288         cd $(BUILD_DIR)/centos/Packages && curl -O http://artifacts.opnfv.org/apex/dependencies/python34-pyghmi-1.0.22-1.el7.centos.noarch.rpm
289         cd $(BUILD_DIR)/centos/Packages && curl -O http://artifacts.opnfv.org/apex/dependencies/python34-virtualbmc-1.2.0-1.el7.centos.noarch.rpm
290         cd $(BUILD_DIR)/centos/Packages && curl -O http://artifacts.opnfv.org/apex/dependencies/python34-smmap2-2.0.3-1.el7.centos.noarch.rpm
291         cd $(BUILD_DIR)/centos/Packages && curl -O http://artifacts.opnfv.org/apex/dependencies/python34-pygerrit2-2.0.3-1.el7.centos.noarch.rpm
292         cd $(BUILD_DIR)/centos/Packages && curl -O http://artifacts.opnfv.org/apex/dependencies/python34-gitdb2-2.0.3-1.el7.centos.noarch.rpm
293         cd $(BUILD_DIR)/centos/Packages && curl -O http://artifacts.opnfv.org/apex/dependencies/python34-GitPython-2.1.7-1.el7.centos.noarch.rpm
294         cd $(BUILD_DIR)/centos/Packages && curl -O http://artifacts.opnfv.org/apex/dependencies/python34-distro-1.2.0-1.el7.centos.noarch.rpm
295         # regenerate yum repo data
296         @echo "Generating new yum metadata"
297         createrepo --update -g $(BUILD_ROOT)/c7-opnfv-x86_64-comps.xml $(BUILD_DIR)/centos
298         # build the iso
299         @echo "Building OPNFV iso"
300         mkisofs -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -V "OPNFV CentOS 7 x86_64" -R -J -v -T -o $(ISO) $(BUILD_DIR)/centos
301         isohybrid $(ISO)
302         @printf "\n\nISO is built at $(ISO)\n\n"
303
304 ##################
305 #  Quagga Clean  #
306 ##################
307 .PHONY: quagga-clean
308 quagga-clean:
309         @rm -rf $(QUAGGA_BUILD_DIR)
310         @sudo yum -y remove zrpc* quagga* c-capnproto* thrift*
311
312 #################
313 #  Quagga+ZRPC  #
314 #################
315 .PHONY: quagga-zrpc
316 quagga-zrpc: quagga-clean thrift-rpm capnproto-rpm quagga-rpm zrpc-rpm
317
318 ##########
319 #  ZRPC  #
320 ##########
321 .PHONY: zrpc-rpm
322 zrpc-rpm: quagga-rpm $(QUAGGA_RPMS_DIR)/zrpcd-%.x86_64.rpm
323
324 $(QUAGGA_RPMS_DIR)/zrpcd-%.x86_64.rpm:
325         @echo "Building ZRPC RPM"
326         @./build_quagga.sh -a zrpc
327
328 ############
329 #  Quagga  #
330 ############
331 .PHONY: quagga-rpm
332 quagga-rpm: $(QUAGGA_RPMS_DIR)/RPMS/x86_64/quagga-1.1.0_%.el7.centos.x86_64.rpm
333
334 $(QUAGGA_RPMS_DIR)/RPMS/x86_64/quagga-1.1.0_%.el7.centos.x86_64.rpm:
335         @echo "Building Quagga RPM"
336         @./build_quagga.sh -a quagga
337
338 ###############
339 #  Capnproto  #
340 ###############
341 .PHONY: capnproto-rpm
342 capnproto-rpm: $(QUAGGA_RPMS_DIR)/RPMS/x86_64/c-capnproto-%.x86_64.rpm
343
344 $(QUAGGA_RPMS_DIR)/RPMS/x86_64/c-capnproto-%.x86_64.rpm:
345         @echo "Building capnproto RPMs"
346         @./build_quagga.sh -a capnproto
347
348 ############
349 #  Thrift  #
350 ############
351
352 .PHONY: thrift-rpm
353 thrift-rpm: $(QUAGGA_RPMS_DIR)/RPMS/x86_64/thrift-%.x86_64.rpm
354
355 $(QUAGGA_RPMS_DIR)/RPMS/x86_64/thrift-%.x86_64.rpm:
356         @echo "Building Thrift RPMs"
357         @./build_quagga.sh -a thrift