Do not create files when check connectivity
[fuel.git] / build / Makefile
1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 # stefan.k.berg@ericsson.com
4 # jonas.bjurel@ericsson.com
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 SHELL = /bin/bash
12
13 # This file will be created if needed by runcontext to contain proxy
14 # settings.
15 -include environment.mk
16
17 ############################################################################
18 # BEGIN of variables to customize
19 #
20 #Input args
21 export MOSVERSION = 9.0
22 export ISOSRC = file:$(shell pwd)/fuel-$(MOSVERSION).iso
23 export ISOCACHE = $(shell pwd)/$(shell basename $(ISOSRC))
24 export PRODNO = "OPNFV_FUEL"
25 export REVSTATE = "P0000"
26 export USER ?= $(shell whoami)
27
28 ifdef BUILD_FUEL_PLUGINS
29 $(warning Overriding plugin build selection to $(BUILD_FUEL_PLUGINS))
30 export NEWISO = $(shell pwd)/release/unofficial-opnfv-${REVSTATE}.iso
31 else
32 export NEWISO = $(shell pwd)/release/opnfv-${REVSTATE}.iso
33 endif
34
35 # Note! Invoke with "make REVSTATE=RXXXX all" to make release build!
36 # Invoke with ICOCACHE=/full/path/to/iso if cached ISO is in non-standard location.
37
38 # Build variables
39 export BUILD_BASE := $(shell pwd)
40 export DEB_DEST := $(BUILD_BASE)/release/packages/ubuntu/pool/main
41 export UDEB_DEST := $(BUILD_BASE)/release/packages/ubuntu/pool/debian-installer
42 export PUPPET_DEST := $(BUILD_BASE)/release/puppet/modules
43 export VERSION_FILE := $(BUILD_BASE)/.versions
44 export DOCKERIMG = opnfv.org/ubuntu-builder:14.04
45 export TOPDIR := $(shell pwd)
46 export REPOINFO  := $(BUILD_BASE)/repo_info.sh
47
48 # Use snapshots
49 # Use nearby repositories
50 export MIRROR_UBUNTU_URL := $(shell ./f_isoroot/f_repobuild/select_ubuntu_repo.sh --url)
51 export MIRROR_UBUNTU := $(shell echo "$(MIRROR_UBUNTU_URL)" | cut -d'/' -f3 )
52 export MIRROR_UBUNTU_ROOT := $(shell echo -n '/' ; echo "$(MIRROR_UBUNTU_URL)" | cut -d'/' -f4-)
53
54 export LATEST_MIRROR_ID_URL := http://$(shell ./select_closest_fuel_mirror.py)
55
56 export MIRROR_MOS_UBUNTU := $(shell echo "$(LATEST_MIRROR_ID_URL)" | cut -d'/' -f3)
57 export LATEST_TARGET_UBUNTU := $(shell curl -sSf "$(MIRROR_MOS_UBUNTU)/mos-repos/ubuntu/$(MOSVERSION).target.txt" | head -1)
58 export MIRROR_MOS_UBUNTU_ROOT := /mos-repos/ubuntu/$(LATEST_TARGET_UBUNTU)
59
60 export LATEST_TARGET_CENTOS := $(shell curl -sSf "$(LATEST_MIRROR_ID_URL)/mos-repos/centos/mos$(MOSVERSION)-centos7/os.target.txt" | head -1)
61 export MIRROR_FUEL := "$(LATEST_MIRROR_ID_URL)/mos-repos/centos/mos$(MOSVERSION)-centos7/$(LATEST_TARGET_CENTOS)/x86_64"
62
63 # uncomment and use: make print-VARIABLE
64 #print-%  : ; @echo $* = $($*)
65
66 #Build subclasses
67
68 SUBDIRS := f_isoroot
69
70 # f_example is only an example of how to generate a .deb package and
71 # should not be enabled in official builds.
72 #SUBDIRS += f_example
73
74 ORIGDIR := $(TOPDIR)/origiso
75 #
76 # END of variables to customize
77 #############################################################################
78
79 SUBCLEAN = $(addsuffix .clean,$(SUBDIRS))
80
81 .PHONY: all
82 all:
83         @docker version >/dev/null 2>&1 || (echo 'No Docker installation available'; exit 1)
84         @make -C docker
85         @lsb_release -a | grep Ubuntu > /dev/null 2>&1 || (echo 'Ubuntu is the only supported Linux distribution for this build system'; exit 1)
86         @KERNEL_VER=$$(uname -r); \
87         KERNEL_ARRAY=($${KERNEL_VER//./ }); \
88         if [ $${KERNEL_ARRAY[0]} -lt 3  ] || [[ $${KERNEL_ARRAY[0]} -eq 3 && $${KERNEL_ARRAY[1]} -lt 19  ]] ; then (echo 'Kernel version must be 3.19 or newer'; exit 1) ; fi
89         @docker/runcontext $(DOCKERIMG) wget -q www.google.com -O /dev/null || (echo 'No docker network connectivity or name server - check your network- and docker settings'; exit 1)
90         @docker/runcontext $(DOCKERIMG) $(MAKE) $(MAKEFLAGS) iso
91
92
93 ############################################################################
94 # BEGIN of Include definitions
95 #
96 include config.mk
97 include cache.mk
98 #
99 # END Include definitions
100 #############################################################################
101
102 $(ISOCACHE):
103         # Clone Fuel to non-persistent location and build
104         if [ ! -d /tmp/fuel-main ]; then \
105                 cd /tmp && git clone $(FUEL_MAIN_REPO); \
106         fi
107         cd /tmp/fuel-main && git checkout $(FUEL_MAIN_TAG)
108         @echo "fuel" `git -C /tmp/fuel-main show | grep commit | head -1 | cut -d " " -f2` >> $(VERSION_FILE)
109         # Patch for using the Czech Fuel mirror
110         cd /tmp/fuel-main && patch -p0 < $(TOPDIR)/repo-mirror-cz.patch
111         # Remove Docker optimizations, otherwise multistrap will fail during
112         # Fuel build.
113         sudo rm -f /etc/apt/apt.conf.d/docker*
114         #
115         # Need to replace the old Docker v. 1.5.0 with a later version to be
116         # able to access the Docker remote repository!
117         sudo apt-get install apt-transport-https ca-certificates -y
118         sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
119         echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list
120         sudo apt-get update -y
121         sudo apt-get install docker-engine -y
122         sudo sh -c 'echo DOCKER_OPTS=\"--bip 172.45.0.1/24\" > /etc/default/docker'
123         sudo service docker stop || exit 0
124         sudo service docker start
125
126         cd /tmp/fuel-main && ./prepare-build-env.sh
127         # Verify that Docker is alive
128         sudo docker info
129         cd /tmp/fuel-main && make repos
130         $(REPOINFO) -r /tmp/fuel-main > gitinfo_fuel.txt
131         # OPNFV patches at Fuel build time
132         # Need to be commited in order for them to be considered by the Fuel
133         # build system
134         cd /tmp/fuel-main/iso && git config user.name "Fuel OPNFV"
135         cd /tmp/fuel-main/iso && git config user.email "fuel@opnfv.org"
136         cd /tmp/fuel-main/iso && patch -p0 < $(TOPDIR)/bootstrap_admin_node.sh.patch
137         cd /tmp/fuel-main/iso && git add -u bootstrap_admin_node.sh
138         cd /tmp/fuel-main/iso/isolinux && patch -p0 <  $(TOPDIR)/isolinux.cfg.patch
139         cd /tmp/fuel-main/iso/isolinux && git add -u isolinux.cfg
140         cd /tmp/fuel-main/iso && git commit -m "Added OPNFV patches"
141         # Repeat build up to three times
142         sudo -E ./fuel_build_loop
143         cp /tmp/fuel-main/build/artifacts/fuel*.iso .
144         # Store artifact in cache straight away if caching is enabled
145         # (no .cacheid will be present unless this is a cached build)
146         test -f .cacheid && $(MAKE) -f Makefile put-cache || exit 0
147
148 .PHONY: mount-origiso umount-origiso
149 mount-origiso: $(ISOCACHE)
150         @echo "Mounting original ISO in $(ORIGDIR)"
151         @mkdir -p $(ORIGDIR)
152         @fuseiso $(ISOCACHE) $(ORIGDIR)
153
154 umount-origiso:
155         @echo "Unmounting original ISO from $(ORIGDIR)"
156         @fusermount -u $(ORIGDIR)
157         @rmdir $(ORIGDIR)
158
159 .PHONY: $(SUBDIRS)
160 $(SUBDIRS):
161         @mkdir -p release/packages/ubuntu/pool/main release/packages/ubuntu/pool/debian-installer release/puppet/modules release/isoroot
162         $(MAKE) -C $@ -f Makefile release
163
164 .PHONY: patch-packages
165 patch-packages:
166         ORIGISO=$(ISOCACHE) REVSTATE=$(REVSTATE) $(MAKE) -C $@ -f Makefile release
167
168 .PHONY: clean $(SUBCLEAN)
169 clean:  $(SUBCLEAN)
170         $(MAKE) -C patch-packages -f Makefile clean
171         @rm -f *.iso
172         @rm -Rf release
173         @rm -Rf newiso
174         @rm -Rf .versions
175         @rm -f $(NEWISO)
176         @rm -f $(BUILD_BASE)/gitinfo_*.txt
177
178 .PHONY: deepclean
179 deepclean: clean clean-cache
180         make -C docker clean
181         docker rmi opnfv.org/ubuntu-builder:14.04 &>/dev/null || exit 0
182         docker rmi opnfv.org/ubuntu-builder:latest &>/dev/null || exit 0
183         docker rmi ubuntu:14.04 &>/dev/null || exit 0
184         @if docker images | grep -q "ubuntu *14.04"; then \
185                 echo "Error: ubuntu:14.04 still present!"; \
186                 exit 1; \
187         fi
188         @if docker images | grep -q "opnfv.org/ubuntu-builder"; then \
189                 echo "Error: opnfv.org/ubuntu-builder still present!"; \
190                 exit 1; \
191         fi
192
193 $(SUBCLEAN): %.clean:
194         $(MAKE) -C $* -f Makefile clean
195
196 .PHONY: setup-env
197 setup-env:
198         @if [ -f environment.mk ]; then \
199                 sudo bash -c "cat environment.mk >> /etc/environment"; \
200         fi
201
202 # Todo: Make things smarter - we shouldn't need to clean everything
203 # betwen make invocations.
204 .PHONY: iso
205 iso:    setup-env $(ISOCACHE) $(SUBDIRS) patch-packages
206         $(REPOINFO) . > gitinfo_main.txt
207         install/install.sh iso $(ISOCACHE) $(NEWISO) $(PRODNO) $(REVSTATE)
208         @printf "\n\nProduct ISO is $(NEWISO)\n\n"
209
210 # Start a bash shell in docker for Makefile debugging
211 .PHONY: debug
212 debug:
213         @docker version >/dev/null 2>&1 || (echo 'No Docker installation available'; exit 1)
214         @make -C docker
215         docker/runcontext $(DOCKERIMG) debug
216
217 #############################################################################
218 # Cache operations - only used when building through ci/build.sh
219 #############################################################################
220
221 # Create a unique hash to be used for getting and putting cache, based on:
222 #   - The commit ID of the full Fuel repo structre
223 #   - The contents of all local Fuel patches
224 .cacheid:
225         cd /tmp && git clone $(FUEL_MAIN_REPO)
226         cd /tmp/fuel-main && git checkout $(FUEL_MAIN_TAG)
227         cd /tmp/fuel-main && make repos
228         $(REPOINFO) -r /tmp/fuel-main > .cachedata
229         sha1sum *.patch >> .cachedata
230         sha1sum fuel_build_loop >> .cachedata
231         sha1sum config.mk >> .cachedata
232         sha1sum Makefile >> .cachedata
233         $(CACHETOOL) getbiweek >> .cachedata
234         cat .cachedata | $(CACHETOOL) getid > .cacheid
235         # Not removing fuel-main as it is re-used in build
236
237 # Clean local data related to caching - called prior to ordinary build
238 .PHONY: clean-cache
239 clean-cache: $(SUBCLEANCACHE)
240         rm -f .cachedata .cacheid
241
242 # Try to download cache - called prior to ordinary build
243 .PHONY: get-cache
244 get-cache: .cacheid
245         @if $(CACHETOOL) check $(shell cat .cacheid); then \
246                  $(CACHETOOL) get $(shell cat .cacheid) | tar xf -;\
247         else \
248                 exit 0;\
249         fi
250
251 # Store cache if not already stored - called after ordinary build
252 .PHONY: put-cache
253 put-cache: .cacheid
254         @tar cf - fuel*.iso gitinfo_fuel.txt | $(CACHETOOL) put $(shell cat .cacheid)