Skip to content

Commit

Permalink
Merge pull request #6 from oblakstudio/feat/tweaks
Browse files Browse the repository at this point in the history
feat: Additional work and tweaks
  • Loading branch information
seebeen authored Aug 14, 2023
2 parents 756c4c5 + b29d2bb commit 55f7332
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test_bleeding_edge.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Bleeding edge tests
name: Test Bleeding Edge DDEV
on:
schedule:
- cron: "25 08 1 * *"
- cron: "25 08 * * *"

workflow_dispatch:
inputs:
Expand Down
3 changes: 2 additions & 1 deletion .redisimageBuild/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
ARG BASE_IMAGE
FROM $BASE_IMAGE

COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
COPY ./docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
8 changes: 1 addition & 7 deletions .redisimageBuild/docker-entrypoint.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env sh
#ddev-generated - Do not modify this file; your modifications will be overwritten.
set -e

Expand All @@ -10,12 +10,6 @@ if [ "${1#-}" != "$1" ] || [ "${1%.conf}" != "$1" ]; then
set -- redis-server "$@"
fi

# allow the container to be started with `--user`
if [ "$1" = 'redis-server' ] && [ "$(id -u)" = '0' ]; then
find . \! -user redis -exec chown redis '{}' +
exec gosu redis "$0" "$@"
fi

# set an appropriate umask (if one isn't set already)
# - https://github.com/docker-library/redis/issues/305
# - https://github.com/redis/redis/blob/bb875603fb7ff3f9d19aad906bd45d7db98d9a39/utils/systemd-redis_server.service#L37
Expand Down
70 changes: 57 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,67 @@
[![tests](https://github.com/oblakstudio/ddev-redis-7/actions/workflows/tests.yml/badge.svg)](https://github.com/oblakstudio/ddev-redis-7/actions/workflows/tests.yml) ![project is maintained](https://img.shields.io/maintenance/yes/2023.svg)
<div align="center">

## What is this?
# ddev-redis-7 - Redis 7 container for DDEV

This repository allows you to quickly install redis into a [Ddev](https://ddev.readthedocs.io) project using just `ddev get oblakstudio/ddev-redis-7`.
![GitHub release (with filter)](https://img.shields.io/github/v/release/oblakstudio/ddev-redis-7)
[![Bleeding edge tests](https://github.com/oblakstudio/ddev-redis-7/actions/workflows/test_bleeding_edge.yml/badge.svg)](https://github.com/oblakstudio/ddev-redis-7/actions/workflows/test_bleeding_edge.yml)
[![E2E Tests](https://github.com/oblakstudio/ddev-redis-7/actions/workflows/test_stable.yml/badge.svg?event=push)](https://github.com/oblakstudio/ddev-redis-7/actions/workflows/tests.yml)
![project is maintained](https://img.shields.io/maintenance/yes/2024.svg)

</div>

This repository provides [Redis 7](https://redis.com) container for [DDEV](https://ddev.readthedocs.io/).

It is based on [redis:7.0.12-alpine](https://hub.docker.com/layers/library/redis/7.0.12-alpine/images/sha256-336ff85d67e89689913130cd7334d5eb67783d0e94362c6ce76314161aa1f0fd?context=explore) docker image and [DDEV custom compose files](https://ddev.readthedocs.io/en/stable/users/extend/custom-compose-files/)

## Comparison to official addon

There are a lot of differences between [official](https://github.com/ddev/ddev-redis) addon and this one

| Feature | ddev/ddev-redis | oblakstudio/ddev-redis-7 |
|-------------------|------------------|--------------------------|
| Maximum Memory | Unlimited | 512Mb |
| Persistence | No | **Yes** |
| Redis Version | 6.2.5 | 7.0.12 |
| Image Size | 39.9Mb | 10.34Mb |
| ARM Support | v7 | v8 |
| Anonymous Volumes | On every restart | **NO** |
| Optimized config | No | **Yes** |

### Anonymous volumes - Wait, what?

Official redis docker image mounts an anonymous volume on `/data` because... reasons. That volume is recreated on every restart. This one mounts the persistance directory on `/data` and names it according to the project name, and gives it a proper label. This way, each DDEV project has it's own data volume, and data can persist accordingly

### Persistance?

Yes, persistance. This image is configured to persist data on `/data` volume. This means that if you stop the container, and start it again, the data will be there. This is useful for long-term caching of data, and for keeping the cache primed between ddev restarts.

## Installation

1. `ddev get oblakstudio/ddev-redis-7`
2. `ddev restart`
```
$ ddev get oblakstudio/ddev-redis-7
$ ddev restart
```

>**Note:** Authentication is setup by default, and the password is `redis`. For latest AUTH support, username is also set to `redis`.

## Configuration

Redis configuration files are split in the `.ddev/redis/conf` folder, you can modify them as you wish.
Otherwise, plugin just works out of the box.

## Explanation
## Commands

<!-- This redis recipe for [ddev](https://ddev.readthedocs.io) installs a [`.ddev/docker-compose.redis.yaml`](docker-compose.redis.yaml) using the `redis` docker image. -->
## Commands

## Interacting with Redis
Addon exposes the following commands

* The Redis instance will listen on TCP port 6379 (the redis default).
* Configure your application to access redis on the host:port `redis:6379`.
* Authentication is setup by default, and the password is `redis`. For latest AUTH support, username is also set to `redis`.
* To reach the redis CLI interface, run `ddev redis-cli` to begin a session. You can also run Redis CLI commands directly on the command-line, e.g., `ddev redis-cli INFO`.
| Command | Usage | Description |
|-------------------|--------------------|------------------------------------|
| `redis` | `ddev redis` | Launches the **redis-cli** |
| `redis *COMMAND*` | `ddev redis` | Run an arbitrary redis-cli command |
| `redis-flush` | `ddev redis-flush` | Clears all the Redis Databases |
___

**Contributed and maintained by [@seebeen](https://github.com/seebeen) based on the original [ddev-contrib recipe](https://github.com/drud/ddev-contrib/tree/master/docker-compose-services/redis) by [@gormus](https://github.com/gormus)**
**Based on the original [ddev-contrib recipe](https://github.com/ddev/ddev-contrib/tree/master/docker-compose-services/mongodb)**
**Developed and maintained by [Oblak Studio](https://github.com/oblakstudio)**
2 changes: 1 addition & 1 deletion commands/redis/redis
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
#ddev-generated
## Description: Run redis-cli inside the redis container
## Usage: redis [flags] [args]
Expand Down
7 changes: 7 additions & 0 deletions commands/redis/redis-flush
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
#ddev-generated
## Description: Run redis-cli inside the redis container
## Usage: redis-flush
## Example: "redis-flush"

redis-cli -a redis --no-auth-warning FLUSHALL ASYNC
2 changes: 1 addition & 1 deletion docker-compose.redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
container_name: ddev-${DDEV_SITENAME}-redis
build:
args:
BASE_IMAGE: redis:7
BASE_IMAGE: redis:7.0.12-alpine
context: ".redisimageBuild"
dockerfile: Dockerfile
no_cache: true
Expand Down
1 change: 1 addition & 0 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ project_files:
- .redisimageBuild/docker-entrypoint.sh
- .redisimageBuild/Dockerfile
- commands/redis/redis
- commands/redis/redis-flush
- redis/conf/redis.conf
- redis/conf/advanced.conf
- redis/conf/append.conf
Expand Down
6 changes: 5 additions & 1 deletion redis/conf/advanced.conf
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ rdb-save-incremental-fsync yes
# lfu-log-factor 10
# lfu-decay-time 1

############################## DEBUG COMMAND #############################

enable-debug-command yes

########################### ACTIVE DEFRAGMENTATION #######################
#
# What is active defragmentation?
Expand Down Expand Up @@ -334,4 +338,4 @@ jemalloc-bg-thread yes
# aof_rewrite_cpulist 8-11
#
# Set bgsave child process to cpu affinity 1,10,11
# bgsave_cpulist 1,10-11
# bgsave_cpulist 1,10-11
4 changes: 2 additions & 2 deletions redis/conf/memory.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# limit for maxmemory so that there is some free RAM on the system for replica
# output buffers (but this is not needed if the policy is 'noeviction').
#
maxmemory 256mb
maxmemory 512mb

# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select one from the following behaviors:
Expand Down Expand Up @@ -139,4 +139,4 @@ replica-lazy-flush no
# command to act exactly like UNLINK, using the following configuration
# directive:

lazyfree-lazy-user-del no
lazyfree-lazy-user-del no
12 changes: 6 additions & 6 deletions redis/conf/snapshots.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
# number of write operations against the DB occurred.
#
# In the example below the behavior will be to save:
# after 900 sec (15 min) if at least 1 key changed
# after 300 sec (5 min) if at least 10 keys changed
# after 60 sec if at least 10000 keys changed
# after 300 sec (5 min) if at least 1 key changed
# after 150 sec (2.5 min) if at least 10 keys changed
# after 30 sec if at least 10000 keys changed
#
# Note: you can disable saving completely by commenting out all "save" lines.
#
Expand All @@ -20,9 +20,9 @@
# like in the following example:
#
# save ""
save 900 1
save 300 10
save 60 10000
save 300 1
save 150 10
save 30 10000

# By default Redis will stop accepting writes if RDB snapshots are enabled
# (at least one save point) and the latest background save failed.
Expand Down
26 changes: 20 additions & 6 deletions tests/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,33 @@ health_checks() {
assert_success
run bash -c "ddev start -y"
assert_success
# Make sure we can hit the 8090 port successfully
# curl -s -I -f https://${PROJNAME}.ddev.site:8090 >/tmp/curlout.txt

# # Make sure `ddev redis` works
# run bash -c "DDEV_DEBUG=true ddev redis"
# assert_success
# assert_output "FULLURL https://${PROJNAME}.ddev.site:8090"
run bash -c "DDEV_DEBUG=true ddev redis --version"
assert_success
assert_output "redis-cli 7.0.12"

# # Keys should be an empty array
run bash -c 'ddev redis "KEYS \*"'
assert_success
assert_output ""

# # Set a key
run bash -c "ddev redis DEBUG POPULATE 10000 TestKey"
assert_success

# # Get the number of keys
run bash -c "ddev redis DBSIZE"
assert_success
assert_output "10000"
}

teardown() {
set -eu -o pipefail
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1
[ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR}
ddev poweroff
}

@test "install from directory" {
Expand All @@ -52,6 +66,6 @@ teardown() {
set -eu -o pipefail
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
echo "# ddev get oblakstudio/ddev-redis with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
health_checks "oblakstudio/ddev-redis"
health_checks "oblakstudio/ddev-redis-7"
}

0 comments on commit 55f7332

Please sign in to comment.