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 ##############################################################################
13 # This file will be created if needed by runcontext to contain proxy
15 -include environment.mk
17 ############################################################################
18 # BEGIN of variables to customize
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 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)
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
36 export NEWISO = $(shell pwd)/release/opnfv-${REVSTATE}.iso
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.
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
53 # Use nearby repositories
54 export MIRROR_UBUNTU_URL := $(shell ./f_isoroot/f_repobuild/select_ubuntu_repo.sh --url)
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-)
58 export LATEST_MIRROR_ID_URL := http://$(shell ./select_closest_fuel_mirror.py)
60 export MIRROR_MOS_UBUNTU ?= $(shell echo "$(LATEST_MIRROR_ID_URL)" | cut -d'/' -f3)
61 export LATEST_TARGET_UBUNTU := $(shell curl -sSf "$(MIRROR_MOS_UBUNTU)/mos-repos/ubuntu/$(MOSVERSION).target.txt" | head -1)
62 export MIRROR_MOS_UBUNTU_ROOT := /mos-repos/ubuntu/$(LATEST_TARGET_UBUNTU)
64 export LATEST_TARGET_CENTOS := $(shell curl -sSf "$(LATEST_MIRROR_ID_URL)/mos-repos/centos/mos$(MOSVERSION)-centos7/os.target.txt" | head -1)
65 export MIRROR_FUEL := "$(LATEST_MIRROR_ID_URL)/mos-repos/centos/mos$(MOSVERSION)-centos7/$(LATEST_TARGET_CENTOS)/x86_64"
67 # uncomment and use: make print-VARIABLE
68 #print-% : ; @echo $* = $($*)
74 # f_example is only an example of how to generate a .deb package and
75 # should not be enabled in official builds.
78 ORIGDIR := $(TOPDIR)/origiso
80 # END of variables to customize
81 #############################################################################
83 # Fuel-main destination path and fuel-* submodule patching, for full list check:
84 # https://github.com/openstack/fuel-main/blob/stable/mitaka/repos.mk#L32-L44
85 FUEL_MAIN_DIR := /tmp/fuel-main
86 FUEL_PATCHES := $(shell find $(BUILD_BASE)/patch-repos -name '*.patch' | sort)
88 SUBCLEAN = $(addsuffix .clean,$(SUBDIRS))
92 @docker version >/dev/null 2>&1 || (echo 'No Docker installation available'; exit 1)
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
102 ############################################################################
103 # BEGIN of Include definitions
108 # END Include definitions
109 #############################################################################
112 # Clone Fuel to non-persistent location and build
113 sudo rm -rf $(FUEL_MAIN_DIR)
114 git clone $(FUEL_MAIN_REPO) $(FUEL_MAIN_DIR)
115 git -C $(FUEL_MAIN_DIR) checkout $(FUEL_MAIN_TAG)
116 @echo "fuel" `git -C $(FUEL_MAIN_DIR) rev-parse HEAD` >> $(VERSION_FILE)
117 # Remove Docker optimizations, otherwise multistrap will fail during
119 sudo rm -f /etc/apt/apt.conf.d/docker*
121 # Need to replace the old Docker v. 1.5.0 with a later version to be
122 # able to access the Docker remote repository!
123 sudo apt-get install apt-transport-https ca-certificates -y
124 sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
125 echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list
126 sudo apt-get update -y
127 sudo apt-get install docker-engine -y
128 sudo sh -c 'echo DOCKER_OPTS=\"--bip 172.45.0.1/24\" > /etc/default/docker'
129 sudo service docker stop || exit 0
130 sudo service docker start
132 cd $(FUEL_MAIN_DIR) && ./prepare-build-env.sh
133 # Verify that Docker is alive
135 # fuel-main Makefiles do not like `make -C`
136 cd $(FUEL_MAIN_DIR) && make repos
137 $(REPOINFO) -r $(FUEL_MAIN_DIR) > gitinfo_fuel.txt
138 # OPNFV patches at Fuel build time
139 # Need to be commited in order for them to be considered by the Fuel
141 $(foreach patch,$(FUEL_PATCHES),git \
142 -C $(subst $(BUILD_BASE)/patch-repos,$(FUEL_MAIN_DIR),$(dir $(patch))) \
143 am --whitespace=nowarn --committer-date-is-author-date $(patch) || \
144 (echo 'Error: Failed patching Fuel repos!' ; exit 1);)
146 # Repeat build up to three times
147 sudo -E ./fuel_build_loop
148 cp $(FUEL_MAIN_DIR)/build/artifacts/fuel*.iso .
149 # Store artifact in cache straight away if caching is enabled
150 # (no .cacheid will be present unless this is a cached build)
151 test -f .cacheid && $(MAKE) -f Makefile put-cache || exit 0
153 .PHONY: mount-origiso umount-origiso
154 mount-origiso: $(ISOCACHE)
155 @echo "Mounting original ISO in $(ORIGDIR)"
157 @fuseiso $(ISOCACHE) $(ORIGDIR)
160 @echo "Unmounting original ISO from $(ORIGDIR)"
161 @fusermount -u $(ORIGDIR)
166 @mkdir -p release/packages/ubuntu/pool/main release/packages/ubuntu/pool/debian-installer release/puppet/modules release/isoroot
167 $(MAKE) -C $@ -f Makefile release
169 .PHONY: patch-packages
171 ORIGISO=$(ISOCACHE) REVSTATE=$(REVSTATE) $(MAKE) -C $@ -f Makefile release
173 .PHONY: clean $(SUBCLEAN)
175 $(MAKE) -C patch-packages -f Makefile clean
181 @rm -f $(BUILD_BASE)/gitinfo_*.txt
184 deepclean: clean clean-cache
186 docker rmi opnfv.org/ubuntu-builder:14.04 &>/dev/null || exit 0
187 docker rmi opnfv.org/ubuntu-builder:latest &>/dev/null || exit 0
188 docker rmi ubuntu:14.04 &>/dev/null || exit 0
189 @if docker images | grep -q "ubuntu *14.04"; then \
190 echo "Error: ubuntu:14.04 still present!"; \
193 @if docker images | grep -q "opnfv.org/ubuntu-builder"; then \
194 echo "Error: opnfv.org/ubuntu-builder still present!"; \
198 $(SUBCLEAN): %.clean:
199 $(MAKE) -C $* -f Makefile clean
203 @if [ -f environment.mk ]; then \
204 sudo bash -c "cat environment.mk >> /etc/environment"; \
207 # Todo: Make things smarter - we shouldn't need to clean everything
208 # betwen make invocations.
210 iso: setup-env $(ISOCACHE) $(SUBDIRS) patch-packages
211 $(REPOINFO) . > gitinfo_main.txt
212 install/install.sh iso $(ISOCACHE) $(NEWISO) $(PRODNO) $(REVSTATE)
213 @printf "\n\nProduct ISO is $(NEWISO)\n\n"
215 # Start a bash shell in docker for Makefile debugging
218 @docker version >/dev/null 2>&1 || (echo 'No Docker installation available'; exit 1)
220 docker/runcontext $(DOCKERIMG) debug
222 #############################################################################
223 # Cache operations - only used when building through ci/build.sh
224 #############################################################################
226 # Create a unique hash to be used for getting and putting cache, based on:
227 # - The commit ID of the full Fuel repo structre
228 # - The contents of all local Fuel patches
230 git clone $(FUEL_MAIN_REPO) $(FUEL_MAIN_DIR)
231 git -C $(FUEL_MAIN_DIR) checkout $(FUEL_MAIN_TAG)
232 make -C $(FUEL_MAIN_DIR) repos
233 $(REPOINFO) -r $(FUEL_MAIN_DIR) > .cachedata
234 $(foreach patch,$(FUEL_PATCHES),sha1sum $(patch) >> .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 # Not removing fuel-main as it is re-used in build
242 # Clean local data related to caching - called prior to ordinary build
244 clean-cache: $(SUBCLEANCACHE)
245 rm -f .cachedata .cacheid
247 # Try to download cache - called prior to ordinary build
250 @if $(CACHETOOL) check $(shell cat .cacheid); then \
251 $(CACHETOOL) get $(shell cat .cacheid) | tar xf -;\
256 # Store cache if not already stored - called after ordinary build
259 @tar cf - fuel*.iso gitinfo_fuel.txt | $(CACHETOOL) put $(shell cat .cacheid)