Bump sfc scenario to ODL 5.2.0-1
[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 = 10.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 export BUILD_DATE = $(shell date --utc +%Y-%m-%d:%H:%M)
28 export OPNFV_GIT_SHA ?= $(shell git rev-parse HEAD)
29 # Store in /etc/fuel_build_id on fuel master
30 export BUILD_ID := $(PRODNO)_$(BUILD_DATE)_$(OPNFV_GIT_SHA)
31
32 ifdef BUILD_FUEL_PLUGINS
33 $(warning Overriding plugin build selection to $(BUILD_FUEL_PLUGINS))
34 export NEWISO = $(shell pwd)/release/unofficial-opnfv-${REVSTATE}.iso
35 else
36 export NEWISO = $(shell pwd)/release/opnfv-${REVSTATE}.iso
37 endif
38
39 # Note! Invoke with "make REVSTATE=RXXXX all" to make release build!
40 # Invoke with ICOCACHE=/full/path/to/iso if cached ISO is in non-standard location.
41
42 # Build variables
43 export BUILD_BASE := $(shell pwd)
44 export DEB_DEST := $(BUILD_BASE)/release/packages/ubuntu/pool/main
45 export UDEB_DEST := $(BUILD_BASE)/release/packages/ubuntu/pool/debian-installer
46 export PUPPET_DEST := $(BUILD_BASE)/release/puppet/modules
47 export VERSION_FILE := $(BUILD_BASE)/.versions
48 export DOCKERIMG = opnfv.org/ubuntu-builder:14.04
49 export TOPDIR := $(shell pwd)
50 export REPOINFO  := $(BUILD_BASE)/repo_info.sh
51
52 # Use snapshots
53 # Use nearby repositories
54 export MIRROR_UBUNTU_URL ?= $(shell ./f_isoroot/f_repobuild/select_ubuntu_repo.sh)
55 export MIRROR_UBUNTU ?= $(shell echo "$(MIRROR_UBUNTU_URL)" | cut -d'/' -f3 )
56 export MIRROR_UBUNTU_ROOT ?= $(shell echo -n '/' ; echo "$(MIRROR_UBUNTU_URL)" | cut -d'/' -f4-)
57 ifeq (,$(MIRROR_UBUNTU_URL))
58 $(warning $(shell ./f_isoroot/f_repobuild/select_ubuntu_repo.sh -d))
59 $(error No sane Ubuntu mirror available)
60 endif
61
62 export LATEST_MIRROR_ID_URL := http://$(shell ./select_closest_fuel_mirror.py)
63
64 export MIRROR_MOS_UBUNTU ?= $(shell echo "$(LATEST_MIRROR_ID_URL)" | cut -d'/' -f3)
65 export LATEST_TARGET_UBUNTU := $(shell curl -sSf "$(MIRROR_MOS_UBUNTU)/mos-repos/ubuntu/$(MOSVERSION).target.txt" | head -1)
66 export MIRROR_MOS_UBUNTU_ROOT := /mos-repos/ubuntu/$(LATEST_TARGET_UBUNTU)
67 export LATEST_TARGET_CENTOS := $(shell curl -sSf "$(LATEST_MIRROR_ID_URL)/mos-repos/centos/mos$(MOSVERSION)-centos7/os.target.txt" | head -1)
68 export MIRROR_FUEL := "$(LATEST_MIRROR_ID_URL)/mos-repos/centos/mos$(MOSVERSION)-centos7/$(LATEST_TARGET_CENTOS)/x86_64"
69
70 # uncomment and use: make print-VARIABLE
71 #print-%  : ; @echo $* = $($*)
72
73 #Build subclasses
74
75 SUBDIRS := f_isoroot
76
77 # f_example is only an example of how to generate a .deb package and
78 # should not be enabled in official builds.
79 #SUBDIRS += f_example
80
81 ORIGDIR := $(TOPDIR)/origiso
82 #
83 # END of variables to customize
84 #############################################################################
85
86 FUEL_MAIN_DIR := /tmp/fuel-main
87
88 SUBCLEAN = $(addsuffix .clean,$(SUBDIRS))
89
90 .PHONY: all
91 all:
92         @docker version >/dev/null 2>&1 || (echo 'No Docker installation available'; exit 1)
93         @make -C docker
94         @lsb_release -a | grep Ubuntu > /dev/null 2>&1 || (echo 'Ubuntu is the only supported Linux distribution for this build system'; exit 1)
95         @KERNEL_VER=$$(uname -r); \
96         KERNEL_ARRAY=($${KERNEL_VER//./ }); \
97         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
98         @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)
99         @docker/runcontext $(DOCKERIMG) $(MAKE) $(MAKEFLAGS) iso
100
101
102 ############################################################################
103 # BEGIN of Include definitions
104 #
105 include config.mk
106 include cache.mk
107 #
108 # END Include definitions
109 #############################################################################
110
111 $(ISOCACHE):
112         # Clone Fuel to non-persistent location and build
113         sudo rm -rf $(FUEL_MAIN_DIR)
114         $(MAKE) -C f_repos -f Makefile release
115         git clone $(FUEL_MAIN_REPO) $(FUEL_MAIN_DIR)
116         # Save upstream ref, checkout OPNFV tag (upstream ref + patches)
117         @echo "fuel" `git -C $(FUEL_MAIN_DIR) \
118                 rev-parse $(F_OPNFV_TAG)-root` >> $(VERSION_FILE)
119         git -C $(FUEL_MAIN_DIR) checkout $(F_OPNFV_TAG)
120         # Remove Docker optimizations, otherwise multistrap will fail during
121         # Fuel build.
122         sudo rm -f /etc/apt/apt.conf.d/docker*
123         #
124         # Need to replace the old Docker v. 1.5.0 with a later version to be
125         # able to access the Docker remote repository!
126         sudo apt-get install apt-transport-https ca-certificates -y
127         sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
128         echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list
129         sudo apt-get update -y
130         sudo apt-get install docker-engine -y
131         sudo sh -c 'echo DOCKER_OPTS=\"--bip 172.45.0.1/24\" > /etc/default/docker'
132         sudo service docker stop || exit 0
133         sudo service docker start
134
135         cd $(FUEL_MAIN_DIR) && ./prepare-build-env.sh
136         # Verify that Docker is alive
137         sudo docker info
138         # fuel-main Makefiles do not like `make -C`
139         cd $(FUEL_MAIN_DIR) && make repos
140         cp f_repos/.cachefuelinfo gitinfo_fuel.txt
141
142         # Repeat build up to three times
143         sudo -E ./fuel_build_loop
144         cp $(FUEL_MAIN_DIR)/build/artifacts/fuel*.iso .
145         # Store artifact in cache straight away if caching is enabled
146         # (no .cacheid will be present unless this is a cached build)
147         test -f .cacheid && $(MAKE) -f Makefile put-cache || exit 0
148
149 .PHONY: mount-origiso umount-origiso
150 mount-origiso: $(ISOCACHE)
151         @echo "Mounting original ISO in $(ORIGDIR)"
152         @mkdir -p $(ORIGDIR)
153         @fuseiso $(ISOCACHE) $(ORIGDIR)
154
155 umount-origiso:
156         @echo "Unmounting original ISO from $(ORIGDIR)"
157         @fusermount -u $(ORIGDIR)
158         @rmdir $(ORIGDIR)
159
160 .PHONY: $(SUBDIRS)
161 $(SUBDIRS):
162         @mkdir -p release/packages/ubuntu/pool/main release/packages/ubuntu/pool/debian-installer release/puppet/modules release/isoroot
163         $(MAKE) -C $@ -f Makefile release
164
165 .PHONY: patch-packages
166 patch-packages:
167         ORIGISO=$(ISOCACHE) REVSTATE=$(REVSTATE) $(MAKE) -C $@ -f Makefile release
168
169 .PHONY: clean $(SUBCLEAN)
170 clean:  $(SUBCLEAN)
171         $(MAKE) -C f_repos -f Makefile clean
172         $(MAKE) -C patch-packages -f Makefile clean
173         @rm -f *.iso
174         @rm -Rf release
175         @rm -Rf newiso
176         @rm -Rf .versions
177         @rm -f $(NEWISO)
178         @rm -f $(BUILD_BASE)/gitinfo_*.txt
179
180 .PHONY: deepclean
181 deepclean: clean clean-cache
182         $(MAKE) -C f_repos -f Makefile deepclean
183         $(MAKE) -C docker clean
184         docker rmi opnfv.org/ubuntu-builder:14.04 &>/dev/null || exit 0
185         docker rmi opnfv.org/ubuntu-builder:latest &>/dev/null || exit 0
186         docker rmi ubuntu:14.04 &>/dev/null || exit 0
187         @if docker images | grep -q "^ubuntu *14.04"; then \
188                 echo "Error: ubuntu:14.04 still present!"; \
189                 exit 1; \
190         fi
191         @if docker images | grep -q "opnfv.org/ubuntu-builder"; then \
192                 echo "Error: opnfv.org/ubuntu-builder still present!"; \
193                 exit 1; \
194         fi
195
196 $(SUBCLEAN): %.clean:
197         $(MAKE) -C $* -f Makefile clean
198
199 .PHONY: setup-env
200 setup-env:
201         @if [ -f environment.mk ]; then \
202                 sudo bash -c "cat environment.mk >> /etc/environment"; \
203         fi
204
205 # Todo: Make things smarter - we shouldn't need to clean everything
206 # betwen make invocations.
207 .PHONY: iso
208 iso:    setup-env $(ISOCACHE) $(SUBDIRS) patch-packages
209         $(REPOINFO) . > gitinfo_main.txt
210         install/install.sh iso $(ISOCACHE) $(NEWISO) $(PRODNO) $(REVSTATE)
211         @printf "\n\nProduct ISO is $(NEWISO)\n\n"
212
213 # Start a bash shell in docker for Makefile debugging
214 .PHONY: debug
215 debug:
216         @docker version >/dev/null 2>&1 || (echo 'No Docker installation available'; exit 1)
217         @make -C docker
218         docker/runcontext $(DOCKERIMG) debug
219
220 #############################################################################
221 # Cache operations - only used when building through ci/build.sh
222 #############################################################################
223
224 # Create a unique hash to be used for getting and putting cache, based on:
225 #   - The commit ID of the full Fuel repo structure
226 #   - The contents of all local Fuel patches
227 #   - Makefile, config and sensitive build scripts fingerprints
228 # NOTE: Patching is deterministic, so we can fingerprint (submodule root commit
229 #       info + OPNFV patches) at once, after patches-import.
230 # NOTE: When git submodule remote tracking is active, `git submodule status`
231 #       will point to the latest commits (remote/branch/HEAD) + OPNFV patches.
232 .cacheid:
233         $(MAKE) -C f_repos -f Makefile get-cache release
234         git submodule status | cut -c2-41 > .cachedata
235         sha1sum fuel_build_loop >> .cachedata
236         sha1sum config.mk >> .cachedata
237         sha1sum Makefile >> .cachedata
238         $(CACHETOOL) getbiweek >> .cachedata
239         cat .cachedata | $(CACHETOOL) getid > .cacheid
240
241 # Clean local data related to caching - called prior to ordinary build
242 .PHONY: clean-cache
243 clean-cache: $(SUBCLEANCACHE)
244         $(MAKE) -C f_repos -f Makefile clean-cache
245         rm -f .cachedata .cacheid
246
247 # Try to download cache - called prior to ordinary build
248 .PHONY: get-cache
249 get-cache: .cacheid
250         @if $(CACHETOOL) check $(shell cat .cacheid); then \
251                  $(CACHETOOL) get $(shell cat .cacheid) | tar xf -;\
252         else \
253                 exit 0;\
254         fi
255
256 # Store cache if not already stored - called after ordinary build
257 .PHONY: put-cache
258 put-cache: .cacheid
259         @tar cf - fuel*.iso gitinfo_fuel.txt | $(CACHETOOL) put $(shell cat .cacheid)