forked from gchq/stroom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildDockerImages.sh
executable file
·117 lines (95 loc) · 2.98 KB
/
buildDockerImages.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
#!/usr/bin/env bash
#**********************************************************************
# Copyright 2018 Crown Copyright
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#**********************************************************************
# This script is all you need to build a local image of stroom and stroom-proxy
# for development purposes.
# Releases to Dockerhub will be done by travis
set -e
#shellcheck disable=SC2034
{
#Shell Colour constants for use in 'echo -e'
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
LGREY='\e[37m'
DGREY='\e[90m'
NC='\033[0m' # No Color
}
MODE_SKIP_GRADLE="skipGradle"
MODE_SKIP_GWT="skipGwt"
show_usage() {
echo -e "Usage: ${BLUE}$0 [${MODE_SKIP_GRADLE}|${MODE_SKIP_GWT}]${NC}"
}
do_gradle_build() {
local gradle_args=(
"clean"
"build"
"-x" "test"
)
if [ "$mode" = "skipGwt" ]; then
echo -e "${GREEN}Skipping GWT compile${NC}"
gradle_args+=( "-x" "gwtCompile" )
fi
echo -e "${GREEN}Gradle arguments: ${BLUE}${gradle_args[*]}${NC}"
# Exclude tests because we want this to be fast.
# I guess you'd better test the build before releasing.
./gradlew "${gradle_args[@]}"
}
do_docker_builds() {
DOCKER_IMAGE_TAG="local-SNAPSHOT"
CURRENT_GIT_COMMIT="$(git rev-parse HEAD)"
echo -e "${GREEN}Building stroom docker image" \
"${BLUE}gchq/stroom:${DOCKER_IMAGE_TAG}${NC} for commit" \
"${BLUE}${CURRENT_GIT_COMMIT}${NC}"
docker build \
--tag gchq/stroom:${DOCKER_IMAGE_TAG} \
--build-arg GIT_COMMIT="${CURRENT_GIT_COMMIT}" \
--build-arg GIT_TAG="${DOCKER_IMAGE_TAG}" \
./stroom-app/docker
echo -e "${GREEN}Building stroom-proxy docker image" \
"${BLUE}gchq/stroom-proxy:${DOCKER_IMAGE_TAG}${NC} for commit" \
"${BLUE}${CURRENT_GIT_COMMIT}${NC}"
docker build \
--tag gchq/stroom-proxy:${DOCKER_IMAGE_TAG} \
--build-arg GIT_COMMIT="${CURRENT_GIT_COMMIT}" \
--build-arg GIT_TAG="${DOCKER_IMAGE_TAG}" \
./stroom-proxy/stroom-proxy-app/docker
}
main() {
if [ "$#" -gt 1 ]; then
echo -e "${RED}Error${NC}: Invalid arguments"
show_usage
exit 1
elif [ "$#" -eq 1 ] \
&& [[ ! "$1" =~ (${MODE_SKIP_GRADLE}|${MODE_SKIP_GWT}) ]]; then
echo -e "${RED}Error${NC}: Invalid mode"
show_usage
exit 1
fi
local mode="$1"
if [ "$mode" = "skipGradle" ]; then
echo -e "${GREEN}Skipping gradle build${NC}"
else
do_gradle_build
fi
if [ $? -ne 0 ]; then
exit 1
fi
do_docker_builds
echo -e "${GREEN}Done${NC}"
}
main "$@"