Cache as we go instead of in the end
[fuel.git] / build / f_isoroot / f_bgpvpn-pluginbuild / Makefile
1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 # jonas.bjurel@ericsson.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 TOP := $(shell pwd)
11
12 ############################################################################
13 # BEGIN of Include definitions
14 #
15 include config.mk
16 #
17 # END Include definitions
18 #############################################################################
19
20
21 .PHONY: all
22 all: .bgpvpnbuild
23
24 .PHONY: clean
25 clean:
26         @rm -f .bgpvpnbuild ../release/opnfv/bgpvpn*.rpm bgpvpn*.rpm
27         @rm -f $(BUILD_BASE)/gitinfo_bgpvpnplugin.txt gitinfo_bgpvpnplugin.txt
28
29 .PHONY: release
30 release:.bgpvpnbuild
31         @rm -f ../release/opnfv/bgpvpn*.rpm
32         @mkdir -p ../release/bgpvpn
33         @cp bgpvpn*.rpm ../release/opnfv/
34         cp gitinfo_bgpvpnplugin.txt $(BUILD_BASE)
35         cd $(BUILD_BASE) && mkdir -p ../deploy/templates/plugins && cp -rf $(TOP)/config/* ../deploy/templates/plugins
36
37 .bgpvpnbuild:
38         rm -rf fuel-plugin-bgpvpn
39         sudo apt-get -y install build-essential ruby-dev rubygems-integration python-pip git rpm createrepo dpkg-dev
40         sudo gem install fpm
41         sudo pip install fuel-plugin-builder
42         git clone $(BGPVPN_REPO)
43         cd fuel-plugin-bgpvpn; \
44         git checkout $(BGPVPN_BRANCH); \
45         if [ ! -z $(BGPVPN_CHANGE) ]; then \
46            git fetch $(BGPVPN_REPO) $(BGPVPN_CHANGE); \
47            git checkout FETCH_HEAD; \
48         fi
49         fpb --debug --build fuel-plugin-bgpvpn/
50         mv fuel-plugin-bgpvpn/bgpvpn*.rpm .
51         $(REPOINFO) -r . > gitinfo_bgpvpnplugin.txt
52         rm -rf fuel-plugin-bgpvpn
53         touch .bgpvpnbuild
54         # Store artifact in cache straight away if caching is enabled
55         # (no .cacheid will be present unless this is a cached build)
56         test -f .cacheid && $(MAKE) -f Makefile put-cache || exit 0
57
58 #############################################################################
59 # Cache operations - only used when building through ci/build.sh
60 #############################################################################
61
62
63 # Create a unique hash to be used for getting and putting cache, based on:
64 #   - The SHA1 hash of the HEAD on the plugin repo's $(BGPVPN_BRANCH)
65 #   - The contents of this Makefile
66 .cacheid:
67         @if [ ! -z $(BGPVPN_CHANGE) ]; then \
68           $(CACHETOOL) getcommitid $(BGPVPN_REPO) $(BGPVPN_CHANGE) > .cachedata; \
69         else \
70           $(CACHETOOL) getcommitid $(BGPVPN_REPO) $(BGPVPN_BRANCH) > .cachedata; \
71         fi
72         sha1sum Makefile >> .cachedata
73         sha1sum config.mk >> .cachedata
74         cat .cachedata | $(CACHETOOL) getid > .cacheid
75
76 # Clean local data related to caching - called prior to ordinary build
77 .PHONY: clean-cache
78 clean-cache: clean
79         rm -f .cachedata .cacheid
80
81 # Try to download cache - called prior to ordinary build
82 .PHONY: get-cache
83 get-cache: .cacheid
84         @if $(CACHETOOL) check $(shell cat .cacheid); then \
85                  $(CACHETOOL) get $(shell cat .cacheid) | tar xf -;\
86         else \
87                 echo "No cache item found for $(shell cat .cacheid)" ;\
88                 exit 0;\
89         fi
90
91 # Store cache if not already stored - called after ordinary build
92 .PHONY: put-cache
93 put-cache: .cacheid
94         @tar cf - .bgpvpnbuild bgpvpn*.rpm gitinfo_bgpvpnplugin.txt | $(CACHETOOL) put $(shell cat .cacheid)