-
Notifications
You must be signed in to change notification settings - Fork 53
/
ci_build_local.sh
executable file
·146 lines (120 loc) · 3.96 KB
/
ci_build_local.sh
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
# This script aims to mimic the github build on a local machine, with
# the exception of releasing artefacts to github and pushing to dockerhub.
# It does the following:
# - Sets up various env vars that the build scripts expect
# - Creates a build dir in /tmp
# - Clones the stroom repo on your current branch into the build dir.
# NOTE: You MUST have committed and pushed any changes you want to
# the remote as it is doing a fresh clone from the remote.
# - Runs the ci_build.sh script that would be run by GitHub Actions
#
# This script and the ci_build script run on this host but all parts
# of the build that need anything more than bash and standard shell tools
# are executed in docker containers.
set -eo pipefail
setup_echo_colours() {
# Exit the script on any error
set -e
# shellcheck disable=SC2034
if [ "${MONOCHROME}" = true ]; then
RED=''
GREEN=''
YELLOW=''
BLUE=''
BLUE2=''
DGREY=''
NC='' # No Colour
else
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
BLUE2='\033[1;34m'
DGREY='\e[90m'
NC='\033[0m' # No Colour
fi
}
debug_value() {
local name="$1"; shift
local value="$1"; shift
if [ "${IS_DEBUG}" = true ]; then
echo -e "${DGREY}DEBUG ${name}: ${value}${NC}"
fi
}
debug() {
local str="$1"; shift
if [ "${IS_DEBUG}" = true ]; then
echo -e "${DGREY}DEBUG ${str}${NC}"
fi
}
main() {
IS_DEBUG=false
local runWithNonEmptyBuildDir
if [[ "${1}" = "force" ]]; then
runWithNonEmptyBuildDir=true
else
runWithNonEmptyBuildDir=false
fi
setup_echo_colours
local stroom_clone_branch
# get the current branch
stroom_clone_branch="$(git rev-parse --abbrev-ref HEAD)"
# shellcheck disable=SC2034
{
# IMPORTANT - Stops us trying to push builds to dockerhub
export LOCAL_BUILD=true
export BUILD_BRANCH="${stroom_clone_branch}" # Needs to be a proper brach as we git clone this
export BUILD_DIR="/tmp/stroom_ci_build"
export BUILD_COMMIT="dummy_commit_hash" # Uses in docker imagge
export BUILD_IS_PULL_REQUEST="false" # ensures we do docker builds
# To run with no tag use BUILD_TAG= ./travis.local_build.sh
export BUILD_TAG="${BUILD_TAG=v7.0-dummy}" # Gets parsed and needs to be set to trigger aspects of the build
# Settings to run the build according for your local hardware
export SKIP_TESTS="${SKIP_TESTS:-false}"
export MAX_WORKERS="${MAX_WORKERS:-6}"
export GWT_MIN_HEAP="${GWT_MIN_HEAP:-50M}"
export GWT_MAX_HEAP="${GWT_MAX_HEAP:-4G}"
}
if [[ ! -n "${BUILD_TAG}" ]]; then
echo -e "${YELLOW}WARNING:${NC} BUILD_TAG unset so won't run release" \
"parts of build${NC}"
fi
if [[ -d "${BUILD_DIR}" ]]; then
if [[ "${runWithNonEmptyBuildDir}" = true ]]; then
echo -e "${YELLOW}WARNING:${NC} BUILD_DIR ${BLUE}${BUILD_DIR}${NC}" \
"already exists, running anyway${NC}"
else
echo -e "${RED}ERROR:${NC} BUILD_DIR ${BLUE}${BUILD_DIR}${NC}" \
"already exists, delete or use 'force' argument${NC}"
exit 1
fi
fi
local stroom_all_dbs_container_id
stroom_all_dbs_container_id="$( \
docker ps \
--quiet \
--filter "name=stroom-all-dbs")"
if [[ -n "${stroom_all_dbs_container_id}" ]]; then
echo -e "${RED}ERROR:${NC} stroom-all-dbs container exists." \
"Delete it and its volumes before running this script"
exit 1
fi
mkdir -p "${BUILD_DIR}"
# Make sure we start in the travis build dir
pushd "${BUILD_DIR}" > /dev/null
echo -e "${GREEN}Cloning branch ${BLUE}${stroom_clone_branch}${NC}" \
"into ${BUILD_DIR}${NC}"
# Clone stroom like travis would
# Speed up clone with no depth and one branch
git clone \
--depth=1 \
--branch "${stroom_clone_branch}" \
--single-branch \
https://github.com/gchq/stroom.git \
"${BUILD_DIR}"
echo -e "${GREEN}Running ${BLUE}ci_build.sh${NC}"
${BUILD_DIR}/ci_build.sh
echo -e "${GREEN}Done local travis build${NC}"
}
main "$@"