b24ac5b4e5fc7e6ae4b7609af4c33e739c985db9
[fuel.git] / ci / build.sh
1 #!/bin/bash -e
2 # shellcheck disable=SC1004,SC1090
3 ##############################################################################
4 # Copyright (c) 2018 Mirantis Inc., Enea AB and others.
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 ##############################################################################
12 # BEGIN of Exit handlers
13 #
14 do_exit () {
15     local RC=$?
16     if [ ${RC} -eq 0 ]; then
17         notify_n "[OK] MCP: Docker build finished succesfully!" 2
18     else
19         notify_n "[ERROR] MCP: Docker build threw a fatal error!"
20     fi
21 }
22 #
23 # End of Exit handlers
24 ##############################################################################
25
26 ##############################################################################
27 # BEGIN of variables to customize
28 #
29 CI_DEBUG=${CI_DEBUG:-0}; [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
30 MCP_REPO_ROOT_PATH=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..")
31 DEPLOY_DIR=$(cd "${MCP_REPO_ROOT_PATH}/mcp/scripts"; pwd)
32 DOCKER_DIR=$(cd "${MCP_REPO_ROOT_PATH}/docker"; pwd)
33 DOCKER_TAG=${1:-latest}
34 DOCKER_PUSH=${2---push}  # pass an empty second arg to disable push
35 CACHE_INVALIDATE=${CACHE_INVALIDATE:-0}
36 SALT_VERSION='stable 2017.7'
37
38 source "${DEPLOY_DIR}/globals.sh"
39 source "${DEPLOY_DIR}/lib.sh"
40 source "${DEPLOY_DIR}/lib_jump_common.sh"
41
42 [ ! "${TERM:-unknown}" = 'unknown' ] || export TERM=vt220
43 [ "${CACHE_INVALIDATE}" = 0 ] || CACHE_INVALIDATE=$(date +%s)
44
45 #
46 # END of variables to customize
47 ##############################################################################
48
49 ##############################################################################
50 # BEGIN of main
51 #
52
53 # Enable the automatic exit trap
54 trap do_exit SIGINT SIGTERM EXIT
55
56 # Set no restrictive umask so that Jenkins can remove any residuals
57 umask 0000
58
59 pushd "${DEPLOY_DIR}" > /dev/null
60
61 # Install distro packages and pip-managed prerequisites
62 notify "[NOTE] Installing required build-time distro and pip pkgs" 2
63 jumpserver_pkg_install 'build'
64 PYTHON_BIN_PATH="$(python3 -m site --user-base)/bin"
65 PATH="$PATH:$PYTHON_BIN_PATH"
66 # Clone git submodules and apply our patches
67 make -C "${MCP_REPO_ROOT_PATH}/mcp/patches" deepclean patches-import
68 python3 -m pip install --upgrade pipenv --user
69 docker_install
70
71 popd > /dev/null
72 pushd "${DOCKER_DIR}" > /dev/null
73
74 env PIPENV_HIDE_EMOJIS=1 VIRTUALENV_ALWAYS_COPY=1 python3 -m pipenv --three install
75 env PIPENV_HIDE_EMOJIS=1 VIRTUALENV_ALWAYS_COPY=1 python3 -m pipenv install invoke
76 # shellcheck disable=SC2086
77 env PIPENV_HIDE_EMOJIS=1 python3 -m pipenv run \
78   invoke build saltmaster-reclass \
79     --require 'salt salt-formulas opnfv reclass tini-saltmaster' \
80     --dist=ubuntu \
81     --dist-rel=bionic \
82     --formula-rev=nightly \
83     --opnfv-tag="${DOCKER_TAG}" \
84     --salt="${SALT_VERSION}" \
85     --build-arg-extra " \
86         CACHE_INVALIDATE=\"${CACHE_INVALIDATE}\"" \
87     ${DOCKER_PUSH}
88
89 env PIPENV_HIDE_EMOJIS=1 python3 -m pipenv run \
90   invoke build saltminion-maas \
91     --require 'maas' \
92     --dist=ubuntu \
93     --dist-rel=bionic \
94     --opnfv-tag="${DOCKER_TAG}" \
95     --salt="${SALT_VERSION}" \
96     ${DOCKER_PUSH}
97
98 popd > /dev/null
99
100 #
101 # END of main
102 ##############################################################################