From d310ddda5beac0bbddb0b8cd7751fa643a1c5b1d Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Sat, 22 Aug 2020 14:09:04 -0400 Subject: [PATCH] add test redis scripts --- bin/jenkins/mvn | 6 +- bin/jenkins/redis.conf.hbs | 23 +++++++ bin/jenkins/test-redis | 68 +++++++++++++++++++ .../src/test/resources/test-bubble-config.yml | 1 + 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 bin/jenkins/redis.conf.hbs create mode 100755 bin/jenkins/test-redis diff --git a/bin/jenkins/mvn b/bin/jenkins/mvn index dc752b30..ecf400ca 100755 --- a/bin/jenkins/mvn +++ b/bin/jenkins/mvn @@ -1,2 +1,6 @@ #!/bin/bash -/usr/bin/mvn -Dstyle.color=never -Dmaven.repo.local=/var/lib/jenkins/.m2_$(basename $(cd ../.. && pwd))/repository "${@}" +THISDIR=$(cd $(dirname ${0}) && pwd) +WORKSPACE_DIR=$(cd ${THISDIR}/../.. && pwd) +WORKSPACE_NAME=$(basename ${WORKSPACE_DIR}) + +/usr/bin/mvn -Dstyle.color=never -Dmaven.repo.local=/var/lib/jenkins/.m2_${WORKSPACE_NAME}/repository "${@}" diff --git a/bin/jenkins/redis.conf.hbs b/bin/jenkins/redis.conf.hbs new file mode 100644 index 00000000..b8c819c0 --- /dev/null +++ b/bin/jenkins/redis.conf.hbs @@ -0,0 +1,23 @@ +bind 127.0.0.1 ::1 +protected-mode yes + +port {{BUBBLE_REDIS_PORT}} + +tcp-backlog 511 +timeout 0 +tcp-keepalive 300 +daemonize yes +supervised no +pidfile /tmp/redis-{{BUBBLE_REDIS_PORT}}/redis.pid +loglevel notice +logfile /tmp/redis-{{BUBBLE_REDIS_PORT}}/redis.log +databases 1 +always-show-logo yes +dir /tmp/redis-{{BUBBLE_REDIS_PORT}} + +lazyfree-lazy-eviction no +lazyfree-lazy-expire no +lazyfree-lazy-server-del no +replica-lazy-flush no +appendonly no +appendfilename "appendonly-{{BUBBLE_REDIS_PORT}}.aof" diff --git a/bin/jenkins/test-redis b/bin/jenkins/test-redis new file mode 100755 index 00000000..bc38af95 --- /dev/null +++ b/bin/jenkins/test-redis @@ -0,0 +1,68 @@ +#!/bin/bash + +THISDIR=$(cd $(dirname ${0}) && pwd) +WORKSPACE_DIR=$(cd ${THISDIR}/../.. && pwd) +WORKSPACE_NAME=$(basename ${WORKSPACE_DIR}) + +function die { + echo 1>&2 "$0: ${1}" + exit 1 +} + +function redis_port() { + if [[ -z "${BUBBLE_REDIS_PORT}" ]] ; then + # pick port based on hash of workspace name; there is a 1-in-4096 chance of collision + # if you get a collision, just define BUBBLE_REDIS_PORT in jenkins to be < 6800 or > 10895 in the job's build config + BUBBLE_REDIS_PORT=$(expr 6800 + $(echo $((16#$(echo -n ${WORKSPACE_NAME} | sha256sum | awk '{print $1}' | tail -c 4))))) + fi + echo ${BUBBLE_REDIS_PORT} +} + +function start_redis() { + port=$(redis_port) + REDIS_DIR=/tmp/redis-${port} + REDIS_CONF=${REDIS_DIR}/redis.conf + + echo "Creating redis dir: ${REDIS_DIR}" + mkdir -p ${REDIS_DIR} || die "Error creating redis dir: ${REDIS_DIR}" + + echo "Writing redis config: ${REDIS_CONF}" + cat ${THISDIR}/redis.conf.hbs | sed -e "s/{{BUBBLE_REDIS_PORT}}/${port}/g" > ${REDIS_CONF} || die "Error writing redis configuration to ${REDIS_CONF}" + + echo "Starting redis..." + redis-server ${REDIS_CONF} + echo "Redis successfully started on port ${port}" +} + +function stop_redis() { + port=$(redis_port) + REDIS_DIR=/tmp/redis-${port} + PID_FILE=${REDIS_DIR}/redis.pid + if [[ ! -f ${PID_FILE} ]] ; then + echo "Redis pid file not found: ${PID_FILE}" + else + echo "Stopping redis on port ${port}" + kill $(cat ${PID_FILE}) || die "Error killing redis using pid file: ${PID_FILE}" + fi + + echo "Removing redis dir: ${REDIS_DIR}" + rm -rf ${REDIS_DIR} || die "Error removing redis dir: ${REDIS_DIR}" + + echo "Redis stopped and cleaned up" +} + +if [[ -z ${1} ]] ; then + die "expected start or stop" +fi + +case ${1} in + "start") + start_redis + ;; + "stop") + stop_redis + ;; + *) + die "invalid argument: ${1}" + ;; +esac diff --git a/bubble-server/src/test/resources/test-bubble-config.yml b/bubble-server/src/test/resources/test-bubble-config.yml index 9dd26080..877bb175 100644 --- a/bubble-server/src/test/resources/test-bubble-config.yml +++ b/bubble-server/src/test/resources/test-bubble-config.yml @@ -64,6 +64,7 @@ jersey: redis: key: '{{#exists BUBBLE_REDIS_ENCRYPTION_KEY}}{{BUBBLE_REDIS_ENCRYPTION_KEY}}{{else}}{{key_file '.BUBBLE_REDIS_ENCRYPTION_KEY'}}{{/exists}}' + port: '{{#exists BUBBLE_REDIS_PORT}}{{BUBBLE_REDIS_PORT}}{{else}}6379{{/exists}}' prefix: bubble errorApi: