-
-
Notifications
You must be signed in to change notification settings - Fork 131
/
start-docker.sh
executable file
·168 lines (136 loc) · 5.41 KB
/
start-docker.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
#
# Yet Another UserAgent Analyzer
# Copyright (C) 2013-2024 Niels Basjes
#
# 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
#
# https://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.
#
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
echo "PWD: ${SCRIPTDIR}"
cd "${SCRIPTDIR}" || ( echo "This should not be possible" ; exit 1 )
PROJECTNAME=yauaa
USER=$(id -un)
CONTAINER_NAME=${PROJECTNAME}-devtools-${USER}-$$
DOCKER_BUILD="docker build"
if [ -n "${INSIDE_DOCKER+x}" ];
then
echo "Nothing to do: You are already INSIDE the docker environment"
exit 1;
fi
if [[ "$(docker images -q ${PROJECTNAME}-devtools 2> /dev/null)" == "" ]]; then
# DOCKER_BUILD="docker build"
cat << "Welcome-message"
_____ _ _ _ _ _
/ ___| | | | | (_) (_) | |
\ `--. ___| |_| |_ _ _ __ __ _ _ _ _ __ ___ _ ____ ___ _ __ ___ _ __ _ __ ___ ___ _ __ | |_
`--. \/ _ \ __| __| | '_ \ / _` | | | | | '_ \ / _ \ '_ \ \ / / | '__/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __|
/\__/ / __/ |_| |_| | | | | (_| | | |_| | |_) | | __/ | | \ V /| | | | (_) | | | | | | | | | __/ | | | |_
\____/ \___|\__|\__|_|_| |_|\__, | \__,_| .__/ \___|_| |_|\_/ |_|_| \___/|_| |_|_| |_| |_|\___|_| |_|\__|
__/ | | |
|___/ |_|
For building Yet Another UserAgent Analyzer
This will take a few minutes...
Welcome-message
else
# DOCKER_BUILD="docker build -q"
echo "Loading Yauaa development environment"
fi
${DOCKER_BUILD} -t ${PROJECTNAME}-devtools devtools/docker/
buildStatus=$?
if [ ${buildStatus} -ne 0 ];
then
echo "Building the docker image failed."
exit ${buildStatus}
fi
if [ "$(uname -s)" == "Linux" ]; then
USER_NAME=${SUDO_USER:=${USER}}
USER_ID=$(id -u "${USER_NAME}")
GROUP_ID=$(id -g "${USER_NAME}")
else # boot2docker uid and gid
USER_NAME=${USER}
USER_ID=1000
GROUP_ID=50
fi
EXTRA_DOCKER_STEPS=""
if [ -f "${HOME}/.gitconfig" ];
then
cp "${HOME}/.gitconfig" ___git_config_for_docker
EXTRA_DOCKER_STEPS="ADD ___git_config_for_docker /home/${USER}/.gitconfig"
fi
DOCKER_GROUP_ID=$(getent group docker | cut -d':' -f3)
cat - > ___UserSpecificDockerfile << UserSpecificDocker
FROM ${PROJECTNAME}-devtools
RUN bash /scripts/configure-for-user.sh "${USER_NAME}" "${USER_ID}" "${GROUP_ID}" "$(grep -F vboxsf /etc/group)"
#RUN groupmod -g ${DOCKER_GROUP_ID} docker
${EXTRA_DOCKER_STEPS}
UserSpecificDocker
${DOCKER_BUILD} -t "${PROJECTNAME}-devtools-${USER_NAME}" -f ___UserSpecificDockerfile .
buildStatus=$?
if [ ${buildStatus} -ne 0 ];
then
echo "Building the user specific docker image failed."
exit ${buildStatus}
fi
rm -f ___git_config_for_docker ___UserSpecificDockerfile
echo ""
echo "Docker image build completed."
echo "=============================================================================================="
echo ""
# Do NOT Map the real ~/.m2 directory !!!
[ -d "${PWD}/devtools/docker/_m2" ] || mkdir "${PWD}/devtools/docker/_m2"
[ -d "${PWD}/devtools/docker/_gnupg" ] || mkdir "${PWD}/devtools/docker/_gnupg"
MOUNTGPGDIR="${PWD}/devtools/docker/_gnupg"
if [[ "${1}" == "RELEASE" ]];
then
cp "${HOME}"/.m2/*.xml "${PWD}/devtools/docker/_m2"
MOUNTGPGDIR="${HOME}/.gnupg"
echo "Setting up for release process"
fi
DOCKER_INTERACTIVE_RUN=${DOCKER_INTERACTIVE_RUN-"-i -t"}
DOCKER_SOCKET_MOUNT=""
if [ -S /var/run/docker.sock ];
then
DOCKER_SOCKET_MOUNT="-v /var/run/docker.sock:/var/run/docker.sock${V_OPTS:-}"
echo "Enabling Docker support with the docker build environment."
else
echo "There is NO Docker support with the docker build environment."
fi
COMMAND=( "$@" )
if [ $# -eq 0 ];
then
COMMAND=( "bash" "-i" )
DOCKER_INTERACTIVE="-i -t"
else
DOCKER_INTERACTIVE="-i"
fi
# man docker-run
# When using SELinux, mounted directories may not be accessible
# to the container. To work around this, with Docker prior to 1.7
# one needs to run the "chcon -Rt svirt_sandbox_file_t" command on
# the directories. With Docker 1.7 and later the z mount option
# does this automatically.
# Since Docker 1.7 was release 5 years ago we only support 1.7 and newer.
V_OPTS=:z
docker run --rm=true ${DOCKER_INTERACTIVE} \
-u "${USER_NAME}" \
-v "${PWD}:/home/${USER_NAME}/${PROJECTNAME}${V_OPTS:-}" \
-v "${HOME}/.m2:/home/${USER_NAME}/.m2${V_OPTS:-}" \
-v "${PWD}/devtools/docker/toolchains.xml:/home/${USER_NAME}/.m2/toolchains.xml" \
-v "${MOUNTGPGDIR}:/home/${USER_NAME}/.gnupg${V_OPTS:-}" \
${DOCKER_SOCKET_MOUNT} \
-w "/home/${USER}/${PROJECTNAME}" \
-p 1313:1313 \
--name "${CONTAINER_NAME}" \
"${PROJECTNAME}-devtools-${USER_NAME}" \
"${COMMAND[@]}"
exit 0