Skip to content

Commit 608571a

Browse files
authored
feat: add Redis Insight (#1)
1 parent 90c3b54 commit 608571a

File tree

7 files changed

+136
-14
lines changed

7 files changed

+136
-14
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<!-- If this PR changes logic, consider adding additional steps or context to the instructions below. -->
1414

1515
```bash
16+
ddev add-on get ddev/ddev-redis
1617
ddev add-on get https://github.com/stasadev/ddev-redis-insight/tarball/refs/pull/REPLACE_ME_WITH_THIS_PR_NUMBER/head
1718
ddev restart
1819
```

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@
77

88
## Overview
99

10+
[Redis Insight](https://redis.io/insight/) is a visual tool that provides capabilities to design, develop, and optimize your Redis application. Query, analyse and interact with your Redis data.
11+
1012
This add-on integrates Redis Insight into your [DDEV](https://ddev.com/) project.
1113

14+
## Requirements
15+
16+
Before installing this add-on, the [Redis service](https://github.com/ddev/ddev-redis) must be available:
17+
18+
```bash
19+
ddev add-on get ddev/ddev-redis
20+
```
21+
1222
## Installation
1323

1424
```bash
@@ -22,15 +32,21 @@ After installation, make sure to commit the `.ddev` directory to version control
2232

2333
| Command | Description |
2434
| ------- | ----------- |
35+
| `ddev redis-insight` | Open Redis Insight in your browser (`https://<project>.ddev.site:5540`) |
2536
| `ddev describe` | View service status and used ports for Redis Insight |
2637
| `ddev logs -s redis-insight` | Check Redis Insight logs |
2738

2839
## Advanced Customization
2940

41+
You may need to adjust the password depending on your Redis configuration:
42+
43+
* A `docker-compose.redis-insight_password.yaml` file is automatically created on install, if we detect that Redis needs one.
44+
* By default, the password is set via `RI_REDIS_PASSWORD=redis` in that file. If you modify it, be sure to remove the `#ddev-generated` comment to prevent your changes from being overwritten.
45+
3046
To change the Docker image:
3147

3248
```bash
33-
ddev dotenv set .ddev/.env.redis-insight --redis-insight-docker-image="busybox:stable"
49+
ddev dotenv set .ddev/.env.redis-insight --redis-insight-docker-image="redis/redisinsight:latest"
3450
ddev add-on get stasadev/ddev-redis-insight
3551
ddev restart
3652
```
@@ -41,7 +57,7 @@ All customization options (use with caution):
4157

4258
| Variable | Flag | Default |
4359
| -------- | ---- | ------- |
44-
| `REDIS_INSIGHT_DOCKER_IMAGE` | `--redis-insight-docker-image` | `busybox:stable` |
60+
| `REDIS_INSIGHT_DOCKER_IMAGE` | `--redis-insight-docker-image` | `redis/redisinsight:latest` |
4561

4662
## Credits
4763

commands/host/redis-insight

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
## #ddev-generated: If you want to edit and own this file, remove this line.
4+
## Description: Launch a browser with Redis Insight
5+
## Usage: redis-insight
6+
## Example: "ddev redis-insight"
7+
8+
# Determine whether to use HTTP or HTTPS based on environment
9+
PROTOCOL="HTTP"
10+
if [ "${DDEV_PRIMARY_URL%://*}" != "http" ] && [ -z "${GITPOD_WORKSPACE_ID:-}" ] && [ "${CODESPACES:-}" != "true" ]; then
11+
PROTOCOL="HTTPS"
12+
fi
13+
14+
# Fetch the appropriate port within the redis-insight container
15+
DDEV_REDIS_INSIGHT_PORT=$(ddev exec -s redis-insight sh -c "printenv | grep -w ${PROTOCOL}_EXPOSE | cut -d '=' -f 2 | cut -d ':' -f 1")
16+
17+
if [ -z "$DDEV_REDIS_INSIGHT_PORT" ]; then
18+
echo "Error: Could not retrieve Redis Insight port."
19+
exit 1
20+
fi
21+
22+
ddev launch :"$DDEV_REDIS_INSIGHT_PORT"

docker-compose.redis-insight.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
#ddev-generated
2-
# Simple template to demonstrate redis-insight
32
services:
43
redis-insight:
54
container_name: ddev-${DDEV_SITENAME}-redis-insight
6-
image: ${REDIS_INSIGHT_DOCKER_IMAGE:-busybox:stable}
7-
command: tail -f /dev/null
5+
image: ${REDIS_INSIGHT_DOCKER_IMAGE:-redis/redisinsight:latest}
86
restart: "no"
97
# These labels ensure this service is discoverable by DDEV.
108
labels:
119
com.ddev.site-name: ${DDEV_SITENAME}
1210
com.ddev.approot: ${DDEV_APPROOT}
13-
11+
environment:
12+
- RI_REDIS_HOST=redis
13+
- RI_REDIS_PORT=6379
14+
- RI_APP_PORT=5540
15+
- VIRTUAL_HOST=$DDEV_HOSTNAME
16+
- HTTP_EXPOSE=5539:5540
17+
- HTTPS_EXPOSE=5540:5540
1418
volumes:
1519
- ".:/mnt/ddev_config"
1620
- "ddev-global-cache:/mnt/ddev-global-cache"
21+
- redis-insight:/data
22+
23+
volumes:
24+
redis-insight:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ddev-generated
2+
# If omit_containers[ddev-router] then this file will be replaced
3+
# with another with a `ports` statement to directly expose port 5540 to 5540
4+
services: {}

install.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
11
name: redis-insight
22

3+
dependencies:
4+
- redis
5+
36
project_files:
47
- docker-compose.redis-insight.yaml
8+
- docker-compose.redis-insight_norouter.yaml
9+
- commands/host/redis-insight
510

611
ddev_version_constraint: '>= v1.24.3'
12+
13+
post_install_actions:
14+
- |
15+
#ddev-description:If router disabled, directly expose port
16+
if ( {{ contains "ddev-router" (list .DdevGlobalConfig.omit_containers | toString) }} ); then
17+
printf "#ddev-generated\nservices:\n redis-insight:\n ports:\n - 5540:5540\n" > docker-compose.redis-insight_norouter.yaml
18+
fi
19+
- |
20+
#ddev-description:If Redis is optimized, set a password
21+
if [ "$(ddev dotenv get .ddev/.env.redis --redis-optimized 2>/dev/null)" = "true" ]; then
22+
printf "#ddev-generated\nservices:\n redis-insight:\n environment:\n - RI_REDIS_PASSWORD=redis\n" > docker-compose.redis-insight_password.yaml
23+
fi
24+
- |
25+
echo "You can now use 'ddev redis-insight' to launch Redis Insight UI"
26+
27+
removal_actions:
28+
- |
29+
#ddev-description:Remove docker-compose.redis-insight_password.yaml file
30+
file=docker-compose.redis-insight_password.yaml
31+
if [ -f "${file}" ]; then
32+
if grep -q '#ddev-generated' "${file}"; then
33+
rm -f "${file}"
34+
else
35+
echo "Unwilling to remove '$DDEV_APPROOT/.ddev/${file}' because it does not have #ddev-generated in it; you can manually delete it if it is safe to delete."
36+
fi
37+
fi

tests/test.bats

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,43 @@ setup() {
3636
assert_success
3737
run ddev start -y
3838
assert_success
39+
40+
# Redis add-on is required for Redis Insight
41+
run ddev add-on get ddev/ddev-redis
42+
assert_success
43+
44+
export HAS_OPTIMIZED_CONFIG=false
3945
}
4046

4147
health_checks() {
42-
# Do something useful here that verifies the add-on
48+
if [ "$HAS_OPTIMIZED_CONFIG" = "true" ]; then
49+
assert_file_exist .ddev/docker-compose.redis-insight_password.yaml
50+
else
51+
assert_file_not_exist .ddev/docker-compose.redis-insight_password.yaml
52+
fi
4353

44-
# You can check for specific information in headers:
45-
# run curl -sfI https://${PROJNAME}.ddev.site
46-
# assert_output --partial "HTTP/2 200"
47-
# assert_output --partial "test_header"
54+
run curl -sfI http://${PROJNAME}.ddev.site:5539
55+
assert_success
56+
assert_output --partial "HTTP/1.1 200"
57+
assert_output --partial "X-Powered-By: Express"
4858

49-
# Or check if some command gives expected output:
50-
DDEV_DEBUG=true run ddev launch
59+
run curl -sf http://${PROJNAME}.ddev.site:5539
5160
assert_success
52-
assert_output --partial "FULLURL https://${PROJNAME}.ddev.site"
61+
assert_output --partial "<title>Redis Insight</title>"
62+
63+
run curl -sfI https://${PROJNAME}.ddev.site:5540
64+
assert_success
65+
assert_output --partial "HTTP/2 200"
66+
assert_output --partial "x-powered-by: Express"
67+
68+
run curl -sf https://${PROJNAME}.ddev.site:5540
69+
assert_success
70+
assert_output --partial "<title>Redis Insight</title>"
71+
72+
# Make sure `ddev redis-insight` works
73+
DDEV_DEBUG=true run ddev redis-insight
74+
assert_success
75+
assert_output --partial "FULLURL https://${PROJNAME}.ddev.site:5540"
5376
}
5477

5578
teardown() {
@@ -74,6 +97,23 @@ teardown() {
7497
health_checks
7598
}
7699

100+
@test "install from directory with optimized Redis" {
101+
set -eu -o pipefail
102+
103+
export HAS_OPTIMIZED_CONFIG=true
104+
105+
run ddev dotenv set .ddev/.env.redis --redis-optimized=true
106+
assert_success
107+
assert_file_exist .ddev/.env.redis
108+
109+
echo "# ddev add-on get ${DIR} with project ${PROJNAME} in $(pwd)" >&3
110+
run ddev add-on get "${DIR}"
111+
assert_success
112+
run ddev restart -y
113+
assert_success
114+
health_checks
115+
}
116+
77117
# bats test_tags=release
78118
@test "install from release" {
79119
set -eu -o pipefail

0 commit comments

Comments
 (0)