Rebased with latest upstream ONOSFW plugin
[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 RSYNC_HOST := $(shell ./select_ubuntu_repo.sh)
14 DEPENDENCIES_FILE := /etc/fuel-createmirror/requirements-deb.txt
15
16
17 .PHONY: all
18 all: nailgun
19
20 nailgun:
21 #       If RSYNC_CONNECT_PROG is set we need to do some magic to copy the
22 #       keys. Make sure to have the username set in the SSH_CONNECT_PROG
23 #       as well!
24         @if [ -n "${RSYNC_CONNECT_PROG}" -a ! -d /root/.ssh ]; then \
25                 sudo mkdir -p /root/.ssh; \
26                 test -d ${HOME}/.ssh && sudo find ${HOME}/.ssh -maxdepth 1 -type f -exec cp {} /root/.ssh \; ; \
27                 sudo bash -c "echo StrictHostKeyChecking=no > /root/.ssh/config"; \
28                 sudo chmod 700 /root/.ssh; \
29         fi
30         sudo apt-get install -y rsync python python-yaml dpkg-dev openssl
31         rm -rf tmpiso tmpdir
32         mkdir tmpiso
33         fuseiso ${ISOCACHE} tmpiso
34         cp tmpiso/ubuntu/pool/main/f/fuel-createmirror/fuel-createmirror_*.deb .
35         fusermount -u tmpiso
36         rm -rf tmpiso
37         sudo dpkg -i fuel-createmirror_*.deb
38         sudo sed -i 's/DOCKER_MODE=true/DOCKER_MODE=false/' /etc/fuel-createmirror/common.cfg
39         sudo sed -i 's/DEBUG="no"/DEBUG="yes"/' /etc/fuel-createmirror/ubuntu.cfg
40         sudo sed -i "s/MIRROR_UBUNTU_HOST=\".*\"/MIRROR_UBUNTU_HOST=\"$(RSYNC_HOST)\"/" /etc/fuel-createmirror/common.cfg
41         # Add dependencies from plugins. With awk help try add only unique packages.
42         sudo bash -c 'find ../ -name requirements-deb.txt -print0 | xargs -0 -I% awk '\''NR == FNR {first[$$0];next}; ! ($$0 in first)'\'' "${DEPENDENCIES_FILE}" "%" >> "${DEPENDENCIES_FILE}"'
43         rm -Rf nailgun
44         sudo mkdir -p /var/www
45         sudo su - -c /opt/fuel-createmirror-*/fuel-createmirror
46         sudo chmod -R 755 /var/www/nailgun
47         cp -Rp /var/www/nailgun .
48
49 .PHONY: clean
50 clean:
51         @rm -rf ../release/opnfv/nailgun nailgun fuel-createmirror_6.1*.deb
52
53 .PHONY: release
54 release:nailgun
55         @rm -Rf ../release/opnfv/nailgun
56         @mkdir -p ../release/opnfv
57         @cp -Rp nailgun ../release/opnfv/nailgun
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)