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