Skip to content

Commit a922139

Browse files
authored
Merge pull request #7 from untergeek/rel/0.8.4
Release prep for 0.8.4
2 parents a111dc9 + 17b057d commit a922139

File tree

10 files changed

+373
-191
lines changed

10 files changed

+373
-191
lines changed

docker_test/VERSION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Version: 1.1.0
2-
Released: 24 August 2024
1+
Version: 1.2.0
2+
Released: 30 August 2024
33

44
# License and Changelog at https://github.com/untergeek/es-docker-test-scripts

docker_test/common.bash

Lines changed: 138 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ REPONAME=testing
1616
LIMIT=30 # How many seconds to wait to obtain the credentials
1717
IMAGE=docker.elastic.co/elasticsearch/elasticsearch
1818
MEMORY=1GB # The heap will be half of this
19+
JAVA_OPTS="-Xms512m -Xmx512m"
20+
CLUSTER_NAME="docker_test"
21+
DISCOVERY_TYPE="single-node"
1922

2023

2124
#############################
@@ -27,6 +30,34 @@ docker_logline () {
2730
echo $(docker logs ${NAME} | grep -n "${1}" | awk -F\: '{print $1}')
2831
}
2932

33+
initial_value () {
34+
# $1 is the value representation
35+
local searchstr=''
36+
37+
case ${1} in
38+
39+
'password')
40+
searchstr='elasticsearch-reset-password'
41+
;;
42+
43+
'nodetoken')
44+
searchstr='\--enrollment-token'
45+
;;
46+
47+
esac
48+
49+
local linenum=$(docker_logline ${searchstr})
50+
51+
# Increment the linenum (because we want the next line)
52+
((++linenum))
53+
54+
# Get the (next) line, i.e. incremented and tailed to isolate
55+
retval=$(docker logs ${NAME} | head -n ${linenum} | tail -1 | awk '{print $1}')
56+
57+
# Strip the ANSI color/bold here. External function because of the control-M sequence
58+
ansi_clean "${retval}"
59+
}
60+
3061
get_espw () {
3162
# Start with an empty value
3263
linenum=''
@@ -74,14 +105,8 @@ get_espw () {
74105
exit 1
75106
fi
76107

77-
# Increment the linenum (because we want the next line)
78-
((++linenum))
79-
80-
# Get the (next) line, i.e. incremented and tailed to isolate
81-
retval=$(docker logs ${NAME} | head -n ${linenum} | tail -1 | awk '{print $1}')
82-
83-
# Strip the ANSI color/bold here. External function because of the control-M sequence
84-
ESPWD=$(ansi_clean "${retval}")
108+
ESPWD=$(initial_value 'password')
109+
NODETOKEN=$(initial_value 'nodetoken')
85110
}
86111

87112
change_espw () {
@@ -127,11 +152,9 @@ change_espw () {
127152

128153
xpack_fork () {
129154

130-
echo
131-
echo "Getting Elasticsearch credentials from container \"${NAME}\"..."
132-
echo
155+
echo "Getting Elasticsearch credentials from container ${NAME}..."
133156

134-
# Get the password from the change_espw function. It sets ESPWD
157+
# Get the password from the get_espw function. It sets ESPWD
135158
get_espw
136159

137160
# If we have an empty value, that's a problem
@@ -143,6 +166,7 @@ xpack_fork () {
143166
# Put envvars in ${ENVCFG}
144167
echo "export ESCLIENT_USERNAME=${ESUSR}" >> ${ENVCFG}
145168
echo "export TEST_USER=${ESUSR}" >> ${ENVCFG}
169+
146170
# We escape the quotes so we can include them in case of special characters
147171
echo "export ESCLIENT_PASSWORD=\"${ESPWD}\"" >> ${ENVCFG}
148172
echo "export TEST_PASS=\"${ESPWD}\"" >> ${ENVCFG}
@@ -156,7 +180,7 @@ xpack_fork () {
156180
echo "--cacert ${CACRT}" >> ${CURLCFG}
157181

158182
# Complete
159-
echo "Credentials captured!"
183+
# echo "Credentials captured!"
160184
}
161185

162186
# Save original execution path
@@ -206,11 +230,9 @@ CACRT=${PROJECT_ROOT}/http_ca.crt
206230

207231
# Set the .env file
208232
ENVCFG=${PROJECT_ROOT}/${ENVFILE}
209-
rm -rf ${ENVCFG}
210233

211234
# Set the curl config file and ensure we're not reusing an old one
212235
CURLCFG=${SCRIPTPATH}/${CURLFILE}
213-
rm -rf ${CURLCFG}
214236

215237
# Determine local IPs
216238
OS=$(uname -a | awk '{print $1}')
@@ -229,15 +251,113 @@ fi
229251
### Set Docker vars ###
230252
#######################
231253

254+
# Set the TRUNK
255+
TRUNK=${PROJECT_NAME}-test
256+
257+
# Set the Docker container number
258+
NUM=0
259+
232260
# Set the Docker container name
233-
NAME=${PROJECT_NAME}-test
261+
NAME=${TRUNK}-${NUM}
234262

235263
# Set the bind mount path for the snapshot repository
236264
REPOLOCAL=${SCRIPTPATH}/repo
237265

238266
# Navigate back to the script path
239267
cd ${SCRIPTPATH}
240268

241-
###################
269+
############################
270+
### URL CHECKER FUNCTION ###
271+
############################
272+
273+
check_url () {
274+
275+
# URL = $1
276+
# EXPECTED = $2
277+
278+
if [ "x${EXPECTED}" == "x" ]; then
279+
local EXPECTED=200
280+
else
281+
local EXPECTED=${2}
282+
fi
283+
284+
# Start with an empty value
285+
local ACTUAL=0
286+
287+
# Initialize loop counter
288+
local COUNTER=0
289+
290+
# Loop until we get our 200 code
291+
while [ "${ACTUAL}" != "${EXPECTED}" ] && [ ${COUNTER} -lt ${LIMIT} ]; do
292+
293+
# Get our actual response
294+
ACTUAL=$(curl -K ${CURLCFG} ${1})
295+
296+
# If we got what we expected, we're great!
297+
if [ "${ACTUAL}" != "${EXPECTED}" ]; then
298+
# Sleep and try again
299+
sleep 1
300+
((++COUNTER))
301+
fi
302+
303+
done
304+
# End while loop
305+
306+
# If we still don't have what we expected, we hit the LIMIT
307+
if [ "${ACTUAL}" != "${EXPECTED}" ]; then
308+
309+
echo "Unable to connect to ${1} in ${LIMIT} seconds. Unable to continue. Exiting..."
310+
exit 1
311+
fi
312+
313+
echo ${ACTUAL}
314+
}
315+
316+
################################
317+
### Start a Docker container ###
318+
################################
319+
320+
start_container () {
321+
# $1 node_number
322+
# $2 enrollment_token
323+
# $3 node roles
324+
325+
if [ "x${2}" == "x" ]; then
326+
local token=''
327+
else
328+
local token=${2}
329+
fi
330+
331+
if [ "x${3}" == "x" ]; then
332+
local roles="'data', 'data_cold', 'data_content', 'data_hot', 'data_warm', 'ingest', 'master'"
333+
else
334+
local roles="${3}"
335+
fi
336+
337+
local fromzero=$(( ${1} - 1 ))
338+
local nodename="${TRUNK}-${fromzero}"
339+
local portnum=$(( 9200 + ${fromzero} ))
340+
341+
echo -en "Container ID: "
342+
docker run -q -d -it \
343+
--name ${nodename} \
344+
--network ${TRUNK}-net \
345+
-m ${MEMORY} \
346+
-p ${portnum}:${DOCKER_PORT} \
347+
-v ${REPOLOCAL}:${REPODOCKER} \
348+
-e ENROLLMENT_TOKEN="${token}" \
349+
-e ES_JAVA_OPTS="${JAVA_OPTS}" \
350+
-e "discovery.type=${DISCOVERY_TYPE}" \
351+
-e "cluster.name=${CLUSTER_NAME}" \
352+
-e "node.name=node-${fromzero}" \
353+
-e "node.roles=[${roles}]" \
354+
-e "xpack.searchable.snapshot.shared_cache.size=100MB" \
355+
-e "xpack.monitoring.templates.enabled=false" \
356+
-e "path.repo=${REPODOCKER}" \
357+
${IMAGE}:${VERSION}
358+
359+
}
360+
361+
##################
242362
### END COMMON ###
243-
###################
363+
##################

0 commit comments

Comments
 (0)