diff options
author | Andrew Brookins <andrew.brookins@redislabs.com> | 2020-07-08 18:59:31 +0000 |
---|---|---|
committer | Andrew Brookins <andrew.brookins@redislabs.com> | 2020-07-08 18:59:31 +0000 |
commit | 7e28b233391e673732fd47d8f78a0364aa5561be (patch) | |
tree | 21a88704d1325d32fef942d5cbb0e3d6a00c32f2 | |
parent | 10fb0c5814709fd6dca1fc666fbfd8b172fb08bc (diff) | |
download | redis-py-7e28b233391e673732fd47d8f78a0364aa5561be.tar.gz |
WIP: All processes in a single container
-rw-r--r-- | Dockerfile | 18 | ||||
-rwxr-xr-x | build_tools/bootstrap.sh | 3 | ||||
-rwxr-xr-x | build_tools/build_redis.sh | 7 | ||||
-rwxr-xr-x | build_tools/install_redis.sh | 16 | ||||
-rwxr-xr-x | build_tools/install_sentinel.sh | 17 | ||||
-rw-r--r-- | build_tools/redis-configs/001-master | 1 | ||||
-rw-r--r-- | build_tools/redis-configs/002-slave | 1 | ||||
-rwxr-xr-x | build_tools/redis_vars.sh | 41 | ||||
-rw-r--r-- | build_tools/sentinel-configs/001-1 | 1 | ||||
-rw-r--r-- | build_tools/sentinel-configs/002-2 | 1 | ||||
-rw-r--r-- | build_tools/sentinel-configs/003-3 | 1 | ||||
-rwxr-xr-x | build_tools/start.sh | 9 | ||||
-rw-r--r-- | docker-compose.yml | 13 |
13 files changed, 64 insertions, 65 deletions
diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..898f5bf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM ubuntu:20.04 + +COPY build_tools /build_tools + +RUN /build_tools/bootstrap.sh +RUN /build_tools/build_redis.sh +RUN /build_tools/install_redis.sh +RUN /build_tools/install_sentinel.sh + +COPY build_tools/start.sh /var/lib/redis/start.sh + +EXPOSE 6379 +EXPOSE 6380 +EXPOSE 26379 +EXPOSE 26380 +EXPOSE 26381 + +CMD /var/lib/redis/start.sh diff --git a/build_tools/bootstrap.sh b/build_tools/bootstrap.sh index a5a0d2c..7125326 100755 --- a/build_tools/bootstrap.sh +++ b/build_tools/bootstrap.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash # need make to build redis -sudo apt-get install make +apt-get update +apt-get install -y make apt-utils wget build-essential diff --git a/build_tools/build_redis.sh b/build_tools/build_redis.sh index 379c6cc..f530bf0 100755 --- a/build_tools/build_redis.sh +++ b/build_tools/build_redis.sh @@ -1,11 +1,8 @@ #!/usr/bin/env bash -source /home/vagrant/redis-py/build_tools/redis_vars.sh +source /build_tools/redis_vars.sh -pushd /home/vagrant - -uninstall_all_sentinel_instances -uninstall_all_redis_instances +pushd /tmp # create a clean directory for redis rm -rf $REDIS_DIR diff --git a/build_tools/install_redis.sh b/build_tools/install_redis.sh index fd53a1c..0e9d4b2 100755 --- a/build_tools/install_redis.sh +++ b/build_tools/install_redis.sh @@ -1,28 +1,25 @@ #!/usr/bin/env bash -source /home/vagrant/redis-py/build_tools/redis_vars.sh +source /build_tools/redis_vars.sh -for filename in `ls $VAGRANT_REDIS_CONF_DIR`; do +for filename in `ls $BUILD_REDIS_CONF_DIR`; do # cuts the order prefix off of the filename, e.g. 001-master -> master PROCESS_NAME=redis-`echo $filename | cut -f 2- -d -` echo "======================================" echo "INSTALLING REDIS SERVER: $PROCESS_NAME" echo "======================================" - # make sure the instance is uninstalled (it should be already) - uninstall_instance $PROCESS_NAME - # base config mkdir -p $REDIS_CONF_DIR cp $REDIS_BUILD_DIR/redis.conf $REDIS_CONF_DIR/$PROCESS_NAME.conf # override config values from file - cat $VAGRANT_REDIS_CONF_DIR/$filename >> $REDIS_CONF_DIR/$PROCESS_NAME.conf + cat $BUILD_REDIS_CONF_DIR/$filename >> $REDIS_CONF_DIR/$PROCESS_NAME.conf # replace placeholder variables in init.d script - cp $VAGRANT_DIR/redis_init_script /etc/init.d/$PROCESS_NAME + cp $BUILD_DIR/redis_init_script /etc/init.d/$PROCESS_NAME sed -i "s/{{ PROCESS_NAME }}/$PROCESS_NAME/g" /etc/init.d/$PROCESS_NAME # need to read the config file to find out what port this instance will run on - port=`grep port $VAGRANT_REDIS_CONF_DIR/$filename | cut -f 2 -d " "` + port=`grep port $BUILD_REDIS_CONF_DIR/$filename | cut -f 2 -d " "` sed -i "s/{{ PORT }}/$port/g" /etc/init.d/$PROCESS_NAME chmod 755 /etc/init.d/$PROCESS_NAME @@ -31,7 +28,4 @@ for filename in `ls $VAGRANT_REDIS_CONF_DIR`; do # save the $PROCESS_NAME into installed instances file echo $PROCESS_NAME >> $REDIS_INSTALLED_INSTANCES_FILE - - # start redis - /etc/init.d/$PROCESS_NAME start done diff --git a/build_tools/install_sentinel.sh b/build_tools/install_sentinel.sh index 0597208..0aa21ef 100755 --- a/build_tools/install_sentinel.sh +++ b/build_tools/install_sentinel.sh @@ -1,28 +1,26 @@ #!/usr/bin/env bash -source /home/vagrant/redis-py/build_tools/redis_vars.sh +source /build_tools/redis_vars.sh -for filename in `ls $VAGRANT_SENTINEL_CONF_DIR`; do + +for filename in `ls $BUILD_SENTINEL_CONF_DIR`; do # cuts the order prefix off of the filename, e.g. 001-master -> master PROCESS_NAME=sentinel-`echo $filename | cut -f 2- -d -` echo "=========================================" echo "INSTALLING SENTINEL SERVER: $PROCESS_NAME" echo "=========================================" - # make sure the instance is uninstalled (it should be already) - uninstall_instance $PROCESS_NAME - # base config mkdir -p $REDIS_CONF_DIR cp $REDIS_BUILD_DIR/sentinel.conf $REDIS_CONF_DIR/$PROCESS_NAME.conf # override config values from file - cat $VAGRANT_SENTINEL_CONF_DIR/$filename >> $REDIS_CONF_DIR/$PROCESS_NAME.conf + cat $BUILD_SENTINEL_CONF_DIR/$filename >> $REDIS_CONF_DIR/$PROCESS_NAME.conf # replace placeholder variables in init.d script - cp $VAGRANT_DIR/sentinel_init_script /etc/init.d/$PROCESS_NAME + cp $BUILD_DIR/sentinel_init_script /etc/init.d/$PROCESS_NAME sed -i "s/{{ PROCESS_NAME }}/$PROCESS_NAME/g" /etc/init.d/$PROCESS_NAME # need to read the config file to find out what port this instance will run on - port=`grep port $VAGRANT_SENTINEL_CONF_DIR/$filename | cut -f 2 -d " "` + port=`grep port $BUILD_SENTINEL_CONF_DIR/$filename | cut -f 2 -d " "` sed -i "s/{{ PORT }}/$port/g" /etc/init.d/$PROCESS_NAME chmod 755 /etc/init.d/$PROCESS_NAME @@ -31,7 +29,4 @@ for filename in `ls $VAGRANT_SENTINEL_CONF_DIR`; do # save the $PROCESS_NAME into installed instances file echo $PROCESS_NAME >> $SENTINEL_INSTALLED_INSTANCES_FILE - - # start redis - /etc/init.d/$PROCESS_NAME start done diff --git a/build_tools/redis-configs/001-master b/build_tools/redis-configs/001-master index 8591f1a..cd1c984 100644 --- a/build_tools/redis-configs/001-master +++ b/build_tools/redis-configs/001-master @@ -6,3 +6,4 @@ unixsocket /tmp/redis_master.sock unixsocketperm 777 dbfilename master.rdb dir /var/lib/redis/backups +logfile /var/log/redis-master diff --git a/build_tools/redis-configs/002-slave b/build_tools/redis-configs/002-slave index 13eb77e..b51cb84 100644 --- a/build_tools/redis-configs/002-slave +++ b/build_tools/redis-configs/002-slave @@ -6,5 +6,6 @@ unixsocket /tmp/redis-slave.sock unixsocketperm 777 dbfilename slave.rdb dir /var/lib/redis/backups +logfile /var/log/redis-slave slaveof 127.0.0.1 6379 diff --git a/build_tools/redis_vars.sh b/build_tools/redis_vars.sh index c52dd4c..b80ff55 100755 --- a/build_tools/redis_vars.sh +++ b/build_tools/redis_vars.sh @@ -1,10 +1,10 @@ #!/usr/bin/env bash -VAGRANT_DIR=/home/vagrant/redis-py/build_tools -VAGRANT_REDIS_CONF_DIR=$VAGRANT_DIR/redis-configs -VAGRANT_SENTINEL_CONF_DIR=$VAGRANT_DIR/sentinel-configs +BUILD_DIR=/build_tools +BUILD_REDIS_CONF_DIR=$BUILD_DIR/redis-configs +BUILD_SENTINEL_CONF_DIR=$BUILD_DIR/sentinel-configs REDIS_VERSION=3.2.0 -REDIS_DOWNLOAD_DIR=/home/vagrant/redis-downloads +REDIS_DOWNLOAD_DIR=/tmp/redis-downloads REDIS_PACKAGE=redis-$REDIS_VERSION.tar.gz REDIS_BUILD_DIR=$REDIS_DOWNLOAD_DIR/redis-$REDIS_VERSION REDIS_DIR=/var/lib/redis @@ -13,36 +13,3 @@ REDIS_CONF_DIR=$REDIS_DIR/conf REDIS_SAVE_DIR=$REDIS_DIR/backups REDIS_INSTALLED_INSTANCES_FILE=$REDIS_DIR/redis-instances SENTINEL_INSTALLED_INSTANCES_FILE=$REDIS_DIR/sentinel-instances - -function uninstall_instance() { - # Expects $1 to be the init.d filename, e.g. redis-nodename or - # sentinel-nodename - - if [ -a /etc/init.d/$1 ]; then - - echo "======================================" - echo "UNINSTALLING REDIS SERVER: $1" - echo "======================================" - - /etc/init.d/$1 stop - update-rc.d -f $1 remove - rm -f /etc/init.d/$1 - fi; - rm -f $REDIS_CONF_DIR/$1.conf -} - -function uninstall_all_redis_instances() { - if [ -a $REDIS_INSTALLED_INSTANCES_FILE ]; then - cat $REDIS_INSTALLED_INSTANCES_FILE | while read line; do - uninstall_instance $line; - done; - fi -} - -function uninstall_all_sentinel_instances() { - if [ -a $SENTINEL_INSTALLED_INSTANCES_FILE ]; then - cat $SENTINEL_INSTALLED_INSTANCES_FILE | while read line; do - uninstall_instance $line; - done; - fi -} diff --git a/build_tools/sentinel-configs/001-1 b/build_tools/sentinel-configs/001-1 index eccc3d1..d12979f 100644 --- a/build_tools/sentinel-configs/001-1 +++ b/build_tools/sentinel-configs/001-1 @@ -1,6 +1,7 @@ pidfile /var/run/sentinel-1.pid port 26379 daemonize yes +logfile /var/log/redis-sentinel-1 # short timeout for sentinel tests sentinel down-after-milliseconds mymaster 500 diff --git a/build_tools/sentinel-configs/002-2 b/build_tools/sentinel-configs/002-2 index 0cd2801..9ab8934 100644 --- a/build_tools/sentinel-configs/002-2 +++ b/build_tools/sentinel-configs/002-2 @@ -1,6 +1,7 @@ pidfile /var/run/sentinel-2.pid port 26380 daemonize yes +logfile /var/log/redis-sentinel-2 # short timeout for sentinel tests sentinel down-after-milliseconds mymaster 500 diff --git a/build_tools/sentinel-configs/003-3 b/build_tools/sentinel-configs/003-3 index c7f4fcd..b971b2f 100644 --- a/build_tools/sentinel-configs/003-3 +++ b/build_tools/sentinel-configs/003-3 @@ -1,6 +1,7 @@ pidfile /var/run/sentinel-3.pid port 26381 daemonize yes +logfile /var/log/redis-sentinel-3 # short timeout for sentinel tests sentinel down-after-milliseconds mymaster 500 diff --git a/build_tools/start.sh b/build_tools/start.sh new file mode 100755 index 0000000..c394b94 --- /dev/null +++ b/build_tools/start.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +/etc/init.d/redis-master start +/etc/init.d/redis-slave start +/etc/init.d/sentinel-1 start +/etc/init.d/sentinel-2 start +/etc/init.d/sentinel-3 start + +tail -f /var/log/redis-master /var/log/redis-slave /var/log/redis-sentinel-1 /var/log/redis-sentinel-2 /var/log/redis-sentinel-3 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9c61dd4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: "3.8" + +services: + redis-py: + build: ./ + ports: + - "6379:6379" + - "6380:6380" + - "26379:26379" + - "26380:26380" + - "26381:26381" + volumes: + - .:/mnt/redis-py |