Skip to content

Commit 4607251

Browse files
committed
Use dedicated Redis service
1 parent 93258f6 commit 4607251

File tree

3 files changed

+103
-10
lines changed

3 files changed

+103
-10
lines changed

.nomad/apiary.nomad

+95
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ job "apiary" {
7575
type = "service"
7676

7777
group "apiary" {
78+
network {
79+
port "resp" {}
80+
}
81+
7882
volume "run" {
7983
type = "host"
8084
source = "run"
@@ -378,6 +382,97 @@ EOF
378382
}
379383
}
380384
}
385+
386+
dynamic "task" {
387+
for_each = var.run_background_containers ? ["redis"] : []
388+
389+
labels = [task.value]
390+
391+
content {
392+
driver = "docker"
393+
394+
lifecycle {
395+
hook = "prestart"
396+
sidecar = true
397+
}
398+
399+
config {
400+
image = "redis"
401+
402+
args = [
403+
"/usr/local/etc/redis/redis.conf"
404+
]
405+
406+
force_pull = true
407+
408+
network_mode = "host"
409+
410+
mount {
411+
type = "bind"
412+
source = "secrets/"
413+
target = "/usr/local/etc/redis/"
414+
}
415+
}
416+
417+
resources {
418+
cpu = 100
419+
memory = 256
420+
memory_max = 2048
421+
}
422+
423+
template {
424+
data = <<EOH
425+
bind 127.0.0.1
426+
port {{ env "NOMAD_PORT_resp" }}
427+
unixsocket /alloc/tmp/redis.sock
428+
unixsocketperm 777
429+
requirepass {{ env "NOMAD_ALLOC_ID" }}
430+
maxmemory {{ env "NOMAD_MEMORY_MAX_LIMIT" }}mb
431+
maxmemory-policy allkeys-lru
432+
EOH
433+
434+
destination = "secrets/redis.conf"
435+
}
436+
437+
service {
438+
name = "${NOMAD_JOB_NAME}-redis"
439+
440+
port = "resp"
441+
442+
address = "127.0.0.1"
443+
444+
tags = [
445+
"resp"
446+
]
447+
448+
check {
449+
success_before_passing = 3
450+
failures_before_critical = 2
451+
452+
interval = "5s"
453+
454+
name = "TCP"
455+
port = "resp"
456+
timeout = "1s"
457+
type = "tcp"
458+
}
459+
460+
check_restart {
461+
limit = 5
462+
grace = "20s"
463+
}
464+
}
465+
466+
restart {
467+
attempts = 5
468+
delay = "10s"
469+
interval = "1m"
470+
mode = "fail"
471+
}
472+
473+
shutdown_delay = "60s"
474+
}
475+
}
381476
}
382477

383478
reschedule {

.nomad/conf/.env.tpl

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ CAS_ENABLE_SAML="false"
1111
{{- range service "mysql" }}
1212
DB_SOCKET="{{- index .ServiceMeta "socket" | trimSpace -}}"
1313
{{ end }}
14-
REDIS_CLIENT="phpredis"
15-
REDIS_SCHEME="null"
16-
REDIS_PORT="-1"
17-
{{- range service "redis" }}
18-
REDIS_HOST="{{- index .ServiceMeta "socket" | trimSpace -}}"
19-
{{ end }}
20-
REDIS_PASSWORD="{{- key "redis/password" | trimSpace -}}"
2114
{{- range service "meilisearch-v1-10" }}
2215
MEILISEARCH_HOST="http://127.0.0.1:{{- .Port -}}"
2316
{{ end }}
@@ -36,3 +29,10 @@ HOME="/secrets/"
3629
RESPONSE_CACHE_HEADER_NAME="x-cache-time"
3730
RESPONSE_CACHE_AGE_HEADER_NAME="x-cache-age"
3831
RESPONSE_CACHE_AGE_HEADER=true
32+
REDIS_CLIENT="phpredis"
33+
REDIS_SCHEME="null"
34+
REDIS_PORT="-1"
35+
REDIS_HOST="/alloc/tmp/redis.sock"
36+
REDIS_PASSWORD="{{ env "NOMAD_ALLOC_ID" }}"
37+
REDIS_DB=0
38+
REDIS_CACHE_DB=1

.nomad/conf/www.conf

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ catch_workers_output = yes
1313
php_admin_value[date.timezone] = America/New_York
1414
{{ if ne (env "NOMAD_JOB_NAME") "apiary-sandbox" }}
1515
php_admin_value[session.save_handler] = redis
16-
{{- range service "redis" }}
17-
php_admin_value[session.save_path] = "unix://{{- index .ServiceMeta "socket" | trimSpace -}}?persistent=1&database={{- with (key "redis/session_database" | parseJSON) -}}{{- index . (env "NOMAD_JOB_NAME") -}}{{- end -}}&timeout=1&auth={{- key "redis/password" | trimSpace -}}"
18-
{{ end }}
16+
php_admin_value[session.save_path] = "unix:///alloc/tmp/redis.sock?persistent=1&database=2&timeout=1&auth={{ env "NOMAD_ALLOC_ID" }}"
1917
{{ end }}
2018
access.log = /proc/self/fd/2
2119
access.format = "%t %m %{REQUEST_URI}e %s %f %{mili}d %{kilo}M %C \"%{HTTP_USER_AGENT}e\"%"

0 commit comments

Comments
 (0)