Support for building Fuel behind a http proxy
[fuel.git] / fuel / 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 ISOSRC = file:$(shell pwd)/fuel-6.1.iso
22 export ISOCACHE = $(shell pwd)/$(shell basename $(ISOSRC))
23 export PRODNO = "OPNFV_BGS"
24 export REVSTATE = "P0000"
25 export NEWISO = $(shell pwd)/release/opnfv-${REVSTATE}.iso
26
27 # Note! Invoke with "make REVSTATE=RXXXX all" to make release build!
28 # Invoke with ICOCACHE=/full/path/to/iso if cached ISO is in non-standard location.
29
30 # Build variables
31 export BUILD_BASE := $(shell pwd)
32 export DEB_DEST := $(BUILD_BASE)/release/packages/ubuntu/pool/main
33 export UDEB_DEST := $(BUILD_BASE)/release/packages/ubuntu/pool/debian-installer
34 export PUPPET_DEST := $(BUILD_BASE)/release/puppet/modules
35 export VERSION_FILE := $(BUILD_BASE)/.versions
36 export DOCKERIMG = opnfv.org/ubuntu-builder:14.04
37 export TOPDIR := $(shell pwd)
38 export REPOINFO  := $(BUILD_BASE)/repo_info.sh
39
40 #Build subclasses
41
42 SUBDIRS := f_isoroot
43
44 # f_example is only an example of how to generate a .deb package and
45 # should not be enabled in official builds.
46 #SUBDIRS += f_example
47
48 ORIGDIR := $(TOPDIR)/origiso
49 #
50 # END of variables to customize
51 #############################################################################
52
53 SUBCLEAN = $(addsuffix .clean,$(SUBDIRS))
54
55 .PHONY: all
56 all:
57         @docker version >/dev/null 2>&1 || (echo 'No Docker installation available'; exit 1)
58         @make -C docker
59         @docker/runcontext $(DOCKERIMG) $(MAKE) $(MAKEFLAGS) iso
60
61
62 ############################################################################
63 # BEGIN of Include definitions
64 #
65 include config.mk
66 include cache.mk
67 #
68 # END Include definitions
69 #############################################################################
70
71 $(ISOCACHE):
72         # Clone Fuel to non-persistent location and build
73         if [ ! -d /tmp/fuel-main ]; then \
74                 cd /tmp && git clone $(FUEL_MAIN_REPO); \
75         fi
76         cd /tmp/fuel-main && git checkout $(FUEL_MAIN_TAG)
77         @echo "fuel" `git -C /tmp/fuel-main show | grep commit | head -1 | cut -d " " -f2` >> $(VERSION_FILE)
78         # Setup cgroups for docker-in-docker
79         sudo /root/enable_dockerx2
80         # Temporary patch to accomodate for new Ubuntu trusty devops keys not yet
81         # backported to fuel 6.0 or 6.1
82         cd /tmp/fuel-main && patch -p0 < $(TOPDIR)/fuel-main_3.patch
83         # Patch for adding dosfstools, as Fuel 6.1 is running mkfs.vfat
84         cd /tmp/fuel-main && patch -p0 < $(TOPDIR)/fuel-main_5.patch
85         # Patch for changing the second layer Docker --bip address
86         cd /tmp/fuel-main && patch -p0 < $(TOPDIR)/fuel-main_6.patch
87         # Remove Docker optimizations, otherwise multistrap will fail during
88         # Fuel build.
89         sudo rm -f /etc/apt/apt.conf.d/docker*
90         #
91         cd /tmp/fuel-main && ./prepare-build-env.sh
92         cd /tmp/fuel-main && make repos
93         $(REPOINFO) -r /tmp/fuel-main > gitinfo_fuel.txt
94         #
95         cd /tmp/fuel-main && sudo make iso
96         cp /tmp/fuel-main/build/artifacts/fuel*.iso .
97
98 .PHONY: mount-origiso umount-origiso
99 mount-origiso: $(ISOCACHE)
100         @echo "Mounting original ISO in $(ORIGDIR)"
101         @mkdir -p $(ORIGDIR)
102         @fuseiso $(ISOCACHE) $(ORIGDIR)
103
104 umount-origiso:
105         @echo "Unmounting original ISO from $(ORIGDIR)"
106         @fusermount -u $(ORIGDIR)
107         @rmdir $(ORIGDIR)
108
109 .PHONY: $(SUBDIRS)
110 $(SUBDIRS):
111         @mkdir -p release/packages/ubuntu/pool/main release/packages/ubuntu/pool/debian-installer release/puppet/modules release/isoroot
112         $(MAKE) -C $@ -f Makefile release
113
114 .PHONY: patch-packages
115 patch-packages:
116         ORIGISO=$(ISOCACHE) REVSTATE=$(REVSTATE) $(MAKE) -C $@ -f Makefile release
117
118 .PHONY: clean $(SUBCLEAN)
119 clean:  $(SUBCLEAN)
120         $(MAKE) -C patch-packages -f Makefile clean
121         @rm -f *.iso
122         @rm -Rf release
123         @rm -Rf newiso
124         @rm -Rf .versions
125         @rm -f $(NEWISO)
126         @rm -f $(BUILD_BASE)/gitinfo_*.txt
127
128 .PHONY: deepclean
129 deepclean: clean clean-cache
130         make -C docker clean
131         docker rmi opnfv.org/ubuntu-builder:14.04 &>/dev/null || exit 0
132         docker rmi opnfv.org/ubuntu-builder:latest &>/dev/null || exit 0
133         docker rmi ubuntu:14.04 &>/dev/null || exit 0
134         @if docker images | grep -q "ubuntu *14.04"; then \
135                 echo "Error: ubuntu:14.04 still present!"; \
136                 exit 1; \
137         fi
138         @if docker images | grep -q "opnfv.org/ubuntu-builder"; then \
139                 echo "Error: opnfv.org/ubuntu-builder still present!"; \
140                 exit 1; \
141         fi
142
143 $(SUBCLEAN): %.clean:
144         $(MAKE) -C $* -f Makefile clean
145
146 .PHONY: setup-env
147 setup-env:
148         @if [ -f environment.mk ]; then \
149                 sudo bash -c "cat environment.mk >> /etc/environment"; \
150         fi
151
152 # Todo: Make things smarter - we shouldn't need to clean everything
153 # betwen make invocations.
154 .PHONY: iso
155 iso:    setup-env $(ISOCACHE) $(SUBDIRS) patch-packages
156         $(REPOINFO) . > gitinfo_main.txt
157         install/install.sh iso $(ISOCACHE) $(NEWISO) $(PRODNO) $(REVSTATE)
158         @printf "\n\nProduct ISO is $(NEWISO)\n\n"
159
160 # Start a bash shell in docker for Makefile debugging
161 .PHONY: debug
162 debug:
163         @docker version >/dev/null 2>&1 || (echo 'No Docker installation available'; exit 1)
164         @make -C docker
165         docker/runcontext $(DOCKERIMG) debug
166
167 #############################################################################
168 # Cache operations - only used when building through ci/build.sh
169 #############################################################################
170
171 # Create a unique hash to be used for getting and putting cache, based on:
172 #   - The commit ID of the full Fuel repo structre
173 #   - The contents of all local Fuel patches
174 .cacheid:
175         cd /tmp && git clone $(FUEL_MAIN_REPO)
176         cd /tmp/fuel-main && git checkout $(FUEL_MAIN_TAG)
177         cd /tmp/fuel-main && make repos
178         $(REPOINFO) -r /tmp/fuel-main > .cachedata
179         sha1sum fuel-main*.patch >> .cachedata
180         cat .cachedata | $(CACHETOOL) getid > .cacheid
181         # Not removing fuel-main as it is re-used in build
182
183 # Clean local data related to caching - called prior to ordinary build
184 .PHONY: clean-cache
185 clean-cache: $(SUBCLEANCACHE)
186         rm -f .cachedata .cacheid
187
188 # Try to download cache - called prior to ordinary build
189 .PHONY: get-cache
190 get-cache: .cacheid
191         @if $(CACHETOOL) check $(shell cat .cacheid); then \
192                  $(CACHETOOL) get $(shell cat .cacheid) | tar xf -;\
193         else \
194                 exit 0;\
195         fi
196
197 # Store cache if not already stored - called after ordinary build
198 .PHONY: put-cache
199 put-cache: .cacheid
200         @tar cf - fuel*.iso gitinfo_fuel.txt | $(CACHETOOL) put $(shell cat .cacheid)