From f37623821d54cf5dc050c559d4b471d9bfa15e83 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 29 Jan 2025 08:14:07 +0100 Subject: [PATCH] add varnish cache between tricot and plume --- cluster/prod/app/plume/config/app.env | 2 +- cluster/prod/app/plume/deploy/plume.hcl | 58 ++++++++++++++++++++----- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/cluster/prod/app/plume/config/app.env b/cluster/prod/app/plume/config/app.env index b663d81..36000c2 100644 --- a/cluster/prod/app/plume/config/app.env +++ b/cluster/prod/app/plume/config/app.env @@ -28,7 +28,7 @@ MIGRATION_DIRECTORY=migrations/postgres USE_HTTPS=0 ROCKET_ADDRESS=:: -ROCKET_PORT={{ env "NOMAD_PORT_web_port" }} +ROCKET_PORT={{ env "NOMAD_PORT_back_port" }} MEDIA_UPLOAD_DIRECTORY=/app/static/media SEARCH_INDEX=/app/search_index diff --git a/cluster/prod/app/plume/deploy/plume.hcl b/cluster/prod/app/plume/deploy/plume.hcl index d9e276e..c759a02 100644 --- a/cluster/prod/app/plume/deploy/plume.hcl +++ b/cluster/prod/app/plume/deploy/plume.hcl @@ -6,7 +6,45 @@ job "plume-blog" { count = 1 network { - port "web_port" { } + port "back_port" { } + port "cache_port" { } + } + + task "varnish" { + driver = "docker" + config { + image = "varnish:7.6.1" + network_mode = "host" + ports = [ "cache_port" ] + + # cache + mount { + type = "tmpfs" + target = "/var/lib/varnish/varnishd:exec" + readonly = false + tmpfs_options { + size = 2684354559 # 2.5GB in bytes + } + } + } + + env { + VARNISH_SIZE = "2G" + VARNISH_BACKEND_HOST = "localhost" + VARNISH_BACKEND_PORT = "${NOMAD_PORT_back_port}" + VARNISH_HTTP_PORT = "${NOMAD_PORT_cache_port}" + } + + service { + name = "plume-cache" + tags = [ + "plume", + "tricot plume.deuxfleurs.fr", + "d53-cname plume.deuxfleurs.fr", + ] + port = "cache_port" + address_mode = "host" + } } task "plume" { @@ -14,9 +52,9 @@ job "plume-blog" { config { image = "lxpz/plume_s3:v1" network_mode = "host" - ports = [ "web_port" ] + ports = [ "back_port" ] command = "sh" - args = [ "-c", "plm search init; plm search refill; plume" ] + args = [ "-c", "plm search init; plume" ] } template { @@ -26,24 +64,22 @@ job "plume-blog" { } resources { - memory = 1024 - memory_max = 1024 + memory = 512 + memory_max = 512 cpu = 100 } service { - name = "plume" + name = "plume-back" tags = [ "plume", - "tricot plume.deuxfleurs.fr", - "d53-cname plume.deuxfleurs.fr", ] - port = "web_port" + port = "back_port" address_mode = "host" check { type = "http" protocol = "http" - port = "web_port" + port = "back_port" path = "/" interval = "60s" timeout = "5s" @@ -55,7 +91,7 @@ job "plume-blog" { } } restart { - interval = "30m" + interval = "20m" attempts = 20 delay = "15s" mode = "delay"