Skip to content

Commit e673841

Browse files
authored
Redis commander: use connections file (#803)
* redis commander: use config file Ignore config.json fixes * Remove phony * Fixes * fixes * fixes
1 parent e3a02b2 commit e673841

File tree

8 files changed

+56
-79
lines changed

8 files changed

+56
-79
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
config.json

services/redis-commander/Makefile

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
.DEFAULT_GOAL := help
22

3-
4-
53
# Internal VARIABLES ------------------------------------------------
64
# STACK_NAME defaults to name of the current directory. Should not to be changed if you follow GitOps operating procedures.
75
STACK_NAME = $(notdir $(shell pwd))
@@ -24,24 +22,21 @@ up-letsencrypt-dns: .init .env ${TEMP_COMPOSE}-letsencrypt-dns
2422
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-letsencrypt-dns ${STACK_NAME}
2523

2624
.PHONY: up-dalco ## Deploys redis-commander stack for Dalco Cluster
27-
up-dalco: .init .env ${TEMP_COMPOSE}-dalco
28-
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-dalco ${STACK_NAME}
25+
up-dalco: up
2926

3027
.PHONY: up-master ## Deploys redis-commander stack for Master Cluster
31-
up-master: .init .env ${TEMP_COMPOSE}-master
32-
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-master ${STACK_NAME}
28+
up-master: up
3329

3430
.PHONY: up-public ## Deploys redis-commander stack for public access Cluster
35-
up-public: .init .env ${TEMP_COMPOSE}-public
36-
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-public ${STACK_NAME}
31+
up-public: up
3732

3833
.PHONY: up-local ## Deploys redis-commander stack for local deployment
3934
up-local: up
4035

4136
.PHONY: up-aws ## Deploys redis-commander stack in aws
42-
up-aws: .init .env ${TEMP_COMPOSE}-aws
43-
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-aws ${STACK_NAME}
37+
up-aws: up
4438

39+
docker-compose.yml: config.json
4540

4641
.PHONY: ${TEMP_COMPOSE}
4742
${TEMP_COMPOSE}: docker-compose.yml .env
@@ -55,18 +50,8 @@ ${TEMP_COMPOSE}-letsencrypt-http: docker-compose.yml docker-compose.letsencrypt.
5550
${TEMP_COMPOSE}-letsencrypt-dns: docker-compose.yml docker-compose.letsencrypt.dns.yml .env
5651
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.letsencrypt.dns.yml > $@
5752

58-
.PHONY: ${TEMP_COMPOSE}-dalco
59-
${TEMP_COMPOSE}-dalco: docker-compose.yml docker-compose.dalco.yml .env
60-
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.dalco.yml > $@
61-
62-
.PHONY: ${TEMP_COMPOSE}-public
63-
${TEMP_COMPOSE}-public: docker-compose.yml docker-compose.public.yml .env
64-
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.public.yml > $@
65-
66-
.PHONY: ${TEMP_COMPOSE}-master
67-
${TEMP_COMPOSE}-master: docker-compose.yml .env
68-
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< > $@
69-
70-
.PHONY: ${TEMP_COMPOSE}-aws
71-
${TEMP_COMPOSE}-aws: docker-compose.yml docker-compose.aws.yml .env
72-
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.aws.yml > $@
53+
config.json: config.json.j2 .env .venv
54+
# generate $@
55+
@$(call jinja, $<, $@)
56+
# validate and format $@
57+
@cat $@ | jq > /dev/null
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{%- macro redis_connection(label, host, port, username, password, index, secure) %}
2+
{
3+
"label": "{{ label }}",
4+
"host": "{{ host }}",
5+
"port": "{{ port }}",
6+
{%- if username %}
7+
"username": "{{ username }}",
8+
{%- endif %}
9+
"password": "{{ password }}",
10+
"dbIndex": {{ index }},
11+
"tls": {{ 'true' if secure.lower() in ['1', 'true', 'yes'] else 'false' }}
12+
}
13+
{%- endmacro %}
14+
{
15+
"connections": [
16+
{#- special if for DALCO. Remove once dalco is not special case anymore #}
17+
{%- if REDIS_STAGING_DATABASES %}
18+
{%- for label in REDIS_STAGING_DATABASES.strip(',').split(',') %}
19+
{{ redis_connection(label, REDIS_HOST, REDIS_PORT, REDIS_USER, REDIS_STAGING_PASSWORD, loop.index0, REDIS_SECURE) | indent(4) }},
20+
{%- endfor %}
21+
{%- endif %}
22+
{%- if REDIS_DATABASES %}
23+
{%- for label in REDIS_DATABASES.strip(',').split(',') %}
24+
{{ redis_connection(label, REDIS_HOST, REDIS_PORT, REDIS_USER, REDIS_PASSWORD, loop.index0, REDIS_SECURE) | indent(4) }}{%- if not loop.last %},{% endif %}
25+
{%- endfor %}
26+
{%- else %}
27+
{{ "REDIS_DATABASES must not be empty" / 0 }}
28+
{%- endif %}
29+
]
30+
}

services/redis-commander/docker-compose.aws.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

services/redis-commander/docker-compose.dalco.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

services/redis-commander/docker-compose.public.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

services/redis-commander/docker-compose.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
version: "3.7"
22
services:
33
redis-commander:
4-
image: rediscommander/redis-commander:snyk-fix-1841981ea4b1abcbc4c13e21d5d2997d
4+
image: ghcr.io/joeferner/redis-commander:0.8.1
55
init: true
66
ports:
77
- 8081
88
networks:
99
- monitored
1010
- public
11+
configs:
12+
- source: redis_commander_config
13+
target: /redis-commander/config/local.json
1114
environment:
12-
- >-
13-
REDIS_HOSTS=
14-
resources:${REDIS_HOST}:${REDIS_PORT}:0:${REDIS_PASSWORD},
15-
locks:${REDIS_HOST}:${REDIS_PORT}:1:${REDIS_PASSWORD},
16-
validation_codes:${REDIS_HOST}:${REDIS_PORT}:2:${REDIS_PASSWORD},
17-
scheduled_maintenance:${REDIS_HOST}:${REDIS_PORT}:3:${REDIS_PASSWORD},
18-
user_notifications:${REDIS_HOST}:${REDIS_PORT}:4:${REDIS_PASSWORD},
19-
announcements:${REDIS_HOST}:${REDIS_PORT}:5:${REDIS_PASSWORD},
20-
distributed_identifiers:${REDIS_HOST}:${REDIS_PORT}:6:${REDIS_PASSWORD},
21-
deferred_tasks:${REDIS_HOST}:${REDIS_PORT}:7:${REDIS_PASSWORD}
2215
- URL_PREFIX=/redis
2316
deploy:
17+
placement:
18+
constraints:
19+
- node.labels.ops == true
2420
labels:
2521
- traefik.enable=true
2622
- traefik.docker.network=${PUBLIC_NETWORK}
@@ -38,6 +34,10 @@ services:
3834
memory: 64M
3935
cpus: "0.1"
4036

37+
configs:
38+
redis_commander_config:
39+
file: ./config.json
40+
4141
networks:
4242
public:
4343
external: true

services/redis-commander/template.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ MONITORING_DOMAIN=${MONITORING_DOMAIN}
22
PREFIX_STACK_NAME=${PREFIX_STACK_NAME}
33
REDIS_HOST=${REDIS_HOST}
44
REDIS_PORT=${REDIS_PORT}
5+
REDIS_USER=${REDIS_USER}
56
REDIS_PASSWORD=${REDIS_PASSWORD}
7+
REDIS_SECURE=${REDIS_SECURE}
8+
REDIS_DATABASES=${REDIS_DATABASES}
69
REDIS_STAGING_PASSWORD=${REDIS_STAGING_PASSWORD}
10+
REDIS_STAGING_DATABASES=${REDIS_STAGING_DATABASES}
711
PUBLIC_NETWORK=${PUBLIC_NETWORK}
812
MONITORED_NETWORK=${MONITORED_NETWORK}

0 commit comments

Comments
 (0)