aboutsummaryrefslogtreecommitdiffstats
path: root/ci/build.sh
blob: 8fab2ca01b4a9b2705ae9169f7e4c7f85f3fd67f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash -e
# shellcheck disable=SC1004,SC1090
##############################################################################
# Copyright (c) 2018 Mirantis Inc., Enea AB and others.
# 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
##############################################################################

##############################################################################
# BEGIN of Exit handlers
#
do_exit () {
    local RC=$?
    if [ ${RC} -eq 0 ]; then
        notify_n "[OK] MCP: Docker build finished succesfully!" 2
    else
        notify_n "[ERROR] MCP: Docker build threw a fatal error!"
    fi
}
#
# End of Exit handlers
##############################################################################

##############################################################################
# BEGIN of variables to customize
#
CI_DEBUG=${CI_DEBUG:-0}; [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
MCP_REPO_ROOT_PATH=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..")
DEPLOY_DIR=$(cd "${MCP_REPO_ROOT_PATH}/mcp/scripts"; pwd)
DOCKER_DIR=$(cd "${MCP_REPO_ROOT_PATH}/docker"; pwd)
DOCKER_TAG=${1:-latest}
DOCKER_PUSH=${2---push}  # pass an empty second arg to disable push
CACHE_INVALIDATE=${CACHE_INVALIDATE:-0}
SALT_VERSION='stable 2017.7'

source "${DEPLOY_DIR}/globals.sh"
source "${DEPLOY_DIR}/lib.sh"
source "${DEPLOY_DIR}/lib_jump_common.sh"

[ ! "${TERM:-unknown}" = 'unknown' ] || export TERM=vt220
[ "${CACHE_INVALIDATE}" = 0 ] || CACHE_INVALIDATE=$(date +%s)

#
# END of variables to customize
##############################################################################

##############################################################################
# BEGIN of main
#

# Enable the automatic exit trap
trap do_exit SIGINT SIGTERM EXIT

# Set no restrictive umask so that Jenkins can remove any residuals
umask 0000

# Clone git submodules and apply our patches
make -C "${MCP_REPO_ROOT_PATH}/mcp/patches" deepclean patches-import

pushd "${DEPLOY_DIR}" > /dev/null

# Install distro packages and pip-managed prerequisites
PYTHON_BIN_PATH="$(python -m site --user-base)/bin"
PATH="$PATH:$PYTHON_BIN_PATH"
notify "[NOTE] Installing required build-time distro and pip pkgs" 2
jumpserver_pkg_install 'build'
python -m pip install --upgrade pipenv --user
docker_install

popd > /dev/null
pushd "${DOCKER_DIR}" > /dev/null

env PIPENV_HIDE_EMOJIS=1 VIRTUALENV_ALWAYS_COPY=1 python -m pipenv --two install
env PIPENV_HIDE_EMOJIS=1 VIRTUALENV_ALWAYS_COPY=1 python -m pipenv install invoke
# shellcheck disable=SC2086
env PIPENV_HIDE_EMOJIS=1 python -m pipenv run \
  invoke build saltmaster-reclass \
    --require 'salt salt-formulas opnfv reclass tini-saltmaster' \
    --dist=ubuntu \
    --dist-rel=xenial \
    --formula-rev=nightly \
    --opnfv-tag="${DOCKER_TAG}" \
    --salt="${SALT_VERSION}" \
    --build-arg-extra " \
        CACHE_INVALIDATE=\"${CACHE_INVALIDATE}\"" \
    ${DOCKER_PUSH}

env PIPENV_HIDE_EMOJIS=1 python -m pipenv run \
  invoke build saltminion-maas \
    --require 'maas' \
    --dist=ubuntu \
    --dist-rel=xenial \
    --opnfv-tag="${DOCKER_TAG}" \
    --salt="${SALT_VERSION}" \
    ${DOCKER_PUSH}

popd > /dev/null

#
# END of main
##############################################################################
installation notes for Ubuntu 14.04. Note: only use the Ubuntu stock distro of Docker (docker-engine). Tested against ver 1.9.x and greater - git (simply available through sudo apt-get install git) - make (simply available through sudo apt-get install make) - curl (simply available through sudo apt-get install curl) Preparations ------------ Setting up the Docker build container ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ After having installed Docker, add yourself to the docker group: <sudo usermod -a -G docker [userid]> Also make sure to define relevant DNS servers part of the global dns chain in in your </etc/default/docker> configuration file. Uncomment, modify the values appropriately and save and quit the file. For example: <DOCKER_OPTS=" --dns=8.8.8.8 --dns=8.8.8.4"> Then restart docker: <sudo service docker restart> Setting up OPNFV Gerrit in order to being able to clone the code ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Start setting up OPNFV gerrit by creating a SSH key (unless you don't already have one), create one with ssh-keygen - Add your generated public key in OPNFV Gerrit <https://gerrit.opnfv.org/> (this requires a linuxfoundation account, create one if you do not already have one) - Select "SSH Public Keys" to the left and then "Add Key" and paste your public key in. Clone the OPNFV code Git repository with your SSH key ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Now it is time to clone the code repository: <git clone ssh://'Linux foundation user'@gerrit.opnfv.org:29418/fuel> Now you should have the OPNFV fuel repository with the Fuel directories stored locally on your build host. Check out the Brahmaputra release: <cd fuel> <git checkout insert-b-release-tag-here0> Clone the OPNFV code Git repository without a SSH key ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also opt to clone the code repository without a SSH key: <git clone https://gerrit.opnfv.org:29418/gerrit/fuel> Make sure to checkout the release tag as described above. Building ======== There are two methods available for building Fuel: - A low level method using Make - An abstracted method using build.sh Support for building behind a http/https/rsync proxy ---------------------------------------------------- The build system is able to make use of a web proxy setup if the http_proxy, https_proxy, no_proxy (if needed) and RSYNC_PROXY or RSYNC_CONNECT_PROG environment variables have been set before invoking make. The proxy setup must permit port 80 (http), 443 (https) and 873 (rsync). Important note about the host Docker daemon settings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The Docker daemon on the host must be configured to use the http proxy for it to be able to pull the base Ubuntu 14.04 image from the Docker registry before invoking make! In Ubuntu this is done by adding a line like: export http_proxy="http://10.0.0.1:8888/" to /etc/default/docker and restarting the Docker daemon. Setting proxy environment variables prior to build ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The build system will make use the following environment variables that needs to be exported to subshells by using export (bash) or setenv (csh/tcsh). | http_proxy (or HTTP_PROXY) | https_proxy (or HTTP_PROXY) | no_proxy (or NO_PROXY) | RSYNC_PROXY | RSYNC_CONNECT_PROG As an example, these are the settings that were put in the user's .bashrc when verifying the proxy build functionality: | export RSYNC_PROXY=10.0.0.1:8888 | export http_proxy=http://10.0.0.1:8888 | export https_proxy=http://10.0.0.1:8888 | export no_proxy=localhost,127.0.0.1,.consultron.com,.sock Using a ssh proxy for the rsync connection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If the proxy setup is not allowing the rsync protocol, an alternative solution is to use a SSH tunnel to a machine capable of accessing the outbound port 873. Set the RSYNC_CONNECT_PROG according to the rsync manual page (for example to "ssh <username>@<hostname> nc %H 873") to enable this. Also note that netcat needs to be installed on the remote system! Make sure that the ssh command also refers to the user on the remote system, as the command itself will be run from the Docker build container as the root user (but with the invoking user's SSH keys). Disabling the Ubuntu repo cache if rsync is not allowed ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ During the build phase, a local Ubuntu package repository is fetched from upstream in order to be added to the OPNFV Fuel ISO and for parts of this process rsync is used. If neither of the two available methods for proxying rsync are available, the last resort is to turn off the caching of the Ubuntu packages in the build system. This is done by removing the "f_repobuild" from SUBDIRS in the beginning of the fuel/build/f_isoroot/Makefile. Note! Doing this will require the Fuel master node to have Internet access when installing the ISO artifact built as no Ubuntu package cache will be on the ISO! Configure your build environment ------------------------------------- ** Configuring the build environment should not be performed if building standard Brahmaputra release ** Select the versions of the components you want to build by editing the fuel/build/config.mk file. Non official build: Selecting which plugins to build ---------------------------------------------------- In order to cut the build time for unofficial builds (made by an individual developer locally), the selection if which Fuel plugins to build (if any) can be done by environment variable "BUILD_FUEL_PLUGINS" prior to building. Only the plugin targets from fuel/build/f_isoroot/Makefile that are specified in the environment variable will then be built. In order to completely disable the building of plugins, the environment variable is set to " ". When using this functionality, the resulting iso file will be prepended with the prefix "unofficial-" to clearly indiciate that this is not a full build. This method of plugin selection is not meant to be used from within Gerrit! Low level build method using make --------------------------------- The low level method is based on Make: From the <fuel/build> directory, invoke <make [target]> Following targets exist: - none/all - this will: - If not already existing, initialize the docker build environment - If not already done, build OpenDaylight from upstream (as defined by fuel-build config-spec) - If not already done, build fuel from upstream (as defined by fuel-build/config-spec) - Build the defined additions to fuel (as defined by the structure of this framework) - Apply changes and patches to fuel (as defined by the structure of this framework) - Reconstruct a fuel .iso image - clean - this will remove all artifacts from earlier builds. If the build is successful, you will find the generated ISO file in the <fuel/build/release> subdirectory! Abstracted build method using build.sh ====================================== The abstracted build method uses the <fuel/ci/build.sh> script which allows you to: - Create and use a build cache - significantly speeding up the buildtime if upstream repositories have not changed. - push/pull cache and artifacts to an arbitrary URI (http(s):, file:, ftp:) For more info type <fuel/ci/build.sh -h>. Artifacts ========= The artifacts produced are: - <OPNFV_XXXX.iso> - Which represents the bootable Fuel image, XXXX is replaced with the build identity provided to the build system - <OPNFV_XXXX.iso.txt> - Which holds version metadata. References ========== - :Authors: Jonas Bjurel (Ericsson), Stefan Berg (Ericsson) :Version: x.x.x **Documentation tracking** Revision: _sha1_ Build date: _date_