From f26ad97acabb93b89925bce51160253cf251ef87 Mon Sep 17 00:00:00 2001 From: Sameer Naik Date: Thu, 19 May 2016 22:58:33 +0530 Subject: [PATCH] Stacksmith merger (#30) * switch to harpoon installer * switch to `gcr.io/stacksmith-images/ubuntu:14.04` base image * removed unused files * tests: updated for current feature set * switch to `gcr.io/stacksmith-images/ubuntu:14.04-r05` base image * updated to redis-3.0.6-1 Noteable changes: - redis password is optional, no default password * tests: updated for redis-3.0.6-1 * organize dockerfile for stacksmith (#3) * define `BITNAMI_APP_CHECKSUM` macro * removed `BITNAMI_APP_DIR` macro * removed `BITNAMI_APP_VOL_PREFIX` macro * add `/opt/bitnami/$BITNAMI_APP_NAME/sbin` to PATH * organize dockerfile for stacksmith * tests: bump `SLEEP_TIME` to `10` seconds * version bump and replication support (#4) * upgrade to `gcr.io/stacksmith-images/ubuntu:14.04-r06` * upgrade to `redis-3.2.0-0` * cleanup dockerfile * ignore `pkg-cache/` in git * ignore `.git` and `tests/` directories in docker builds * add env parameters to configure master/slave replication * tests: adds replication tests * readme: updated * updated checksum * tests: bump `SLEEP_TIME` to `30` seconds to fix jenkins tests * upgrade to `gcr.io/stacksmith-images/ubuntu:14.04-r07` baseimage * updated readme * readme: fixed typo * readme: use `/path/to/redis-persistence` and `/path/to/redis-backups` in examples --- bitnami/redis/.dockerignore | 2 + bitnami/redis/.gitignore | 1 + bitnami/redis/Dockerfile | 23 +- bitnami/redis/README.md | 258 ++++++------------ bitnami/redis/help.txt | 28 -- bitnami/redis/help.yaml | 15 - bitnami/redis/installer.run.sha256 | 1 - bitnami/redis/post-install.sh | 14 - bitnami/redis/rootfs/app-entrypoint.sh | 17 ++ bitnami/redis/rootfs/bitnami-utils-custom.sh | 61 ----- .../rootfs/etc/cont-init.d/01-bitnami-redis | 19 -- .../rootfs/etc/services.d/redis-logs/finish | 1 - .../rootfs/etc/services.d/redis-logs/run | 5 - .../redis/rootfs/etc/services.d/redis/finish | 21 -- bitnami/redis/rootfs/etc/services.d/redis/run | 7 - bitnami/redis/test.sh | 240 ++++++++-------- 16 files changed, 241 insertions(+), 472 deletions(-) create mode 100644 bitnami/redis/.dockerignore create mode 100644 bitnami/redis/.gitignore delete mode 100644 bitnami/redis/help.txt delete mode 100644 bitnami/redis/help.yaml delete mode 100644 bitnami/redis/installer.run.sha256 delete mode 100644 bitnami/redis/post-install.sh create mode 100755 bitnami/redis/rootfs/app-entrypoint.sh delete mode 100644 bitnami/redis/rootfs/bitnami-utils-custom.sh delete mode 100755 bitnami/redis/rootfs/etc/cont-init.d/01-bitnami-redis delete mode 120000 bitnami/redis/rootfs/etc/services.d/redis-logs/finish delete mode 100755 bitnami/redis/rootfs/etc/services.d/redis-logs/run delete mode 100755 bitnami/redis/rootfs/etc/services.d/redis/finish delete mode 100755 bitnami/redis/rootfs/etc/services.d/redis/run diff --git a/bitnami/redis/.dockerignore b/bitnami/redis/.dockerignore new file mode 100644 index 000000000000..02a9feef3673 --- /dev/null +++ b/bitnami/redis/.dockerignore @@ -0,0 +1,2 @@ +.git/ +tests/ diff --git a/bitnami/redis/.gitignore b/bitnami/redis/.gitignore new file mode 100644 index 000000000000..651590132c03 --- /dev/null +++ b/bitnami/redis/.gitignore @@ -0,0 +1 @@ +pkg-cache/ diff --git a/bitnami/redis/Dockerfile b/bitnami/redis/Dockerfile index eed1fad3c30f..e950328cd79e 100644 --- a/bitnami/redis/Dockerfile +++ b/bitnami/redis/Dockerfile @@ -1,20 +1,17 @@ -FROM bitnami/base-ubuntu:14.04-onbuild +FROM gcr.io/stacksmith-images/ubuntu:14.04-r07 MAINTAINER Bitnami -ENV BITNAMI_APP_NAME=redis \ - BITNAMI_APP_USER=redis \ - BITNAMI_APP_DAEMON=redis-server \ - BITNAMI_APP_VERSION=3.0.7-1 +ENV BITNAMI_IMAGE_VERSION=3.2.0-r0 \ + BITNAMI_APP_NAME=redis \ + BITNAMI_APP_USER=redis -ENV BITNAMI_APP_DIR=$BITNAMI_PREFIX/$BITNAMI_APP_NAME \ - BITNAMI_APP_VOL_PREFIX=/bitnami/$BITNAMI_APP_NAME - -ENV PATH=$BITNAMI_APP_DIR/bin:$BITNAMI_PREFIX/common/bin:$PATH - -RUN $BITNAMI_PREFIX/install.sh --disable-components common --redis_enable_authentication 0 +RUN bitnami-pkg unpack redis-3.2.0-0 --checksum 4b462cc8ad13553c6aa78249ff344d44f9800ee9909de59599a0de3d66078f20 +ENV PATH=/opt/bitnami/$BITNAMI_APP_NAME/sbin:/opt/bitnami/$BITNAMI_APP_NAME/bin:$PATH COPY rootfs/ / +ENTRYPOINT ["/app-entrypoint.sh"] +CMD ["harpoon", "start", "--foreground", "redis"] + +VOLUME ["/bitnami/$BITNAMI_APP_NAME"] EXPOSE 6379 -VOLUME ["$BITNAMI_APP_VOL_PREFIX/data", "$BITNAMI_APP_VOL_PREFIX/conf", "$BITNAMI_APP_VOL_PREFIX/logs"] -ENTRYPOINT ["/entrypoint.sh"] diff --git a/bitnami/redis/README.md b/bitnami/redis/README.md index 9f9f30c1dee0..74ad3e4b8dbd 100644 --- a/bitnami/redis/README.md +++ b/bitnami/redis/README.md @@ -1,37 +1,33 @@ -[![Build -Status](http://bitnami-container-builds.bitnamiapp.com/jenkins/buildStatus/icon?job=docker-redis)](http://bitnami-container-builds.bitnamiapp.com/jenkins/job/docker-redis/) +[![BuildStatus](http://bitnami-container-builds.bitnamiapp.com/jenkins/buildStatus/icon?job=docker-redis)](http://bitnami-container-builds.bitnamiapp.com/jenkins/job/docker-redis/) + # What is Redis? -> Redis is an advanced key-value cache and store. It is often referred to as a data structure server -> since keys can contain strings, hashes, lists, sets, sorted sets, bitmaps and hyperloglogs. +> Redis is an advanced key-value cache and store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets, sorted sets, bitmaps and hyperloglogs. [redis.io](http://redis.io/) # TLDR ```bash -docker run --name redis bitnami/redis +docker run --name redis bitnami/redis:latest ``` ## Docker Compose ``` redis: - image: bitnami/redis + image: bitnami/redis:latest ``` # Get this image -The recommended way to get the Bitnami Redis Docker Image is to pull the prebuilt image from the -[Docker Hub Registry](https://hub.docker.com/r/bitnami/redis). +The recommended way to get the Bitnami Redis Docker Image is to pull the prebuilt image from the [Docker Hub Registry](https://hub.docker.com/r/bitnami/redis). ```bash docker pull bitnami/redis:latest ``` -To use a specific version, you can pull a versioned tag. You can view the -[list of available versions](https://hub.docker.com/r/bitnami/redis/tags/) -in the Docker Hub Registry. +To use a specific version, you can pull a versioned tag. You can view the [list of available versions](https://hub.docker.com/r/bitnami/redis/tags/) in the Docker Hub Registry. ```bash docker pull bitnami/redis:[TAG] @@ -40,43 +36,34 @@ docker pull bitnami/redis:[TAG] If you wish, you can also build the image yourself. ```bash -git clone https://github.com/bitnami/bitnami-docker-redis.git -cd bitnami-docker-redis -docker build -t bitnami/redis . +docker build -t bitnami/redis:latest https://github.com/bitnami/bitnami-docker-redis.git ``` # Persisting your database -If you remove the container all your data will be lost, and the next time you run the image the -database will be reinitialized. To avoid this loss of data, you should mount a volume that will -persist even after the container is removed. +If you remove the container all your data and configurations will be lost, and the next time you run the image the data and configurations will be reinitialized. To avoid this loss of data, you should mount a volume that will persist even after the container is removed. **Note!** -If you have already started using your database, follow the steps on -[backing up](#backing-up-your-container) and [restoring](#restoring-a-backup) to pull the data from -your running container down to your host. +If you have already started using your database, follow the steps on [backing up](#backing-up-your-container) and [restoring](#restoring-a-backup) to pull the data from your running container down to your host. -The Redis image exposes a volume at `/bitnami/redis/data`, you can mount a directory from your -host to serve as the data store. If the directory you mount is empty, the database will be -initialized. +The image exposes a volume at `/bitnami/redis` for the Redis data and configurations. For persistence you can mount a directory at this location from your host. If the mounted directory is empty, it will be initialized on the first run. ```bash -docker run -v /path/to/data:/bitnami/redis/data bitnami/redis +docker run -v /path/to/redis-persistence:/bitnami/redis bitnami/redis:latest ``` or using Docker Compose: ``` redis: - image: bitnami/redis + image: bitnami/redis:latest volumes: - - /path/to/data:/bitnami/redis/data + - /path/to/redis-persistence:/bitnami/redis ``` # Linking -If you want to connect to your Redis server inside another container, you can use the linking -system provided by Docker. +If you want to connect to your Redis server inside another container, you can use the linking system provided by Docker. ## Connecting a Redis client container to the Redis server container @@ -84,38 +71,29 @@ system provided by Docker. The first step is to start our Redis server. -Docker's linking system uses container ids or names to reference containers. We can explicitly -specify a name for our Redis server to make it easier to connect to other containers. +Docker's linking system uses container ids or names to reference containers. We can explicitly specify a name for our Redis server to make it easier to connect to other containers. ```bash -docker run --name redis bitnami/redis +docker run --name redis bitnami/redis:latest ``` ### Step 2: Run Redis as a client and link to our server -Now that we have our Redis server running, we can create another container that links to it by -giving Docker the `--link` option. This option takes the id or name of the container we want to link -it to as well as a hostname to use inside the container, separated by a colon. For example, to have -our Redis server accessible in another container with `server` as it's hostname we would pass -`--link redis:server` to the Docker run command. +Now that we have our Redis server running, we can create another container that links to it by giving Docker the `--link` option. This option takes the id or name of the container we want to link it to as well as a hostname to use inside the container, separated by a colon. For example, to have our Redis server accessible in another container with `server` as it's hostname we would pass `--link redis:server` to the Docker run command. -The Bitnami Redis Docker Image also ships with a Redis client, but by default it will start a -server. To start the client instead, we can override the default command Docker runs by stating a -different command to run after the image name. +The Bitnami Redis Docker Image also ships with a Redis client, but by default it will start a server. To start the client instead, we can override the default command Docker runs by stating a different command to run after the image name. ```bash -docker run --rm -it --link redis:server bitnami/redis redis-cli -h server +docker run --rm -it --link redis:server bitnami/redis:latest redis-cli -h server ``` -We started the Redis client passing in the `-h` option that allows us to specify the hostname of the -server, which we set to the hostname we created in the link. +We started the Redis client passing in the `-h` option that allows us to specify the hostname of the server, which we set to the hostname we created in the link. **Note!** -You can also run the Redis client in the same container the server is running in using the Docker -[exec](https://docs.docker.com/reference/commandline/cli/#exec) command. +You can also run the Redis client in the same container the server is running in using the Docker [exec](https://docs.docker.com/reference/commandline/cli/#exec) command. ```bash -docker exec -it redis-server redis-cli +docker exec -it redis redis-cli ``` ## Linking with Docker Compose @@ -126,13 +104,12 @@ Copy the snippet below into your `docker-compose.yml` to add Redis to your appli ``` redis: - image: bitnami/redis + image: bitnami/redis:latest ``` ### Step 2: Link it to another container in your application -Update the definitions for containers you want to access your Redis server from to include a link -to the `redis` entry you added in Step 1. +Update the definitions for containers you want to access your Redis server from to include a link to the `redis` entry you added in Step 1. ``` myapp: @@ -147,18 +124,17 @@ Inside `myapp`, use `redis` as the hostname for the Redis server. ## Setting the server password on first run -Passing the `REDIS_PASSWORD` environment variable when running the image for the first time will -set the Redis server password to the value of `REDIS_PASSWORD`. +Passing the `REDIS_PASSWORD` environment variable when running the image for the first time will set the Redis server password to the value of `REDIS_PASSWORD`. ```bash -docker run --name redis -e REDIS_PASSWORD=password123 bitnami/redis +docker run --name redis -e REDIS_PASSWORD=password123 bitnami/redis:latest ``` or using Docker Compose: ``` redis: - image: bitnami/redis + image: bitnami/redis:latest environment: - REDIS_PASSWORD=password123 ``` @@ -167,85 +143,72 @@ redis: A [replication](http://redis.io/topics/replication) cluster can easily be setup with the Bitnami Redis Docker Image using the following environment variables: - - `REDIS_REPLICATION_MODE`: Replication mode. Possible values `master`/`slave` (default: none). - - `REDIS_MASTER_HOST`: Hostname/IP of replication master (parameter available only on slave). - - `REDIS_MASTER_PORT`: Port of replication master, defaults to `6379` (parameter available only on slave). - - `REDIS_MASTER_PASSWORD`: Master auth password used by slave to authenticate with the master (default: none). + - `REDIS_REPLICATION_MODE`: The replication mode. Possible values `master`/`slave`. No defaults. + - `REDIS_MASTER_HOST`: Hostname/IP of replication master (slave parameter). No defaults. + - `REDIS_MASTER_PORT`: Server port of the replication master (slave parameter). Defaults to `6379`. + - `REDIS_MASTER_PASSWORD`: Password to authenticate with the master (slave parameter). No defaults. -In a replication cluster you can have one master and zero or more slaves. When replication is enabled writes can occur only on the master while reads can take place on both the master or slaves. For best performance you should limit the reads to the slaves and use the master only for the writes. +In a replication cluster you can have one master and zero or more slaves. When replication is enabled the master node is in read-write mode, while the slaves are in read-only mode. For best performance its advisable to limit the reads to the slaves. ### Step 1: Create the replication master -The first step is to start the master. +The first step is to start the Redis master. ```bash docker run --name redis-master \ - -e REDIS_PASSWORD=masterpassword123 \ -e REDIS_REPLICATION_MODE=master \ - bitnami/redis + -e REDIS_PASSWORD=masterpassword123 \ + bitnami/redis:latest ``` -In this command we are configuring the container as the master using the `REDIS_REPLICATION_MODE=master` parameter. The `REDIS_PASSWORD` parameter enables authentication on the Redis master. +In the above command the container is configured as the `master` using the `REDIS_REPLICATION_MODE` parameter. The `REDIS_PASSWORD` parameter enables authentication on the Redis master. ### Step 2: Create the replication slave -Next we start a replication slave container. +Next we start a Redis slave container. ```bash docker run --name redis-slave \ --link redis-master:master \ - -e REDIS_PASSWORD=password123 \ + -e REDIS_REPLICATION_MODE=slave \ -e REDIS_MASTER_HOST=master \ -e REDIS_MASTER_PORT=6379 \ -e REDIS_MASTER_PASSWORD=masterpassword123 \ - -e REDIS_REPLICATION_MODE=slave \ - bitnami/redis -``` - -In this command we are configuring the container as a slave using the `REDIS_REPLICATION_MODE=slave` parameter. The `REDIS_MASTER_HOST` and `REDIS_MASTER_PORT` parameters are used by the slave container to connect to the master. The `REDIS_MASTER_PASSWORD` specifies the master password allowing the slave to authenticate with the master. The `REDIS_PASSWORD` parameter enables authentication on the Redis slave. - -Using the `master` docker link alias, the Bitnami Redis Docker image automatically fetches the replication paramaters from the master container, namely: - - - `REDIS_MASTER_HOST` - - `REDIS_MASTER_PORT` - - `REDIS_MASTER_PASSWORD` - -As a result you can drop all of these parameters from the slave. - -```bash -docker run --name redis-slave \ - --link redis-master:master \ -e REDIS_PASSWORD=password123 \ - -e REDIS_REPLICATION_MODE=slave \ - bitnami/redis + bitnami/redis:latest ``` -With these two commands you now have a two node Redis master-slave replication cluster up and running. When required you can add more slaves to the cluster without any downtime allowing you to scale the cluster horizontally. +In the above command the container is configured as a `slave` using the `REDIS_REPLICATION_MODE` parameter. The `REDIS_MASTER_HOST`, `REDIS_MASTER_PORT` and `REDIS_MASTER_PASSWORD ` parameters are used connect and authenticate with the Redis master. The `REDIS_PASSWORD` parameter enables authentication on the Redis slave. -If the master goes down you can reconfigure a slave to become a master and begin accepting writes using: +You now have a two node Redis master/slave replication cluster up and running which can be scaled by adding/removing slaves. + +If the Redis master goes down you can reconfigure a slave to become a master using: ```bash docker exec redis-slave redis-cli -a password123 SLAVEOF NO ONE ``` -> **Note**: The configuration of the other slaves in the cluster needs to be updated so that they are aware of the new master. This would require you to restart the other slaves with `--link redis-slave:master` as per our examples. +> **Note**: The configuration of the other slaves in the cluster needs to be updated so that they are aware of the new master. In our example, this would involve restarting the other slaves with `--link redis-slave:master`. -With Docker Compose the master-slave replication can be setup using: +With Docker Compose the master/slave replication can be setup using: ```yaml master: - image: bitnami/redis + image: bitnami/redis:latest environment: - - REDIS_PASSWORD=masterpassword123 - REDIS_REPLICATION_MODE=master + - REDIS_PASSWORD=masterpassword123 slave: - image: bitnami/redis + image: bitnami/redis:latest links: - master:master environment: - - REDIS_PASSWORD=password123 - REDIS_REPLICATION_MODE=slave + - REDIS_MASTER_HOST=master + - REDIS_MASTER_PORT=6379 + - REDIS_MASTER_PASSWORD=masterpassword123 + - REDIS_PASSWORD=password123 ``` Scale the number of slaves using: @@ -258,43 +221,25 @@ The above command scales up the number of slaves to `3`. You can scale down in t > **Note**: You should not scale up/down the number of master nodes. Always have only one master node running. -## Command-line options - -The simplest way to configure your Redis server is to pass custom command-line options when -running the image. - -```bash -docker run bitnami/redis --maxclients 10 -``` - -or using Docker Compose: - -``` -redis: - image: bitnami/redis - command: --maxclients 10 -``` - ## Configuration file -This image looks for configuration in `/bitnami/redis/conf`. You can mount a volume there with -your own configuration, or the default configuration will be copied to your volume if it is empty. +The image looks for configuration in the `conf/` directory of `/bitnami/redis`. As as mentioned in [Persisting your database](#persisting-your-data) you can mount a volume at this location and copy your own configurations in the `conf/` directory. The default configuration will be copied to the `conf/` directory if it's empty. ### Step 1: Run the Redis image Run the Redis image, mounting a directory from your host. ```bash -docker run --name redis -v /path/to/redis/conf:/bitnami/redis/conf bitnami/redis +docker run --name redis -v /path/to/redis-persistence:/bitnami/redis bitnami/redis:latest ``` or using Docker Compose: ``` redis: - image: bitnami/redis + image: bitnami/redis:latest volumes: - - /path/to/redis/conf:/bitnami/redis/conf + - /path/to/redis-persistence:/bitnami/redis ``` ### Step 2: Edit the configuration @@ -302,7 +247,7 @@ redis: Edit the configuration on your host using your favorite editor. ```bash -vi /path/to/redis/conf/redis.conf +vi /path/to/redis-persistence/conf/redis.conf ``` ### Step 3: Restart Redis @@ -325,13 +270,7 @@ docker-compose restart redis # Logging -The Bitnami Redis Docker Image supports two different logging modes: logging to stdout, and -logging to a file. - -## Logging to stdout - -The default behavior is to log to stdout, as Docker expects. These will be collected by Docker, -converted to JSON and stored in the host, to be accessible via the `docker logs` command. +The Bitnami Redis Docker image sends the container logs to the `stdout`. To view the logs: ```bash docker logs redis @@ -343,29 +282,7 @@ or using Docker Compose: docker-compose logs redis ``` -This method of logging has the downside of not being easy to manage. Without an easy way to rotate -logs, they could grow exponentially and take up large amounts of disk space on your host. - -## Logging to file - -To log to file, run the Redis image, mounting a directory from your host at `/bitnami/redis/logs`. -This will instruct the container to send logs to a `redis-server.log` file in the mounted volume. - -```bash -docker run --name redis -v /path/to/redis/logs:/bitnami/redis/logs bitnami/redis -``` - -or using Docker Compose: - -``` -redis: - image: bitnami/redis - volumes: - - /path/to/redis/logs:/bitnami/redis/logs -``` - -To perform operations (e.g. logrotate) on the logs, mount the same directory in a container designed -to operate on log files, such as logstash. +You can configure the containers [logging driver](https://docs.docker.com/engine/admin/logging/overview/) using the `--log-driver` option if you wish to consume the container logs differently. In the default configuration docker uses the `json-file` driver. # Maintenance @@ -387,52 +304,40 @@ docker-compose stop redis ### Step 2: Run the backup command -We need to mount two volumes in a container we will use to create the backup: a directory on your -host to store the backup in, and the volumes from the container we just stopped so we can access the -data. +We need to mount two volumes in a container we will use to create the backup: a directory on your host to store the backup in, and the volumes from the container we just stopped so we can access the data. ```bash -docker run --rm -v /path/to/backups:/backups --volumes-from redis busybox \ - cp -a /bitnami/redis /backups/latest +docker run --rm -v /path/to/redis-backups:/backups --volumes-from redis busybox \ + cp -a /bitnami/redis:latest /backups/latest ``` or using Docker Compose: ```bash -docker run --rm -v /path/to/backups:/backups --volumes-from `docker-compose ps -q redis` busybox \ - cp -a /bitnami/redis /backups/latest +docker run --rm -v /path/to/redis-backups:/backups --volumes-from `docker-compose ps -q redis` busybox \ + cp -a /bitnami/redis:latest /backups/latest ``` -**Note!** -If you only need to backup database data, or configuration, you can change the first argument to -`cp` to `/bitnami/redis/data` or `/bitnami/redis/conf` respectively. - ## Restoring a backup Restoring a backup is as simple as mounting the backup as volumes in the container. ```bash -docker run -v /path/to/backups/latest/data:/bitnami/redis/data \ - -v /path/to/backups/latest/conf:/bitnami/redis/conf \ - -v /path/to/backups/latest/logs:/bitnami/redis/logs \ - bitnami/redis +docker run -v /path/to/redis-backups/latest:/bitnami/redis bitnami/redis:latest ``` or using Docker Compose: ``` redis: - image: bitnami/redis + image: bitnami/redis:latest volumes: - - /path/to/backups/latest/data:/bitnami/redis/data - - /path/to/backups/latest/conf:/bitnami/redis/conf - - /path/to/backups/latest/logs:/bitnami/redis/logs + - /path/to/redis-backups/latest:/bitnami/redis ``` ## Upgrade this image -Bitnami provides up-to-date versions of Redis, including security patches, soon after they are -made upstream. We recommend that you follow these steps to upgrade your container. +Bitnami provides up-to-date versions of Redis, including security patches, soon after they are made upstream. We recommend that you follow these steps to upgrade your container. ### Step 1: Get the updated image @@ -463,8 +368,7 @@ docker-compose rm -v redis ### Step 4: Run the new image -Re-create your container from the new image, [restoring your backup](#restoring-a-backup) if -necessary. +Re-create your container from the new image, [restoring your backup](#restoring-a-backup) if necessary. ```bash docker run --name redis bitnami/redis:latest @@ -478,32 +382,32 @@ docker-compose start redis # Testing -This image is tested for expected runtime behavior, using the -[Bats](https://github.com/sstephenson/bats) testing framework. You can run the tests on your machine -using the `bats` command. +This image is tested for expected runtime behavior, using the [Bats](https://github.com/sstephenson/bats) testing framework. You can run the tests on your machine using the `bats` command. ``` bats test.sh ``` +# Notable Changes + +## 3.2.0-r0 + +- All volumes have been merged at `/bitnami/redis`. Now you only need to mount a single volume at `/bitnami/redis` for persistence. +- The logs are always sent to the `stdout` and are no longer collected in the volume. + # Contributing -We'd love for you to contribute to this container. You can request new features by creating an -[issue](https://github.com/bitnami/bitnami-docker-redis/issues), or submit a -[pull request](https://github.com/bitnami/bitnami-docker-redis/pulls) with your contribution. +We'd love for you to contribute to this container. You can request new features by creating an [issue](https://github.com/bitnami/bitnami-docker-redis/issues), or submit a [pull request](https://github.com/bitnami/bitnami-docker-redis/pulls) with your contribution. # Issues -If you encountered a problem running this container, you can file an -[issue](https://github.com/bitnami/bitnami-docker-redis/issues). For us to provide better support, -be sure to include the following information in your issue: +If you encountered a problem running this container, you can file an [issue](https://github.com/bitnami/bitnami-docker-redis/issues). For us to provide better support, be sure to include the following information in your issue: - Host OS and version - Docker version (`docker version`) - Output of `docker info` - Version of this container (`echo $BITNAMI_APP_VERSION` inside the container) -- The command you used to run the container, and any relevant output you saw (masking any sensitive -information) +- The command you used to run the container, and any relevant output you saw (masking any sensitive information) # License Copyright 2015 Bitnami diff --git a/bitnami/redis/help.txt b/bitnami/redis/help.txt deleted file mode 100644 index 46c6374b695d..000000000000 --- a/bitnami/redis/help.txt +++ /dev/null @@ -1,28 +0,0 @@ - $BITNAMI_APP_NAME cheatsheet: - - ENVIRONMENT VARIABLES: - REDIS_PASSWORD: Password set at first boot for your $BITNAMI_APP_NAME server (default: none). - REDIS_REPLICATION_MODE: Replication mode. Possible values master/slave (default: none). - REDIS_MASTER_HOST: Hostname/IP of replication master (parameter available only on slave). - REDIS_MASTER_PORT: Port of replication master, defaults to 6379 (parameter available only on slave). - REDIS_MASTER_PASSWORD: Master auth password used by slave to authenticate with the master (default: none). - - VOLUMES: - $BITNAMI_APP_VOL_PREFIX/data: Location of $BITNAMI_APP_NAME database dump. - $BITNAMI_APP_VOL_PREFIX/conf: Location of redis.conf ($BITNAMI_APP_NAME config file). - $BITNAMI_APP_VOL_PREFIX/logs: Location of $BITNAMI_APP_NAME logs. - - PORTS: - 6379: Default $BITNAMI_APP_NAME port. - - MISC: - Options: You can add extra options during the docker run using the -- prefix. - Note: The password is only set the first time you run the container. - - COMMANDS: - print-help: Print this page. - check-updates: Check if a new version of the $BITNAMI_APP_NAME image is available. - - Visit $GITHUB_PAGE for more information. - - diff --git a/bitnami/redis/help.yaml b/bitnami/redis/help.yaml deleted file mode 100644 index 88b72b75c45f..000000000000 --- a/bitnami/redis/help.yaml +++ /dev/null @@ -1,15 +0,0 @@ -environment_variables: - REDIS_PASSWORD: "Password set at first boot for your $BITNAMI_APP_NAME server (default: none)." - REDIS_REPLICATION_MODE: "Replication mode. Possible values master/slave (default: none)." - REDIS_MASTER_HOST: "Hostname/IP of replication master (parameter available only on slave)." - REDIS_MASTER_PORT: "Port of replication master, defaults to 6379 (parameter available only on slave)." - REDIS_MASTER_PASSWORD: "Master auth password used by slave to authenticate with the master (default: none)." -volumes: - $BITNAMI_APP_VOL_PREFIX/data: "Location of $BITNAMI_APP_NAME database dump." - $BITNAMI_APP_VOL_PREFIX/conf: "Location of redis.conf ($BITNAMI_APP_NAME config file)." - $BITNAMI_APP_VOL_PREFIX/logs: "Location of $BITNAMI_APP_NAME logs." -ports: - 6379: "Default $BITNAMI_APP_NAME port." -misc: - Options: "You can add extra options during the docker run using the -- prefix." - Note: "The password is only set the first time you run the container." diff --git a/bitnami/redis/installer.run.sha256 b/bitnami/redis/installer.run.sha256 deleted file mode 100644 index 7d93b235f83c..000000000000 --- a/bitnami/redis/installer.run.sha256 +++ /dev/null @@ -1 +0,0 @@ -fb15b161119ccacdd95ce54ab51e134158e8841016d328f9133e701133f0b0a4 /tmp/installer.run \ No newline at end of file diff --git a/bitnami/redis/post-install.sh b/bitnami/redis/post-install.sh deleted file mode 100644 index c72cf9814920..000000000000 --- a/bitnami/redis/post-install.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -set -e - -cd $BITNAMI_APP_DIR - -# set up default config -mkdir $BITNAMI_APP_DIR/etc/conf.defaults -mv $BITNAMI_APP_DIR/etc/redis.conf $BITNAMI_APP_DIR/etc/conf.defaults -ln -s $BITNAMI_APP_DIR/etc/conf/redis.conf $BITNAMI_APP_DIR/etc/redis.conf - -# symlink mount points at root to install dir -ln -s $BITNAMI_APP_DIR/etc/conf $BITNAMI_APP_VOL_PREFIX/conf -ln -s $BITNAMI_APP_DIR/var/data $BITNAMI_APP_VOL_PREFIX/data -ln -s $BITNAMI_APP_DIR/var/log $BITNAMI_APP_VOL_PREFIX/logs diff --git a/bitnami/redis/rootfs/app-entrypoint.sh b/bitnami/redis/rootfs/app-entrypoint.sh new file mode 100755 index 000000000000..151df6aa5ee5 --- /dev/null +++ b/bitnami/redis/rootfs/app-entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e + +if [[ "$1" == "harpoon" && "$2" == "start" ]]; then + status=`harpoon inspect $BITNAMI_APP_NAME` + if [[ "$status" == *'"lifecycle": "unpacked"'* ]]; then + harpoon initialize $BITNAMI_APP_NAME \ + ${REDIS_PASSWORD:+--password $REDIS_PASSWORD} \ + ${REDIS_REPLICATION_MODE:+--replicationMode $REDIS_REPLICATION_MODE} \ + ${REDIS_MASTER_HOST:+--masterHost $REDIS_MASTER_HOST} \ + ${REDIS_MASTER_PORT:+--masterPort $REDIS_MASTER_PORT} \ + ${REDIS_MASTER_PASSWORD:+--masterPassword $REDIS_MASTER_PASSWORD} + fi + chown $BITNAMI_APP_USER: /bitnami/$BITNAMI_APP_NAME || true +fi + +exec /entrypoint.sh "$@" diff --git a/bitnami/redis/rootfs/bitnami-utils-custom.sh b/bitnami/redis/rootfs/bitnami-utils-custom.sh deleted file mode 100644 index a6977a5a0e93..000000000000 --- a/bitnami/redis/rootfs/bitnami-utils-custom.sh +++ /dev/null @@ -1,61 +0,0 @@ -# Redis Utility functions - -set_redis_password() { - if [ "$REDIS_PASSWORD" ]; then - echo "Setting redis password ..." - sed -i 's/# requirepass .*/requirepass '"$REDIS_PASSWORD"'/' $BITNAMI_APP_DIR/etc/conf/redis.conf - fi -} - -configure_replication() { - if [ "$REDIS_REPLICATION_MODE" == "slave" ]; then - echo "" - echo "==> Setting up Redis slave..." - - echo "==> Trying to fetch Redis replication parameters from the master link..." - REDIS_MASTER_HOST=${REDIS_MASTER_HOST:-$MASTER_PORT_6379_TCP_ADDR} - REDIS_MASTER_PORT=${REDIS_MASTER_PORT:-$MASTER_PORT_6379_TCP_PORT} - REDIS_MASTER_PASSWORD=${REDIS_MASTER_PASSWORD:-$MASTER_ENV_REDIS_PASSWORD} - - if [ ! $REDIS_MASTER_HOST ]; then - echo "In order to setup a replication slave you need to provide the REDIS_MASTER_HOST as well" - echo "" - exit -1 - fi - - if [ ! $REDIS_MASTER_PORT ]; then - echo "REDIS_MASTER_PORT not specified. Defaulting to 6379" - echo "" - POSTGRESQL_MASTER_PORT=${POSTGRESQL_MASTER_PORT:-6379} - fi - - echo "==> Checking if master is ready to accept connection (60s timeout)..." - timeout=60 - while ! redis-cli -h $REDIS_MASTER_HOST -p $REDIS_MASTER_PORT ${REDIS_MASTER_PASSWORD:+-a $REDIS_MASTER_PASSWORD} ping >/dev/null 2>&1 - do - timeout=$(expr $timeout - 1) - if [[ $timeout -eq 0 ]]; then - echo "" - echo "Could not connect to replication master" - echo "" - exit -1 - fi - sleep 1 - done - - echo "==> Setting the master configuration..." - sed 's|^[#]*[ ]*slaveof .*|slaveof '"$REDIS_MASTER_HOST"' '"$REDIS_MASTER_PORT"'|' -i $BITNAMI_APP_DIR/etc/conf/redis.conf - if [ $REDIS_MASTER_PASSWORD ]; then - sed 's|^[#]*[ ]*masterauth .*|masterauth '"$REDIS_MASTER_PASSWORD"'|' -i $BITNAMI_APP_DIR/etc/conf/redis.conf - fi - echo "" - fi -} - -print_redis_password() { - if [ -z $REDIS_PASSWORD ]; then - echo "**none**" - else - echo $REDIS_PASSWORD - fi -} diff --git a/bitnami/redis/rootfs/etc/cont-init.d/01-bitnami-redis b/bitnami/redis/rootfs/etc/cont-init.d/01-bitnami-redis deleted file mode 100755 index 94cdd40296f5..000000000000 --- a/bitnami/redis/rootfs/etc/cont-init.d/01-bitnami-redis +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/with-contenv bash -set -e -source $BITNAMI_PREFIX/bitnami-utils.sh - -if [ ! "$(ls -A $BITNAMI_APP_VOL_PREFIX/conf)" ]; then - generate_conf_files $BITNAMI_APP_DIR/etc - - set_redis_password - - print_app_credentials $BITNAMI_APP_NAME **none** `print_redis_password` -else - print_container_already_initialized $BITNAMI_APP_NAME -fi - -configure_replication - -chown -R $BITNAMI_APP_USER:$BITNAMI_APP_USER $BITNAMI_APP_VOL_PREFIX/data/ \ - $BITNAMI_APP_VOL_PREFIX/logs/ \ - $BITNAMI_APP_VOL_PREFIX/conf/ || true diff --git a/bitnami/redis/rootfs/etc/services.d/redis-logs/finish b/bitnami/redis/rootfs/etc/services.d/redis-logs/finish deleted file mode 120000 index 63b10de42114..000000000000 --- a/bitnami/redis/rootfs/etc/services.d/redis-logs/finish +++ /dev/null @@ -1 +0,0 @@ -/bin/true \ No newline at end of file diff --git a/bitnami/redis/rootfs/etc/services.d/redis-logs/run b/bitnami/redis/rootfs/etc/services.d/redis-logs/run deleted file mode 100755 index d98bbc00f057..000000000000 --- a/bitnami/redis/rootfs/etc/services.d/redis-logs/run +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/with-contenv bash -set -e -source $BITNAMI_PREFIX/bitnami-utils.sh - -exec s6-setuidgid $BITNAMI_APP_USER tail -f -n 1000 $BITNAMI_APP_VOL_PREFIX/logs/*.log 2>/dev/null diff --git a/bitnami/redis/rootfs/etc/services.d/redis/finish b/bitnami/redis/rootfs/etc/services.d/redis/finish deleted file mode 100755 index 9f54f1ccfc16..000000000000 --- a/bitnami/redis/rootfs/etc/services.d/redis/finish +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/with-contenv bash - -failcount=0 -if [ -f $BITNAMI_APP_DIR/tmp/failcount ]; then - failcount=$(cat $BITNAMI_APP_DIR/tmp/failcount) -fi - -start=$(cat $BITNAMI_APP_DIR/tmp/start) -stop=`date '+%d%H%M%S'` -interval=`expr $stop - $start` -if test $interval -lt 30 ; then - failcount=`expr $failcount + 1` -else - failcount=0 -fi -echo -n $failcount > $BITNAMI_APP_DIR/tmp/failcount - -# bring down container on frequent failures. something is definitely wrong -if test $failcount -ge 3 ; then - s6-svscanctl -t /var/run/s6/services -fi diff --git a/bitnami/redis/rootfs/etc/services.d/redis/run b/bitnami/redis/rootfs/etc/services.d/redis/run deleted file mode 100755 index dc0fbc1a9776..000000000000 --- a/bitnami/redis/rootfs/etc/services.d/redis/run +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/with-contenv bash -set -e -source $BITNAMI_PREFIX/bitnami-utils.sh - -mkdir -p $BITNAMI_APP_DIR/tmp -date '+%d%H%M%S' > $BITNAMI_APP_DIR/tmp/start -exec s6-setuidgid $BITNAMI_APP_USER $BITNAMI_APP_DAEMON $BITNAMI_APP_VOL_PREFIX/conf/redis.conf $PROGRAM_OPTIONS ${EXTRA_OPTIONS:+"$EXTRA_OPTIONS"} diff --git a/bitnami/redis/test.sh b/bitnami/redis/test.sh index 777ace5f91ca..f70f7805bce8 100644 --- a/bitnami/redis/test.sh +++ b/bitnami/redis/test.sh @@ -4,7 +4,9 @@ REDIS_PASSWORD=test_password123 # source the helper script APP_NAME=redis -SLEEP_TIME=5 +VOL_PREFIX=/bitnami/$APP_NAME +VOLUMES=$VOL_PREFIX +SLEEP_TIME=30 load tests/docker_helper # Link to container and execute redis client @@ -17,7 +19,7 @@ redis_client() { # Cleans up all running/stopped containers and host mounted volumes cleanup_environment() { container_remove_full default - container_remove_full slave + container_remove_full slave0 } # Teardown called at the end of each test @@ -28,35 +30,19 @@ teardown() { # cleanup the environment before starting the tests cleanup_environment -@test "Auth if no password provided" { +@test "Port 6379 exposed and accepting external connections" { container_create default -d + run redis_client default ping [[ "$output" =~ "PONG" ]] } -@test "Auth if password provided" { +@test "Authentication is enabled if password is specified" { container_create default -d \ -e REDIS_PASSWORD=$REDIS_PASSWORD run redis_client default ping - [[ "$output" =~ "NOAUTH Authentication required" ]] - - run redis_client default -a $REDIS_PASSWORD ping - [[ "$output" =~ "PONG" ]] -} - -@test "Password settings are preserved after restart" { - container_create default -d \ - -e REDIS_PASSWORD=$REDIS_PASSWORD - - run container_logs default - [[ "$output" =~ "Credentials for redis:" ]] - [[ "$output" =~ "Password: $REDIS_PASSWORD" ]] - - container_restart default - - run container_logs default - [[ "$output" =~ "The credentials were set on first boot." ]] + [[ "$output" =~ "Authentication required" ]] run redis_client default -a $REDIS_PASSWORD ping [[ "$output" =~ "PONG" ]] @@ -66,28 +52,30 @@ cleanup_environment container_create default -d run container_inspect default --format {{.Mounts}} - [[ "$output" =~ "$VOL_PREFIX/logs" ]] - [[ "$output" =~ "$VOL_PREFIX/conf" ]] - [[ "$output" =~ "$VOL_PREFIX/data" ]] + [[ "$output" =~ "$VOL_PREFIX" ]] } -@test "Data gets generated in conf, data and logs if bind mounted in the host" { +@test "Data gets generated in the volume if bind mounted" { container_create_with_host_volumes default -d # restart container to force redis-server to generate `dump.rdb` container_restart default - # files expected in conf volume - run container_exec default ls -la $VOL_PREFIX/conf/ - [[ "$output" =~ "redis.conf" ]] - - # files expected in data volume run container_exec default ls -la $VOL_PREFIX/data/ [[ "$output" =~ "dump.rdb" ]] - # files expected in logs volume - run container_exec default ls -la $VOL_PREFIX/logs/ - [[ "$output" =~ "redis-server.log" ]] + run container_exec default ls -la $VOL_PREFIX/conf/ + [[ "$output" =~ "redis.conf" ]] +} + +@test "Password settings are preserved after restart" { + container_create default -d \ + -e REDIS_PASSWORD=$REDIS_PASSWORD + + container_restart default + + run redis_client default -a $REDIS_PASSWORD ping + [[ "$output" =~ "PONG" ]] } @test "If host mounted, configuration and data persist" { @@ -97,13 +85,9 @@ cleanup_environment run redis_client default -a $REDIS_PASSWORD set winter 'is coming' [[ "$output" =~ "OK" ]] - # remove container container_remove default - - # recreate container without specifying any env parameters container_create_with_host_volumes default -d - # check if record exists run redis_client default -a $REDIS_PASSWORD get winter [[ "$output" =~ "is coming" ]] } @@ -127,143 +111,180 @@ cleanup_environment } @test "Can't setup replication slave without master host" { - # create replication slave without specifying REDIS_MASTER_HOST - run container_create slave \ + run container_create slave0 \ -e REDIS_REPLICATION_MODE=slave - [[ "$output" =~ "you need to provide the REDIS_MASTER_HOST" ]] + [[ "$output" =~ "provide the --masterHost property as well" ]] } -@test "Master data is replicated on slave" { +@test "Can setup master/slave replication without authentication" { container_create default -d \ -e REDIS_REPLICATION_MODE=master - container_create slave -d \ + container_create slave0 -d \ $(container_link default $CONTAINER_NAME) \ - -e REDIS_MASTER_HOST=$CONTAINER_NAME \ - -e REDIS_MASTER_PORT=6379 \ - -e REDIS_REPLICATION_MODE=slave + -e REDIS_REPLICATION_MODE=slave \ + -e REDIS_MASTER_HOST=$CONTAINER_NAME - # create record in master run redis_client default set winter 'is coming' [[ "$output" =~ "OK" ]] - # verify that record is replicated on slave - run redis_client slave get winter + run redis_client slave0 get winter [[ "$output" =~ "is coming" ]] } -@test "Master data is replicated on slave with authentication enabled" { +@test "Can setup master/slave replication with authentication" { container_create default -d \ - -e REDIS_PASSWORD=$REDIS_PASSWORD \ - -e REDIS_REPLICATION_MODE=master + -e REDIS_REPLICATION_MODE=master \ + -e REDIS_PASSWORD=$REDIS_PASSWORD - container_create slave -d \ + container_create slave0 -d \ $(container_link default $CONTAINER_NAME) \ + -e REDIS_REPLICATION_MODE=slave \ -e REDIS_MASTER_HOST=$CONTAINER_NAME \ - -e REDIS_MASTER_PORT=6379 \ - -e REDIS_MASTER_PASSWORD=$REDIS_PASSWORD \ - -e REDIS_PASSWORD=$REDIS_PASSWORD \ - -e REDIS_REPLICATION_MODE=slave + -e REDIS_MASTER_PASSWORD=$REDIS_PASSWORD - # create record in master run redis_client default -a $REDIS_PASSWORD set winter 'is coming' [[ "$output" =~ "OK" ]] - # verify that record is replicated on slave - run redis_client slave -a $REDIS_PASSWORD get winter + run redis_client slave0 get winter [[ "$output" =~ "is coming" ]] } -@test "Replication slave can fetch replication parameters from link alias \"master\"" { +@test "Can setup master/slave replication with authentication and a slave password" { container_create default -d \ - -e REDIS_PASSWORD=$REDIS_PASSWORD \ - -e REDIS_REPLICATION_MODE=master + -e REDIS_REPLICATION_MODE=master \ + -e REDIS_PASSWORD=$REDIS_PASSWORD - container_create slave -d \ - $(container_link default master) \ - -e REDIS_PASSWORD=$REDIS_PASSWORD \ - -e REDIS_REPLICATION_MODE=slave + container_create slave0 -d \ + $(container_link default $CONTAINER_NAME) \ + -e REDIS_REPLICATION_MODE=slave \ + -e REDIS_MASTER_HOST=$CONTAINER_NAME \ + -e REDIS_MASTER_PASSWORD=$REDIS_PASSWORD \ + -e REDIS_PASSWORD=$REDIS_PASSWORD - # create record in master run redis_client default -a $REDIS_PASSWORD set winter 'is coming' [[ "$output" =~ "OK" ]] - # verify that record is replicated on slave - run redis_client slave -a $REDIS_PASSWORD get winter + run redis_client slave0 -a $REDIS_PASSWORD get winter [[ "$output" =~ "is coming" ]] } @test "Slave synchronizes with the master (delayed start)" { container_create default -d \ - -e REDIS_PASSWORD=$REDIS_PASSWORD \ - -e REDIS_REPLICATION_MODE=master + -e REDIS_REPLICATION_MODE=master \ + -e REDIS_PASSWORD=$REDIS_PASSWORD - # create record in master run redis_client default -a $REDIS_PASSWORD set winter 'is coming' [[ "$output" =~ "OK" ]] - container_create slave -d \ + container_create slave0 -d \ $(container_link default $CONTAINER_NAME) \ + -e REDIS_REPLICATION_MODE=slave \ -e REDIS_MASTER_HOST=$CONTAINER_NAME \ - -e REDIS_MASTER_PORT=6379 \ -e REDIS_MASTER_PASSWORD=$REDIS_PASSWORD \ -e REDIS_PASSWORD=$REDIS_PASSWORD \ - -e REDIS_REPLICATION_MODE=slave - # verify that record is replicated on slave - run redis_client slave -a $REDIS_PASSWORD get winter + run redis_client slave0 -a $REDIS_PASSWORD get winter [[ "$output" =~ "is coming" ]] } -@test "Replication status is preserved after deletion" { +@test "Replication setup and state is preserved after restart" { container_create_with_host_volumes default -d \ - -e REDIS_PASSWORD=$REDIS_PASSWORD \ - -e REDIS_REPLICATION_MODE=master + -e REDIS_REPLICATION_MODE=master \ + -e REDIS_PASSWORD=$REDIS_PASSWORD - # create record in master run redis_client default -a $REDIS_PASSWORD set winter 'is coming' [[ "$output" =~ "OK" ]] - container_create_with_host_volumes slave -d \ + container_create_with_host_volumes slave0 -d \ $(container_link default $CONTAINER_NAME) \ + -e REDIS_REPLICATION_MODE=slave \ -e REDIS_MASTER_HOST=$CONTAINER_NAME \ - -e REDIS_MASTER_PORT=6379 \ -e REDIS_MASTER_PASSWORD=$REDIS_PASSWORD \ - -e REDIS_PASSWORD=$REDIS_PASSWORD \ - -e REDIS_REPLICATION_MODE=slave + -e REDIS_PASSWORD=$REDIS_PASSWORD - # stop and remove master and slave containers - container_remove slave - container_remove default + container_restart slave0 + container_restart default - # start master and slave containers with existing host volumes and no additional env arguments - container_create_with_host_volumes default -d - container_create_with_host_volumes slave -d $(container_link default $CONTAINER_NAME) - - # insert new record into the master run redis_client default -a $REDIS_PASSWORD set night 'is dark and full of terrors' [[ "$output" =~ "OK" ]] - # verify that all previous and new data is replicated on slave - run redis_client slave -a $REDIS_PASSWORD get winter + run redis_client slave0 -a $REDIS_PASSWORD get winter [[ "$output" =~ "is coming" ]] - run redis_client slave -a $REDIS_PASSWORD get night + run redis_client slave0 -a $REDIS_PASSWORD get night [[ "$output" =~ "is dark and full of terrors" ]] } +@test "Replication setup and state is preserved after deletion" { + container_create_with_host_volumes default -d \ + -e REDIS_REPLICATION_MODE=master \ + -e REDIS_PASSWORD=$REDIS_PASSWORD + + run redis_client default -a $REDIS_PASSWORD set winter 'is coming' + [[ "$output" =~ "OK" ]] + + container_create_with_host_volumes slave0 -d \ + $(container_link default $CONTAINER_NAME) \ + -e REDIS_REPLICATION_MODE=slave \ + -e REDIS_MASTER_HOST=$CONTAINER_NAME \ + -e REDIS_MASTER_PASSWORD=$REDIS_PASSWORD \ + -e REDIS_PASSWORD=$REDIS_PASSWORD + + container_remove slave0 + container_remove default + + container_create_with_host_volumes default -d + container_create_with_host_volumes slave0 -d $(container_link default $CONTAINER_NAME) + + run redis_client default -a $REDIS_PASSWORD set night 'is dark and full of terrors' + [[ "$output" =~ "OK" ]] + + run redis_client slave0 -a $REDIS_PASSWORD get winter + [[ "$output" =~ "is coming" ]] + + run redis_client slave0 -a $REDIS_PASSWORD get night + [[ "$output" =~ "is dark and full of terrors" ]] +} + +@test "Slave recovers if master is temporarily offine" { + container_create_with_host_volumes default -d \ + -e REDIS_REPLICATION_MODE=master \ + -e REDIS_PASSWORD=$REDIS_PASSWORD + + run redis_client default -a $REDIS_PASSWORD set winter 'is coming' + [[ "$output" =~ "OK" ]] + + container_create slave0 -d \ + $(container_link default $CONTAINER_NAME) \ + -e REDIS_REPLICATION_MODE=slave \ + -e REDIS_MASTER_HOST=$CONTAINER_NAME \ + -e REDIS_MASTER_PASSWORD=$REDIS_PASSWORD \ + -e REDIS_PASSWORD=$REDIS_PASSWORD + + container_restart default + + run redis_client default -a $REDIS_PASSWORD set dead 'may never die' + [[ "$output" =~ "OK" ]] + + run redis_client default -a $REDIS_PASSWORD get winter + [[ "$output" =~ "is coming" ]] + + run redis_client default -a $REDIS_PASSWORD get dead + [[ "$output" =~ "may never die" ]] +} + @test "Slave can be triggered to act as the master" { container_create default -d \ - -e REDIS_PASSWORD=$REDIS_PASSWORD \ - -e REDIS_REPLICATION_MODE=master + -e REDIS_REPLICATION_MODE=master \ + -e REDIS_PASSWORD=$REDIS_PASSWORD - container_create slave -d \ + container_create slave0 -d \ $(container_link default $CONTAINER_NAME) \ + -e REDIS_REPLICATION_MODE=slave \ -e REDIS_MASTER_HOST=$CONTAINER_NAME \ - -e REDIS_MASTER_PORT=6379 \ -e REDIS_MASTER_PASSWORD=$REDIS_PASSWORD \ - -e REDIS_PASSWORD=$REDIS_PASSWORD \ - -e REDIS_REPLICATION_MODE=slave + -e REDIS_PASSWORD=$REDIS_PASSWORD # create record in master run redis_client default -a $REDIS_PASSWORD set winter 'is coming' @@ -273,23 +294,22 @@ cleanup_environment container_remove default # convert slave to become master - run redis_client slave -a $REDIS_PASSWORD SLAVEOF NO ONE + run redis_client slave0 -a $REDIS_PASSWORD SLAVEOF NO ONE [[ "$output" =~ "OK" ]] # create container that configures slave as the master container_create default -d \ - $(container_link slave $CONTAINER_NAME) \ + $(container_link slave0 $CONTAINER_NAME) \ + -e REDIS_REPLICATION_MODE=slave \ -e REDIS_MASTER_HOST=$CONTAINER_NAME \ - -e REDIS_MASTER_PORT=6379 \ -e REDIS_MASTER_PASSWORD=$REDIS_PASSWORD \ - -e REDIS_PASSWORD=$REDIS_PASSWORD \ - -e REDIS_REPLICATION_MODE=slave + -e REDIS_PASSWORD=$REDIS_PASSWORD # insert new record into slave, since it is now the master it should allow writes - run redis_client slave -a $REDIS_PASSWORD set night 'is dark and full of terrors' + run redis_client slave0 -a $REDIS_PASSWORD set night 'is dark and full of terrors' [[ "$output" =~ "OK" ]] - # verify that all past and new data is replicated on default + # verify that all past and new data is replicated on new slave run redis_client default -a $REDIS_PASSWORD get winter [[ "$output" =~ "is coming" ]]