From 55b872d17f44e3ffc4dc973928f080964e61e1a4 Mon Sep 17 00:00:00 2001 From: Dan Radez Date: Wed, 1 Apr 2015 14:10:23 -0400 Subject: Initial build.sh files for install via foreman build.sh accepts params defined by https://etherpad.opnfv.org/p/BGS_CI Build currently requires that - CentOS-7.0-1406-x86_64-Minimal.iso - VirtualBox-4.3-4.3.26_98988_fedora18-1.x86_64.rpm - vagrant_1.7.2_x86_64.rpm are placed in the build directory Produces a CentOS 7 iso that will be able to install foreman and provision OpenStack JIRA: BGS-15 Change-Id: If9786d9723f7e77b208745e61704b15cba3ae9c0 Signed-off-by: Dan Radez --- foreman/build/Makefile | 111 +++++++++ foreman/build/c7-opnfv-x86_64-comps.xml | 277 ++++++++++++++++++++++ foreman/build/cache.mk | 78 +++++++ foreman/build/config.mk | 0 foreman/build/isolinux.cfg | 120 ++++++++++ foreman/ci/build.sh | 398 ++++++++++++++++++++++++++++++++ foreman/include/build.sh.debug | 1 + 7 files changed, 985 insertions(+) create mode 100644 foreman/build/Makefile create mode 100644 foreman/build/c7-opnfv-x86_64-comps.xml create mode 100644 foreman/build/cache.mk create mode 100644 foreman/build/config.mk create mode 100644 foreman/build/isolinux.cfg mode change 100644 => 100755 foreman/ci/build.sh create mode 100644 foreman/include/build.sh.debug diff --git a/foreman/build/Makefile b/foreman/build/Makefile new file mode 100644 index 0000000..c08844f --- /dev/null +++ b/foreman/build/Makefile @@ -0,0 +1,111 @@ +############################################################################## +# Copyright (c) 2015 Ericsson AB and others. +# stefan.k.berg@ericsson.com +# jonas.bjurel@ericsson.com +# dradez@redhat.com +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +SHELL = /bin/bash +############################################################################ +# BEGIN of variables to customize +# +#Input args +export UNIT_TEST = FALSE +export INTERACTIVE = TRUE +export ISOSRC = file:$(shell pwd)/CentOS-7.0-1406-x86_64-Minimal.iso +export ISOCACHE = $(shell pwd)/$(shell basename $(ISOSRC)) +export PRODNO = "OPNFV_BGS" +export REVSTATE = "P0000" +export NEWISO = $(shell pwd)/release/OPNFV-CentOS-7-x86_64-${REVSTATE}.iso +export VBOXRPM = $(shell pwd)/VirtualBox-4.3-4.3.26_98988_fedora18-1.x86_64.rpm +export VAGRANTRPM = $(shell pwd)/vagrant_1.7.2_x86_64.rpm + +# Note! Invoke with "make REVSTATE=RXXXX all" to make release build! +# Invoke with ICOCACHE=/full/path/to/iso if cached ISO is in non-standard location. + +#Build variables +export BUILD_BASE := $(shell pwd) +export CACHE_DIR := $(BUILD_BASE)/cache +export VERSION_FILE := $(BUILD_BASE)/.versions +export TOPDIR := $(shell pwd) + +CENTDIR := $(TOPDIR)/centiso +# +# END of variables to customize +############################################################################# + +SUBCLEAN = $(addsuffix .clean,$(SUBDIRS)) + + +.PHONY: all +all: iso + @echo "Versions of cached build results built by" $(shell hostname) "at" $(shell date -u) > $(VERSION_FILE) + @echo "cache.mk" $(shell md5sum $(BUILD_BASE)/cache.mk | cut -f1 -d " ") >> $(VERSION_FILE) + @echo "config.mk" $(shell md5sum $(BUILD_BASE)/config.mk | cut -f1 -d " ") >> $(VERSION_FILE) + +############################################################################ +# BEGIN of Include definitions +# +include config.mk +include cache.mk +# +# END Include definitions +############################################################################# + +$(ISOCACHE): + #cp ~/Downloads/opnfv_iso/CentOS-7.0-1406-x86_64-Minimal.iso $(ISOCACHE) + +.PHONY: mount-centiso umount-centiso +mount-centiso: $(ISOCACHE) + @echo "Mounting CentOS ISO in $(CENTDIR)" + @mkdir -p $(CENTDIR) + @fuseiso $(ISOCACHE) $(CENTDIR) + +umount-centiso: + @set +e + @echo "Unmounting CentOS ISO from $(CENTDIR)" + @fusermount -u $(CENTDIR) + @rmdir $(CENTDIR) + @set -e + +.PHONY: build-clean $(SUBCLEAN) +build-clean: $(SUBCLEAN) + @rm -Rf centos + @rm -Rf release + @rm -Rf newiso + @rm -f $(NEWISO) + +.PHONY: clean $(SUBCLEAN) +clean: clean-cache $(SUBCLEAN) + @rm -f *.iso + @rm -Rf release + @rm -Rf newiso + @rm -f $(NEWISO) + @rm -f $(BUILD_BASE)/.versions + +$(SUBCLEAN): %.clean: + $(MAKE) -C $* -f Makefile clean + +# Todo: Make things smarter - we shouldn't need to clean everything +# betwen make invocations. +.PHONY: iso +iso: build-clean mount-centiso $(ISOCACHE) $(VBOXRPM) $(VAGRANTRPM) + @mkdir centos release + cp -r $(CENTDIR)/* centos + @make umount-centiso + # modify the installer iso's contents + @rm -rf centos/repodata + @cp -f isolinux.cfg centos/isolinux/isolinux.cfg + @cp $(VBOXRPM) centos/Packages + @cp $(VAGRANTRPM) centos/Packages + # regenerate yum repo data + @echo "Generating new yum metadata" + createrepo centos/Packages -g ../../c7-opnfv-x86_64-comps.xml -o centos + # build the iso + @echo "Building OPNFV iso" + mkisofs -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -V "OPNFV CentOS 7 x86_64" -R -J -v -T -o $(NEWISO) centos + @printf "\n\nISO is built at $(NEWISO)\n\n" diff --git a/foreman/build/c7-opnfv-x86_64-comps.xml b/foreman/build/c7-opnfv-x86_64-comps.xml new file mode 100644 index 0000000..3d0266e --- /dev/null +++ b/foreman/build/c7-opnfv-x86_64-comps.xml @@ -0,0 +1,277 @@ + + + + + + core + Core + Kern + ማዕከላዊ ቦታ + اللبّ + ভিত্তি + هستگ + Падмурак + Основа + কোর + কোর + Jezgra + Nucli + Úplný základ + Craidd + Grundlæggende + Kern + Πυρήνας + Core + Núcleo + Tuum + اصل + Keskeiset + Core + Núcleo + મૂળ + ליבה + कोर + Jezgra + Mag + Հիմք + Nucleo + Inti + Bugas + Lágmarkskerfi + Principale + コア + ბირთვი + ಅಂತಸ್ಸಾರ + 핵심 + Pamatsistēma + कोर + Основни + കോറ്‍ + कोर + Teras + Kjerne + कोर + Kern + Kjerne + Bogare + ପ୍ରମୂଖ + ਮੂਲ + Rdzeń + Núcleo + Núcleo + Nucleu + Основа + න්‍යෂ්ඨිය + Jadro + Jedro + Bërthama + Срж + Srž + Srž + Grund + கோர் + అంతర్భాగం + Система + แกนหลัก + Çekirdek + Основа + مرکز + Lõi + 核心 + 核心 + Okuyikhona + Smallest possible installation. + ন্যূনতম ইনস্টল। + ন্যূনতম ইনস্টলেশন। + ন্যূনতম ইনস্টলেশন। + Nejmenší možná instalace. + Kleinstmögliche Installation. + La instalación más pequeña posible. + Plus petite installation possible. + નાનામાં નાના શક્ય સ્થાપન. + लघुतम संभावित संस्थापन. + Le minime possibile installation. + Minima installazione possibile. + 最小限のインストール + ಅತ್ಯಲ್ಪಸಾಧ್ಯ ಅನುಸ್ಥಾಪನೆ. + 가능한 최소 설치 + സാധ്യമായ ഏറ്റവും ചെറിയ ഇന്‍സ്റ്റലേഷന്‍. + शक्यतया सर्वात लहान प्रतिष्ठापन. + କ୍ଷୁଦ୍ରତମ ସମ୍ଭାବ୍ଯ ସ୍ଥାପନା। + ਘੱਟੋ-ਘੱਟ ਸੰਭਵ ਇੰਸਟਾਲੇਸ਼ਨ। + Najmniejsza możliwa instalacja. + Menor instalação possível + Минимально возможная установка + Minsta möjliga installation + மிகச் சிறிய செயல்படுத்தக்கூடிய நிறுவல். + సాధ్యమగు అతిచిన్న సంస్థాపన. + Мінімально можливе встановлення. + 最小可能安装。 + 最小型安裝。 + false + false + + aic94xx-firmware + alsa-firmware + bfa-firmware + dracut-config-rescue + ivtv-firmware + iwl1000-firmware + iwl100-firmware + iwl105-firmware + iwl135-firmware + iwl2000-firmware + iwl2030-firmware + iwl3160-firmware + iwl3945-firmware + iwl4965-firmware + iwl5000-firmware + iwl5150-firmware + iwl6000-firmware + iwl6000g2a-firmware + iwl6000g2b-firmware + iwl6050-firmware + iwl7260-firmware + kernel-tools + libertas-sd8686-firmware + libertas-sd8787-firmware + libertas-usb8388-firmware + linux-firmware + microcode_ctl + NetworkManager + NetworkManager-tui + postfix + ql2100-firmware + ql2200-firmware + ql23xx-firmware + audit + basesystem + bash + biosdevname + btrfs-progs + coreutils + cronie + curl + dhclient + e2fsprogs + filesystem + glibc + hostname + initscripts + iproute + iprutils + iptables + iputils + irqbalance + kbd + kexec-tools + less + man-db + ncurses + openssh-clients + openssh-server + parted + passwd + plymouth + policycoreutils + procps-ng + rootfiles + rpm + rsyslog + selinux-policy-targeted + setup + shadow-utils + sudo + systemd + tar + tuned + util-linux + vagrant + vim-minimal + VirtualBox + xfsprogs + yum + dracut-config-generic + dracut-fips-aesni + dracut-fips + dracut-network + openssh-keycat + selinux-policy-mls + tboot + + + + + opnfv_provisioning + OPNVF Provisioning Server Install + নূন্যতম ইনস্টল + ন্যূনতম ইনস্টল + Minimální instalace + Minimale Installation + Instalación mínima + Installation minimale + ન્યૂનતમ સ્થાપન + न्यूनतम संस्थापन + Installazione minima + 最小限のインストール + ಕನಿಷ್ಟ ಅನುಸ್ಥಾಪನೆ + 최소 설치 + ഏറ്റവും കുറഞ്ഞ ഇന്‍സ്റ്റോള്‍ + किमान इंस्टॉल + ସର୍ବନିମ୍ନ ସ୍ଥାପନ + ਘੱਟ ਤੋਂ ਘੱਟ ਇੰਸਟਾਲ + Minimalna instalacja + Instalações Mínimas + Минимальная установка + குறைந்தபட்ச நிறுவல் + కనీసపు సంస్థాపన + Мінімальна система + 最小安装 + 最小型安裝 + Basic functionality. + মৌলি কাৰ্য্যকৰীতা। + প্রাথমিক বৈশিষ্ট্য। + Základní funkcionalita. + Grundlegende Funktionalität. + Funcionalidad básica. + Fonctionnalité de base. + મૂળભૂત વિધેય. + मौलिक प्रकार्यात्मकता. + Funzione di base. + 基本的な機能です。 + ಮೂಲಭೂತ ಕ್ರಿಯಾಶೀಲತೆ. + 기본적인 기능입니다. + അടിസ്ഥാന പ്രവൃത്തിവിശേഷണം. + मूळ कार्यक्षमता. + ସାଧାରଣ କାର୍ଯ୍ୟକାରିତା। + ਮੁੱਢਲੀ ਕਾਰਜਸ਼ੀਲਤਾ। + Podstawowa funkcjonalność. + Função básica + Базовая функциональность. + அடிப்படை செயலம்சம். + ప్రాథమిక ఫంక్షనాలిటి. + Основні можливості. + 基本功能。 + 基本功能。 + 5 + + core + + + + + + + + + + + + + + + + + + + diff --git a/foreman/build/cache.mk b/foreman/build/cache.mk new file mode 100644 index 0000000..9ae3a7c --- /dev/null +++ b/foreman/build/cache.mk @@ -0,0 +1,78 @@ +############################################################################## +# Copyright (c) 2015 Ericsson AB and others. +# stefan.k.berg@ericsson.com +# jonas.bjurel@ericsson.com +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +SHELL = /bin/bash +CACHEVALIDATE := $(addsuffix .validate,$(SUBDIRS)) +CACHECLEAN := $(addsuffix .clean,$(CACHEFILES) $(CACHEDIRS)) + +############################################################################ +# BEGIN of variables to customize +# +CACHEFILES += .versions +CACHEFILES += $(shell basename $(ISOSRC)) +# +# END of variables to customize +############################################################################ + +.PHONY: prepare-cache +prepare-cache: make-cache-dir $(CACHEDIRS) $(CACHEFILES) + +.PHONY: make-cache-dir +make-cache-dir: + @rm -rf ${CACHE_DIR} + @mkdir ${CACHE_DIR} + +.PHONY: clean-cache +clean-cache: $(CACHECLEAN) + @rm -rf ${CACHE_DIR} + +.PHONY: $(CACHEDIRS) +$(CACHEDIRS): + @mkdir -p $(dir $(CACHE_DIR)/$@) + @if [ ! -d $(BUILD_BASE)/$@ ]; then\ + mkdir -p $(BUILD_BASE)/$@;\ + fi + @ln -s $(BUILD_BASE)/$@ $(CACHE_DIR)/$@ + +.PHONY: $(CACHEFILES) +$(CACHEFILES): + @mkdir -p $(dir $(CACHE_DIR)/$@) + @if [ ! -d $(dir $(BUILD_BASE)/$@) ]; then\ + mkdir -p $(dir $(BUILD_BASE)/$@);\ + fi + + @if [ ! -f $(BUILD_BASE)/$@ ]; then\ + echo " " > $(BUILD_BASE)/$@;\ + ln -s $(BUILD_BASE)/$@ $(CACHE_DIR)/$@;\ + rm -f $(BUILD_BASE)/$@;\ + else\ + ln -s $(BUILD_BASE)/$@ $(CACHE_DIR)/$@;\ + fi + +.PHONY: validate-cache +validate-cache: prepare $(CACHEVALIDATE) + @if [[ $(shell md5sum $(BUILD_BASE)/config.mk | cut -f1 -d " ") != $(shell cat $(VERSION_FILE) | grep config.mk | awk '{print $$NF}') ]]; then\ + echo "Cache does not match current config.mk definition, cache must be rebuilt";\ + exit 1;\ + fi; + + @if [[ $(shell md5sum $(BUILD_BASE)/cache.mk | cut -f1 -d " ") != $(shell cat $(VERSION_FILE) | grep cache.mk | awk '{print $$NF}') ]]; then\ + echo "Cache does not match current cache.mk definition, cache must be rebuilt";\ + exit 1;\ + fi; + +.PHONY: $(CACHEVALIDATE) +$(CACHEVALIDATE): %.validate: + @echo VALIDATE $(CACHEVALIDATE) + $(MAKE) -C $* -f Makefile validate-cache + +.PHONY: $(CACHECLEAN) +$(CACHECLEAN): %.clean: + rm -rf ${CACHE_DIR}/$* diff --git a/foreman/build/config.mk b/foreman/build/config.mk new file mode 100644 index 0000000..e69de29 diff --git a/foreman/build/isolinux.cfg b/foreman/build/isolinux.cfg new file mode 100644 index 0000000..12848de --- /dev/null +++ b/foreman/build/isolinux.cfg @@ -0,0 +1,120 @@ +default vesamenu.c32 +timeout 600 + +display boot.msg + +# Clear the screen when exiting the menu, instead of leaving the menu displayed. +# For vesamenu, this means the graphical background is still displayed without +# the menu itself for as long as the screen remains in graphics mode. +menu clear +menu background splash.png +menu title CentOS 7 +menu vshift 8 +menu rows 18 +menu margin 8 +#menu hidden +menu helpmsgrow 15 +menu tabmsgrow 13 + +# Border Area +menu color border * #00000000 #00000000 none + +# Selected item +menu color sel 0 #ffffffff #00000000 none + +# Title bar +menu color title 0 #ff7ba3d0 #00000000 none + +# Press [Tab] message +menu color tabmsg 0 #ff3a6496 #00000000 none + +# Unselected menu item +menu color unsel 0 #84b8ffff #00000000 none + +# Selected hotkey +menu color hotsel 0 #84b8ffff #00000000 none + +# Unselected hotkey +menu color hotkey 0 #ffffffff #00000000 none + +# Help text +menu color help 0 #ffffffff #00000000 none + +# A scrollbar of some type? Not sure. +menu color scrollbar 0 #ffffffff #ff355594 none + +# Timeout msg +menu color timeout 0 #ffffffff #00000000 none +menu color timeout_msg 0 #ffffffff #00000000 none + +# Command prompt text +menu color cmdmark 0 #84b8ffff #00000000 none +menu color cmdline 0 #ffffffff #00000000 none + +# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message. + +menu tabmsg Press Tab for full configuration options on menu items. + +menu separator # insert an empty line +menu separator # insert an empty line + +label linux + menu label ^Install OPNFV CentOS 7 + menu default + kernel vmlinuz + append initrd=initrd.img inst.stage2=hd:LABEL=OPNFV\x20CentOS\x207\x20x86_64 + +#label check +# menu label Test this ^media & install CentOS 7 +# kernel vmlinuz +# append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet + +menu separator # insert an empty line + +# utilities submenu +menu begin ^Troubleshooting + menu title Troubleshooting + +label vesa + menu indent count 5 + menu label Install CentOS 7 in ^basic graphics mode + text help + Try this option out if you're having trouble installing + CentOS 7. + endtext + kernel vmlinuz + append initrd=initrd.img inst.stage2=hd:LABEL=OPNFV\x20CentOS\x207\x20x86_64 xdriver=vesa nomodeset quiet + +label rescue + menu indent count 5 + menu label ^Rescue a CentOS system + text help + If the system will not boot, this lets you access files + and edit config files to try to get it booting again. + endtext + kernel vmlinuz + append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rescue quiet + +label memtest + menu label Run a ^memory test + text help + If your system is having issues, a problem with your + system's memory may be the cause. Use this utility to + see if the memory is working correctly. + endtext + kernel memtest + +menu separator # insert an empty line + +label local + menu label Boot from ^local drive + localboot 0xffff + +menu separator # insert an empty line +menu separator # insert an empty line + +label returntomain + menu label Return to ^main menu + menu exit + +menu end diff --git a/foreman/ci/build.sh b/foreman/ci/build.sh old mode 100644 new mode 100755 index e69de29..f3d5cf0 --- a/foreman/ci/build.sh +++ b/foreman/ci/build.sh @@ -0,0 +1,398 @@ +#!/bin/bash +set -e +############################################################################## +# Copyright (c) 2015 Ericsson AB and others. +# stefan.k.berg@ericsson.com +# jonas.bjurel@ericsson.com +# dradez@redhat.com +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +trap 'echo "Exiting ..."; \ +if [ -f ${LOCK_FILE} ]; then \ + if [ $(cat ${LOCK_FILE}) -eq $$ ]; then \ + rm -f ${LOCK_FILE}; \ + fi; \ +fi;' EXIT + +############################################################################ +# BEGIN of usage description +# +usage () +{ +cat << EOF +$0 Builds the Foreman OPNFV Deployment ISO + +usage: $0 [-s spec-file] [-c cache-URI] [-l log-file] [-f Flags] build-directory + +OPTIONS: + -s spec-file ($BUILD_SPEC), define the build-spec file, default ../build/config.mk + -c cache base URI ($BUILD_CACHE_URI), specifies the base URI to a build cache to be used/updated - the name is automatically generated from the md5sum of the spec-file, http://, ftp://, file://[absolute path] suported. + + -l log-file ($BUILD_LOG), specifies the output log-file (stdout and stderr), if not specified logs are output to console as normal + -v version tag to be applied to the build result + -r alternative remote access method script/program. curl is default. + -t run small build-script unit test. + -T run large build-script unit test. + -f build flags ($BUILD_FLAGS): + o s: Do nothing, succeed + o f: Do nothing, fail + o t: run build unit tests + o i: run interactive (-t flag to docker run) + o P: Populate a new local cache and push it to the (-c cache-URI) cache artifactory if -c option is present, currently file://, http:// and ftp:// are supported + o d: Detatch - NOT YET SUPPORTED + + build-directory ($BUILD_DIR), specifies the directory for the output artifacts (.iso file). + + -h help, prints this help text + +Description: +build.sh builds opnfv .iso artifact. +To reduce build time it uses build cache on a local or remote location. The cache is rebuilt and uploaded if either of the below conditions are met: +1) The P(opulate) flag is set and the -c cache-base-URI is provided, if -c is not provided the cache will stay local. +2) If the cache is invalidated by one of the following conditions: + - The config spec md5sum does not compare to the md5sum for the spec which the cache was built. + - The git Commit-Id on the remote repos/HEAD defined in the spec file does not correspont with the Commit-Id for what the cache was built with. +3) A valid cache does not exist on the specified -c cache-base-URI. + +The cache URI object name is foreman_cache-"md5sum(spec file)" + +Logging by default to console, but can be directed elsewhere with the -l option in which case both stdout and stderr is redirected to that destination. + +Built in unit testing of components is enabled by adding the t(est) flag. + +Return codes: + - 0 Success! + - 1-99 Unspecified build error + - 100-199 Build system internal error (not build it self) + o 101 Build system instance busy + - 200 Build failure + +Examples: +build -c http://opnfv.org/artifactory/foreman/cache -d ~/jenkins/genesis/foreman/ci/output -f ti +NOTE: At current the build scope is set to the git root of the repository, -d destination locations outside that scope will not work +EOF +} +# +# END of usage description +############################################################################ + +############################################################################ +# BEGIN of variables to customize +# +BUILD_BASE=$(readlink -e ../build/) +RESULT_DIR="${BUILD_BASE}/release" +BUILD_SPEC="${BUILD_BASE}/config.mk" +CACHE_DIR="cache" +LOCAL_CACHE_ARCH_NAME="foreman-cache" +REMOTE_CACHE_ARCH_NAME="foreman_cache-$(md5sum ${BUILD_SPEC}| cut -f1 -d " ")" +REMOTE_ACCESS_METHD=curl +INCLUDE_DIR=../include +# +# END of variables to customize +############################################################################ + +############################################################################ +# BEGIN of script assigned variables +# +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +LOCK_FILE="${SCRIPT_DIR}/.build.lck" +TEST_SUCCEED=0 +TEST_FAIL=0 +UNIT_TEST=0 +UPDATE_CACHE=0 +POPULATE_CACHE=0 +RECURSIV=0 +DETACH=0 +DEBUG=0 +INTEGRATION_TEST=0 +FULL_INTEGRATION_TEST=0 +INTERACTIVE=0 +BUILD_CACHE_URI= +BUILD_SPEC= +BUILD_DIR= +BUILD_LOG= +BUILD_VERSION= +MAKE_ARGS= +# +# END of script assigned variables +############################################################################ + +############################################################################ +# BEGIN of include pragmas +# +source ${INCLUDE_DIR}/build.sh.debug +# +# END of include +############################################################################ + +############################################################################ +# BEGIN of main +# +while getopts "s:c:d:v:f:l:r:RtTh" OPTION +do + case $OPTION in + h) + usage + rc=0 + exit $rc + ;; + + s) + BUILD_SPEC=${OPTARG} + ;; + + c) + BUILD_CACHE_URI=${OPTARG} + ;; + + d) + BUILD_DIR=${OPTARG} + ;; + + l) + BUILD_LOG=${OPTARG} + ;; + + v) + BUILD_VERSION=${OPTARG} + ;; + + f) + BUILD_FLAGS=${OPTARG} + ;; + + r) REMOTE_ACCESS_METHD=${OPTARG} + ;; + + R) + RECURSIVE=1 + ;; + + t) + INTEGRATION_TEST=1 + ;; + + T) + INTEGRATION_TEST=1 + FULL_INTEGRATION_TEST=1 + ;; + + *) + echo "${OPTION} is not a valid argument" + rc=100 + exit $rc + ;; + esac +done + +if [ -z $BUILD_DIR ]; then + BUILD_DIR=$(echo $@ | cut -d ' ' -f ${OPTIND}) +fi + +for ((i=0; i<${#BUILD_FLAGS};i++)); do + case ${BUILD_FLAGS:$i:1} in + s) + rc=0 + exit $rc + ;; + + f) + rc=1 + exit $rc + ;; + + t) + UNIT_TEST=1 + ;; + + i) + INTERACTIVE=1 + ;; + + P) + POPULATE_CACHE=1 + ;; + + d) + DETACH=1 + echo "Detach is not yet supported - exiting ...." + rc=100 + exit $rc + ;; + + D) + DEBUG=1 + ;; + + *) + echo "${BUILD_FLAGS:$i:1} is not a valid build flag - exiting ...." + rc=100 + exit $rc + ;; + esac +done + +shift $((OPTIND-1)) + +if [ ${INTEGRATION_TEST} -eq 1 ]; then + integration-test + rc=0 + exit $rc +fi + +if [ ! -f ${BUILD_SPEC} ]; then + echo "spec file does not exist: $BUILD_SPEC - exiting ...." + rc=100 + exit $rc +fi + +if [ -z ${BUILD_DIR} ]; then + echo "Missing build directory - exiting ...." + rc=100 + exit $rc +fi + +if [ ! -z ${BUILD_LOG} ]; then + if [[ ${RECURSIVE} -ne 1 ]]; then + set +e + eval $0 -R $@ > ${BUILD_LOG} 2>&1 + rc=$? + set -e + if [ $rc -ne 0]; then + exit $rc + fi + fi +fi + +if [ ${TEST_SUCCEED} -eq 1 ]; then + sleep 1 + rc=0 + exit $rc +fi + +if [ ${TEST_FAIL} -eq 1 ]; then + sleep 1 + rc=1 + exit $rc +fi + +if [ -e ${LOCK_FILE} ]; then + echo "A build job is already running, exiting....." + rc=101 + exit $rc +fi + +echo $$ > ${LOCK_FILE} + +if [ ! -z ${BUILD_CACHE_URI} ]; then + if [ ${POPULATE_CACHE} -ne 1 ]; then + rm -rf /tmp/cache + mkdir /tmp/cache + echo "Downloading cach file ${BUILD_CACHE_URI}/${REMOTE_CACHE_ARCH_NAME} ..." + set +e + ${REMOTE_ACCESS_METHD} -o /tmp/cache/${LOCAL_CACHE_ARCH_NAME}.tgz ${BUILD_CACHE_URI}/${REMOTE_CACHE_ARCH_NAME}.tgz + tar -tzf ${BUILD_CACHE_URI}/${REMOTE_CACHE_ARCH_NAME}.tgz >/dev/null + rc=$? + set -e + if [ $rc -ne 0 ]; then + echo "Remote cache does not exist, or is not accessible - a new cache will be built ..." + POPULATE_CACHE=1 + else + echo "Unpacking cache file ..." + tar -C /tmp/cache -xvf /tmp/cache/${LOCAL_CACHE_ARCH_NAME}.tgz + cp /tmp/cache/cache/.versions ${BUILD_BASE}/. + set +e + make -C ${BUILD_BASE} validate-cache; + rc=$? + set -e + + if [ $rc -ne 0 ]; then + echo "Cache invalid - a new cache will be built " + POPULATE_CACHE=1 + else + cp -rf /tmp/cache/cache/. ${BUILD_BASE} + fi + rm -rf /tmp/cache + fi + fi +fi + +if [ ${POPULATE_CACHE} -eq 1 ]; then + if [ ${DEBUG} -eq 0 ]; then + set +e + cd ${BUILD_BASE} && make clean + rc=$? + set -e + if [ $rc -ne 0 ]; then + echo "Build - make clean failed, exiting ..." + rc=100 + exit $rc + fi + fi +fi + +if [ ! -z ${BUILD_VERSION} ]; then + MAKE_ARGS+="REVSTATE=${BUILD_VERSION} " +fi + +if [ ${UNIT_TEST} -eq 1 ]; then + MAKE_ARGS+="UNIT_TEST=TRUE " +else + MAKE_ARGS+="UNIT_TEST=FALSE " +fi + +if [ ${INTERACTIVE} -eq 1 ]; then + MAKE_ARGS+="INTERACTIVE=TRUE " +else + MAKE_ARGS+="INTERACTIVE=FALSE " +fi + +MAKE_ARGS+=all + +if [ ${DEBUG} -eq 0 ]; then + set +e + cd ${BUILD_BASE} && make ${MAKE_ARGS} + rc=$? + set -e + if [ $rc -gt 0 ]; then + echo "Build: make all failed, exiting ..." + rc=200 + exit $rc + fi +else +debug_make +fi +set +e +make -C ${BUILD_BASE} prepare-cache +rc=$? +set -e + +if [ $rc -gt 0 ]; then + echo "Build: make prepare-cache failed - exiting ..." + rc=100 + exit $rc +fi +echo "Copying built OPNFV .iso file to target directory ${BUILD_DIR} ..." +rm -rf ${BUILD_DIR} +mkdir -p ${BUILD_DIR} +cp ${BUILD_BASE}/.versions ${BUILD_DIR} +cp ${RESULT_DIR}/*.iso* ${BUILD_DIR} + +if [ $POPULATE_CACHE -eq 1 ]; then + if [ ! -z ${BUILD_CACHE_URI} ]; then + echo "Building cache ..." + tar --dereference -C ${BUILD_BASE} -caf ${BUILD_BASE}/${LOCAL_CACHE_ARCH_NAME}.tgz ${CACHE_DIR} + echo "Uploading cache ${BUILD_CACHE_URI}/${REMOTE_CACHE_ARCH_NAME}" + ${REMOTE_ACCESS_METHD} -T ${BUILD_BASE}/${LOCAL_CACHE_ARCH_NAME}.tgz ${BUILD_CACHE_URI}/${REMOTE_CACHE_ARCH_NAME}.tgz + rm ${BUILD_BASE}/${LOCAL_CACHE_ARCH_NAME}.tgz + fi +fi +echo "Success!!!" +exit 0 +# +# END of main +############################################################################ diff --git a/foreman/include/build.sh.debug b/foreman/include/build.sh.debug new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/foreman/include/build.sh.debug @@ -0,0 +1 @@ + -- cgit 1.2.3-korg