Skip to content

Commit 372d22c

Browse files
authored
Varnish + nginx for tiler cache (#747)
* Add varnish config * Update varnish config and remove nginx cache * Update traefik for varnish * Update congif forvarnish y clean the tiles in a bash * Update varnish purge config * Fix varnish config * Fix tiler viewer * Remove unused env vars for tiler-cache * Update docker config * Remove logic to remove tiler from s3 - tegola * Rename varnish folder * Fix VARNISH_TILE_URL_PREFIX to pass ohm, ohm_admin and ohm_other_boundaries * Update config to deploy
1 parent 6af3a35 commit 372d22c

20 files changed

Lines changed: 561 additions & 542 deletions

File tree

.github/workflows/chartpress.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
branches:
55
- 'main'
66
- 'staging'
7-
- 'req_fresh_tiles'
7+
- 'varnish_tiler'
88
jobs:
99
build:
1010
runs-on: ubuntu-22.04
@@ -71,7 +71,7 @@ jobs:
7171
OHM_SLACK_WEBHOOK_URL: ${{ secrets.OHM_SLACK_WEBHOOK_URL }}
7272
################ Staging secrets ################
7373
- name: Staging - substitute secrets
74-
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/req_fresh_tiles'
74+
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/varnish_tiler'
7575
uses: bluwy/substitute-string-action@v1
7676
with:
7777
_input-file: 'values.staging.template.yaml'
@@ -189,14 +189,14 @@ jobs:
189189
PRODUCTION_OPENSTREETMAP_AUTH_SECRET: ${{ secrets.PRODUCTION_OPENSTREETMAP_AUTH_SECRET }}
190190

191191
- name: AWS Credentials
192-
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/req_fresh_tiles'
192+
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/varnish_tiler'
193193
uses: aws-actions/configure-aws-credentials@v1
194194
with:
195195
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
196196
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
197197
aws-region: us-east-1
198198
- name: Setup Kubectl and Helm Dependencies
199-
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/req_fresh_tiles'
199+
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/varnish_tiler'
200200
run: |
201201
sudo pip install awscli --ignore-installed six
202202
sudo curl -L -o /usr/bin/kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.17.7/2020-07-08/bin/linux/amd64/kubectl
@@ -210,22 +210,22 @@ jobs:
210210
helm version
211211
212212
- name: Update kube-config staging
213-
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/req_fresh_tiles'
213+
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/varnish_tiler'
214214
run: aws eks --region us-east-1 update-kubeconfig --name osmseed-staging
215215
- name: Update kube-config prod
216216
if: github.ref == 'refs/heads/main'
217217
run: aws eks --region us-east-1 update-kubeconfig --name osmseed-production-v2
218218
- name: Add Helm repository
219-
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/req_fresh_tiles'
219+
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/varnish_tiler'
220220
run: |
221221
helm repo add osm-seed https://osm-seed.github.io/osm-seed-chart/
222222
helm repo update
223223
- name: Install helm dependencies for
224-
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/req_fresh_tiles'
224+
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/varnish_tiler'
225225
run: cd ohm && helm dep up
226226
# Staging
227227
- name: Staging - helm deploy
228-
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/req_fresh_tiles'
228+
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/varnish_tiler'
229229
run: helm upgrade --install staging --wait ohm/ -f values.staging.yaml -f ohm/values.yaml
230230
# Production
231231
- name: Production - helm deploy

compose/martin.yml

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1-
# Martin tile server
2-
# Cache invalidation: nginx TTLs per zoom + manual purge via ?purge=1 query param.
3-
# No external purge service needed.
1+
# Martin tile server + Varnish cache
2+
# Caching: Varnish only. Nginx in Martin does routing/gzip/tilejson/static.
3+
# Invalidation: BAN requests from tiler-cache (replaces TTL-based invalidation).
44
services:
5+
varnish:
6+
image: varnish:7.5
7+
container_name: varnish
8+
ports:
9+
- "6081:6081"
10+
volumes:
11+
- ../images/tiler-varnish/default.vcl:/etc/varnish/default.vcl:ro
12+
command: >
13+
varnishd -F
14+
-a :6081
15+
-f /etc/varnish/default.vcl
16+
-s dynamic=malloc,${VARNISH_DYNAMIC_SIZE:-2G}
17+
-s static=malloc,${VARNISH_STATIC_SIZE:-1G}
18+
networks:
19+
- ohm_network
20+
depends_on:
21+
- martin
22+
523
martin:
624
container_name: martin
725
image: rub21/tiler-server-martin:v1
@@ -10,21 +28,51 @@ services:
1028
dockerfile: Dockerfile
1129
volumes:
1230
- ../images/tiler-server-martin:/app
13-
- martin_nginx_cache:/var/cache/nginx
1431
ports:
1532
- "3020:80"
33+
expose:
34+
- "3001"
1635
env_file:
1736
- ../envs/.env.tiler
1837
environment:
1938
- OHM_DOMAIN=${OHM_DOMAIN:-openhistoricalmap.org}
20-
# restart: always
2139
networks:
2240
- ohm_network
2341

24-
volumes:
25-
martin_nginx_cache:
26-
driver: local
27-
name: martin_nginx_cache
42+
tiler-cache:
43+
container_name: tiler-cache
44+
image: ohm/tiler-cache:latest
45+
build:
46+
context: ../images/tiler-cache
47+
dockerfile: Dockerfile
48+
volumes:
49+
- ../images/tiler-cache:/app
50+
ports:
51+
- "8000:8000"
52+
command:
53+
- /bin/sh
54+
- -c
55+
- |
56+
set -x
57+
python sqs_processor.py &
58+
python main.py
59+
env_file:
60+
- ../envs/.env.tiler
61+
environment:
62+
- PORT=8000
63+
- TILE_CACHE_BACKEND=varnish
64+
- VARNISH_URL=http://varnish:6081
65+
restart: always
66+
healthcheck:
67+
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health').read()"]
68+
interval: 30s
69+
timeout: 10s
70+
retries: 3
71+
start_period: 40s
72+
networks:
73+
- ohm_network
74+
depends_on:
75+
- varnish
2876

2977
networks:
3078
ohm_network:

hetzner/start_all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ echo "########################## ENVIRONMENT -> $ENVIRONMENT ###################
2020
source "$SCRIPT_DIR/.env.traefik"
2121
echo "########################## OHM_DOMAIN -> $OHM_DOMAIN ##########################"
2222

23-
# ###################### Tiler ######################
23+
###################### Tiler ######################
2424
./hetzner/deploy.sh start tiler $ENVIRONMENT -y
2525

2626
# ###################### Osmcha ######################

hetzner/tiler/env.production.example

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,13 @@ TILER_CACHE_AWS_SECRET_ACCESS_KEY=hetzner_credentials
4747
TILER_CACHE_AWS_ENDPOINT=https://hel1.your-objectstorage.com
4848

4949
# #######################################
50-
# tiler cache
50+
# tiler cache (Varnish BAN invalidator)
5151
# #######################################
5252
AWS_REGION_NAME=us-east-1
5353
AWS_ACCESS_KEY_ID=xxxx
5454
AWS_SECRET_ACCESS_KEY=yyyyy
5555
SQS_QUEUE_URL=https://sqs.us-east-1.amazonaws.com/1234567890/tiler-imposm3
5656
ENVIRONMENT=production
57-
DOCKER_IMAGE=none
58-
NODEGROUP_TYPE=web_large
59-
MAX_ACTIVE_JOBS=10
60-
DELETE_OLD_JOBS_AGE=3600
61-
EXECUTE_PURGE=true
62-
EXECUTE_SEED=false
63-
PURGE_MIN_ZOOM=3
64-
PURGE_MAX_ZOOM=10
65-
SEED_MIN_ZOOM=0
66-
SEED_MAX_ZOOM=8
67-
SEED_CONCURRENCY=64
68-
PURGE_CONCURRENCY=64
6957
ZOOM_LEVELS_TO_DELETE=8,9,10,11,12,13,14,15,16,17,18,19,20
70-
S3_BUCKET_CACHE_TILER=tiler-cache-bucket
71-
S3_BUCKET_PATH_FILES=mnt/data/osm
58+
ENABLE_DELAYED_CLEANUP=true
59+
VARNISH_URL=http://varnish:6081

hetzner/tiler/tiler.base.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
services:
2-
tiler_server:
3-
container_name: tiler_server
4-
image: ghcr.io/openhistoricalmap/tiler-server:0.0.1-0.dev.git.3296.h0e45d176
5-
# image: tiler-server:staging
6-
# build:
7-
# context: ../../images/tiler-server
8-
# dockerfile: Dockerfile
9-
# ports:
10-
# - "9090:9090"
2+
tiler_server_martin:
3+
container_name: tiler_server_martin
4+
image: ghcr.io/openhistoricalmap/tiler-server-martin:0.0.1-0.dev.git.3352.h1c81647b
5+
restart: always
6+
environment:
7+
- OHM_DOMAIN=${OHM_DOMAIN:-openhistoricalmap.org}
118
env_file:
129
- .env.tiler
13-
restart: always
14-
# volumes:
15-
# - ../../images/tiler-server/start.sh:/app/start.sh:ro
10+
ports:
11+
- "3030:80"
12+
volumes:
13+
- tiler_martin_nginx_cache:/var/cache/nginx
1614
networks:
1715
- ohm_network
1816

hetzner/tiler/tiler.production.yml

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,9 @@ services:
3737
networks:
3838
- ohm_network
3939

40-
# Tiler server
41-
tiler_server:
42-
container_name: tiler_server
43-
image: ghcr.io/openhistoricalmap/tiler-server:0.0.1-0.dev.git.3292.h0f5e7d60
44-
# ports:
45-
# - "9090:9090"
46-
restart: always
47-
networks:
48-
- ohm_network
49-
5040
tiler_sqs_cleaner:
5141
container_name: tiler_sqs_cleaner
52-
image: ghcr.io/openhistoricalmap/tiler-cache:0.0.1-0.dev.git.3290.h63549fc1
42+
image: ghcr.io/openhistoricalmap/tiler-cache:0.0.1-0.dev.git.3357.h3c23a908
5343
environment:
5444
- PORT=8000
5545
env_file:
@@ -70,55 +60,6 @@ services:
7060
networks:
7161
- ohm_network
7262

73-
tiler_s3_cleaner:
74-
container_name: tiler_s3_cleaner
75-
image: ghcr.io/openhistoricalmap/tiler-cache:0.0.1-0.dev.git.3290.h63549fc1
76-
# image: tiler-cache:latest
77-
# build:
78-
# context: ../../images/tiler-cache
79-
# dockerfile: Dockerfile
80-
command:
81-
- /bin/sh
82-
- -c
83-
- |
84-
tiler-cache-cleaner clean_by_prefix --prefix-path-file mnt/data/ohm
85-
tiler-cache-cleaner clean_by_prefix --prefix-path-file mnt/data/ohm_admin
86-
tiler-cache-cleaner clean_by_prefix --prefix-path-file mnt/data/ohm_other_boundaries
87-
env_file:
88-
- .env.tiler
89-
networks:
90-
- ohm_network
91-
92-
tile_global_seeding:
93-
container_name: tiler_global_seeding
94-
image: ghcr.io/openhistoricalmap/tiler-server:0.0.1-0.dev.git.3296.h0e45d176
95-
env_file:
96-
- .env.tiler
97-
volumes:
98-
- ./seed.sh:/opt/seed.sh
99-
entrypoint:
100-
- /bin/bash
101-
- "-c"
102-
- |
103-
/opt/seed.sh global
104-
networks:
105-
- ohm_network
106-
107-
tile_coverage_seeding:
108-
container_name: tiler_coverage_seeding
109-
image: ghcr.io/openhistoricalmap/tiler-server:0.0.1-0.dev.git.3296.h0e45d176
110-
volumes:
111-
- ./seed.sh:/opt/seed.sh
112-
entrypoint:
113-
- /bin/bash
114-
- "-c"
115-
- |
116-
/opt/seed.sh coverage
117-
env_file:
118-
- .env.tiler
119-
networks:
120-
- ohm_network
121-
12263
tiler_monitor:
12364
container_name: tiler_monitor
12465
image: ghcr.io/openhistoricalmap/tiler-monitor:0.0.1-0.dev.git.3348.h4fbb83d8
@@ -138,7 +79,7 @@ services:
13879

13980
tiler_server_martin:
14081
container_name: tiler_server_martin
141-
image: ghcr.io/openhistoricalmap/tiler-server-martin:0.0.1-0.dev.git.3357.he67b0015
82+
image: ghcr.io/openhistoricalmap/tiler-server-martin:0.0.1-0.dev.git.3352.h1c81647b
14283
restart: always
14384
environment:
14485
- OHM_DOMAIN=${OHM_DOMAIN:-openhistoricalmap.org}

hetzner/tiler/tiler.staging.yml

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,5 @@
11
services:
2-
tiler_db:
3-
container_name: tiler_db
4-
image: ghcr.io/openhistoricalmap/tiler-db:0.0.1-0.dev.git.2166.hc55c4cd
5-
volumes:
6-
- tiler_pgdata:/var/lib/postgresql/data
7-
- ./config/postgresql.staging.conf:/etc/postgresql/postgresql.conf
8-
environment:
9-
- PGDATA=/var/lib/postgresql/data
10-
- POSTGRES_CONFIG_FILE=/etc/postgresql/postgresql.conf
11-
command:
12-
- postgres
13-
- "-c"
14-
- "config_file=/etc/postgresql/postgresql.conf"
15-
ports:
16-
- "5432:5432"
17-
env_file:
18-
- .env.tiler
19-
networks:
20-
- ohm_network
21-
tiler_imposm:
22-
container_name: tiler_imposm
23-
# image: ghcr.io/openhistoricalmap/tiler-imposm:0.0.1-0.dev.git.3208.h6ef73bb
24-
image: tiler-imposm:staging
25-
build:
26-
context: ../../images/tiler-imposm
27-
dockerfile: Dockerfile
28-
volumes:
29-
- tiler_imposm_data:/mnt/data
30-
command:
31-
- sh
32-
- -c
33-
- |
34-
./start.sh
35-
env_file:
36-
- .env.tiler
37-
restart: always
38-
networks:
39-
- ohm_network
2+
403
volumes:
414
tiler_pgdata:
425
driver: local

hetzner/traefik/traefik.template.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ http:
8484
rule: Host(`vtiles.{{OHM_DOMAIN}}`)
8585
entryPoints:
8686
- port-web
87-
service: tiler_server_martin
87+
service: varnish_tiles
8888
middlewares:
8989
- secure-headers-allow-iframe
9090
- replace-osm-tiles-to-ohm
@@ -130,14 +130,6 @@ http:
130130
middlewares:
131131
- secure-headers
132132

133-
martin-router:
134-
rule: Host(`martin.{{OHM_DOMAIN}}`)
135-
entryPoints:
136-
- port-web
137-
service: tiler_server_martin
138-
middlewares:
139-
- secure-headers
140-
141133
node-exporter-router:
142134
rule: Host(`node-exporter.{{OHM_DOMAIN}}`)
143135
entryPoints:
@@ -193,10 +185,10 @@ http:
193185
servers:
194186
- url: http://taginfo_web:4567
195187

196-
tiler_server_martin:
188+
varnish_tiles:
197189
loadBalancer:
198190
servers:
199-
- url: http://tiler_server_martin:80
191+
- url: http://varnish:6081
200192

201193
node_exporter:
202194
loadBalancer:

images/tiler-cache/Dockerfile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
FROM python:3.10
22

3-
# Install kubectl
4-
ARG KUBECTL_VERSION=v1.30.1
5-
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl \
6-
&& chmod +x kubectl \
7-
&& mv kubectl /usr/local/bin/
8-
RUN kubectl version --client
93
WORKDIR /app
104
RUN echo "installing requirements"
115
COPY ./requirements.txt .

0 commit comments

Comments
 (0)