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