Merge "Build local mirrors for stable/mitaka"
[fuel.git] / build / f_isoroot / f_repobuild / 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 TOP := $(shell pwd)
13 TMP_ROOT_DIR := $(shell echo "$(MIRROR_UBUNTU_ROOT)" | cut -d "/" -f2)
14 # Enable use of exact repo commit if defined, else use Fuel main branch
15 FUEL_MIRROR_COMMIT?=$(FUEL_MAIN_TAG)
16
17 include ../../config.mk
18
19 export MOS_VERSION
20 export OPENSTACK_VERSION
21
22 .PHONY: all
23 all: nailgun
24
25 nailgun:
26         sudo apt-get install -y git libxml2-dev libxslt-dev python-dev  python-pip libz-dev libyaml-dev createrepo python-yaml
27         rm -Rf nailgun
28         sudo mkdir -p /var/www/nailgun
29         git clone https://github.com/openstack/fuel-mirror
30         cd fuel-mirror && git checkout -q $(FUEL_MIRROR_COMMIT)
31         sudo pip install -U -r ./fuel-mirror/requirements.txt
32         sudo pip install ./fuel-mirror
33         sudo pip install ./fuel-mirror/contrib/fuel_mirror
34         ./opnfv_mirror_conf.py
35         sudo fuel-mirror --debug --config ./opnfv-config.yaml create --group ubuntu --pattern=ubuntu
36         sudo chmod -R 755 /var/www/nailgun
37         cp -Rp /var/www/nailgun .
38         # On the end we want to have ubuntu repository in mirrors/ubuntu directory
39         -if [ "$(MIRROR_UBUNTU_ROOT)" != "/ubuntu/" ]; then \
40           mkdir -p nailgun/mirrors/ubuntu;\
41           mv nailgun/mirrors$(MIRROR_UBUNTU_ROOT)* nailgun/mirrors/ubuntu;\
42           [ "$(MIRROR_UBUNTU_ROOT)" != "/" ] && rm -rf nailgun/mirrors/$(TMP_ROOT_DIR);\
43         fi
44         # Store artifact in cache straight away if caching is enabled
45         # (no .cacheid will be present unless this is a cached build)
46         test -f .cacheid && $(MAKE) -f Makefile put-cache || exit 0
47
48 .PHONY: clean
49 clean:
50         @rm -rf ../release/opnfv/nailgun nailgun fuel-mirror opnfv-config.yaml ubuntu.yaml
51
52 .PHONY: release
53 release:nailgun
54         @rm -Rf ../release/opnfv/nailgun
55         @mkdir -p ../release/opnfv
56         @cp -Rp nailgun ../release/opnfv/nailgun
57         @cp fuel_bootstrap_cli.yaml ../release/opnfv/
58
59 #############################################################################
60 # Cache operations - only used when building through ci/build.sh
61 #############################################################################
62
63 # Create a unique hash to be used for getting and putting cache, based on:
64 #   - Year and week (causing the cache to be rebuilt weekly)
65 #   - The contents of this Makefile
66 .cacheid:
67         date +"Repocache %G%V" > .cachedata
68         sha1sum Makefile >> .cachedata
69         cat .cachedata | $(CACHETOOL) getid > .cacheid
70
71 # Clean local data related to caching - called prior to ordinary build
72 .PHONY: clean-cache
73 clean-cache: clean
74         rm -f .cachedata .cacheid
75
76 # Try to download cache - called prior to ordinary build
77 .PHONY: get-cache
78 get-cache: .cacheid
79         @if $(CACHETOOL) check $(shell cat .cacheid); then \
80                  $(CACHETOOL) get $(shell cat .cacheid) | tar xf -;\
81         else \
82                 echo "No cache item found for $(shell cat .cacheid)" ;\
83                 exit 0;\
84         fi
85
86 # Store cache if not already stored - called after ordinary build
87 .PHONY: put-cache
88 put-cache: .cacheid
89         @tar cf - nailgun | $(CACHETOOL) put $(shell cat .cacheid)