Skip to content

Commit e2a5961

Browse files
author
Ruben Lopez M
authored
Merge pull request #191 from developmentseed/tiler_s3_cache
S3 cache Deployment - Tiler
2 parents cc49f05 + d1de7c4 commit e2a5961

File tree

13 files changed

+306
-79
lines changed

13 files changed

+306
-79
lines changed

.env-tiler.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ POSTGRES_DB=tiler-osm
1919
POSTGRES_USER=postgres
2020
POSTGRES_PASSWORD=1234
2121
POSTGRES_PORT=5432
22+
POSTGRES_DB_MAX_CONNECTIONS=200
2223

2324
# ====================================================================================================
2425
# tiler-imposm evn variables

.github/workflows/chartpress.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
run: git config --global user.email "[email protected]" && git config --global user.name "Github Action"
1919
- name: Install Chartpress
2020
run: |
21-
pip install -v chartpress
21+
pip install -v chartpress && pip install six
2222
- name: Run Chartpress
2323
run: chartpress --push --publish-chart
2424
env:

images/tiler-db/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ COPY ./config/docker-entrypoint.sh /usr/local/bin/
66
RUN mkdir -p /docker-entrypoint-initdb.d
77
COPY ./config/initdb_db.sh /docker-entrypoint-initdb.d/postgis.sh
88
COPY ./config/update_db.sh /usr/local/bin
9+
COPY ./config/update_postgresql.sh /docker-entrypoint-initdb.d
910

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
# max_connections
4+
if [[ "${POSTGRES_DB_MAX_CONNECTIONS}X" != "X" ]]; then
5+
sed -i -e"s/^.*max_connections =.*$/max_connections = $POSTGRES_DB_MAX_CONNECTIONS/" $PGDATA/postgresql.conf
6+
fi
7+
8+
# shared_buffers
9+
if [[ "${POSTGRES_DB_SHARED_BUFFERS}X" != "X" ]]; then
10+
sed -i -e"s/^.*shared_buffers =.*$/shared_buffers = $POSTGRES_DB_SHARED_BUFFERS/" $PGDATA/postgresql.conf
11+
fi
12+
13+
# work_mem
14+
if [[ "${POSTGRES_DB_WORK_MEM}X" != "X" ]]; then
15+
sed -i -e"s/^.*#work_mem =.*$/work_mem = $POSTGRES_DB_WORK_MEM/" $PGDATA/postgresql.conf
16+
fi
17+
18+
# maintenance_work_mem
19+
if [[ "${POSTGRES_DB_MAINTENANCE_WORK_MEM}X" != "X" ]]; then
20+
sed -i -e"s/^.*maintenance_work_mem =.*$/maintenance_work_mem = $POSTGRES_DB_MAINTENANCE_WORK_MEM/" $PGDATA/postgresql.conf
21+
fi
22+
23+
# effective_cache_size
24+
if [[ "${POSTGRES_DB_EFFECTIVE_CACHE_SIZE}X" != "X" ]]; then
25+
sed -i -e"s/^.*effective_cache_size =.*$/effective_cache_size = $POSTGRES_DB_EFFECTIVE_CACHE_SIZE/" $PGDATA/postgresql.conf
26+
fi

images/tiler-imposm/Dockerfile

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,59 @@
1-
FROM ubuntu:16.04
1+
FROM osgeo/gdal:ubuntu-small-3.2.3
22

33
RUN apt-get -y update
44
RUN apt-get install -y \
5-
\
65
g++ \
7-
git-core \
86
libboost-dev \
97
libboost-system-dev \
108
libboost-filesystem-dev \
119
libexpat1-dev \
1210
zlib1g-dev \
1311
libbz2-dev \
1412
libpq-dev \
15-
libgeos-dev \
1613
libgeos++-dev \
1714
libproj-dev \
1815
libleveldb-dev \
1916
libgeos-dev \
2017
libprotobuf-dev \
21-
libgeos++-dev \
22-
libjson0-dev \
18+
git-core \
2319
curl \
2420
wget \
2521
unzip \
2622
software-properties-common
2723

28-
# Install python
29-
RUN add-apt-repository ppa:deadsnakes/ppa \
30-
&& apt-get update && \
31-
apt-get update -y && \
32-
apt-get install -y build-essential python3.6 python3.6-dev python3-pip && \
33-
apt-get install -y git && \
34-
# update pip
35-
python3.6 -m pip install pip --upgrade && \
36-
python3.6 -m pip install wheel
24+
# # Install python
25+
RUN add-apt-repository ppa:deadsnakes/ppa && \
26+
apt-get update && \
27+
apt-get install -y build-essential python3.6 python3.6-dev python3-pip && \
28+
python3 -m pip install pip --upgrade && \
29+
python3 -m pip install wheel
3730

3831
# Install postgresql-client
39-
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
40-
&& sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list' \
41-
&& apt-get update && apt-get install -y postgresql-client \
42-
&& rm -rf /var/lib/apt/lists/*
43-
44-
# Gdal is required to process the natural earth files
45-
RUN add-apt-repository ppa:ubuntugis/ppa \
46-
&& apt-get -y update \
47-
&& apt-get install -y gdal-bin \
48-
&& rm -rf /var/lib/apt/lists/*
32+
RUN apt-get update && apt-get install -y postgresql-client && \
33+
rm -rf /var/lib/apt/lists/*
4934

5035
# Install go
51-
RUN add-apt-repository ppa:gophers/archive \
52-
&& apt-get -y update \
53-
&& apt-get install -y golang-1.10-go \
54-
&& cp /usr/lib/go-1.10/bin/go /usr/bin/go \
55-
&& cp /usr/lib/go-1.10/bin/gofmt /usr/bin/gofmt
36+
RUN wget -c https://dl.google.com/go/go1.10.linux-amd64.tar.gz -O - | tar -xz -C /usr/local
37+
ENV PATH $PATH:/usr/local/go/bin
5638

57-
# Install imposm
58-
ENV GOPATH /usr/bin
59-
RUN mkdir -p go
6039
WORKDIR /go
61-
RUN export GOPATH=`pwd`
40+
ENV GOPATH /go
6241
RUN go get github.com/omniscale/imposm3
6342
RUN go install github.com/omniscale/imposm3/cmd/imposm
64-
RUN cp $GOPATH/bin/imposm /usr/bin/imposm
43+
ENV PATH $PATH:$GOPATH/bin
6544

6645
# Install awscli and gsutil to get the pbf file
6746
RUN pip3 install -U setuptools
6847
RUN pip3 install awscli
6948
RUN pip3 install gsutil
7049

71-
7250
ENV IMPOSMDATA /mnt/data
73-
RUN mkdir -p "$IMPOSMDATA" && chmod 777 "$IMPOSMDATA"
74-
VOLUME /mnt/data
51+
RUN mkdir -p $IMPOSMDATA && chmod 777 -R $IMPOSMDATA
52+
WORKDIR $IMPOSMDATA
53+
VOLUME $IMPOSMDATA
7554

76-
WORKDIR /mnt/data
7755
WORKDIR /osm
7856
COPY config config
7957
COPY scripts scripts
8058
COPY start.sh start.sh
81-
CMD ./start.sh
59+
CMD ./start.sh

images/tiler-imposm/start.sh

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ function importData () {
124124
echo "Import OSM Land"
125125
./scripts/osm_land.sh
126126
echo "Import PBF file"
127-
128127
if [ -z "$TILER_IMPORT_LIMIT" ]; then
129128
imposm import \
130129
-config $workDir/config.json \
@@ -149,12 +148,13 @@ function importData () {
149148
# These index will help speed up tegola tile generation
150149
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST/$POSTGRES_DB" -a -f config/postgis_index.sql
151150

151+
touch /mnt/data/init_done
152152
# Update the DB
153153
updateData
154154
}
155155

156156

157-
echo "Connecting... to postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST/$POSTGRES_DB"
157+
echo "Connecting to DB..."
158158
flag=true
159159
while "$flag" = true; do
160160
pg_isready -h $POSTGRES_HOST -p 5432 >/dev/null 2>&2 || continue
@@ -163,21 +163,16 @@ while "$flag" = true; do
163163
hasData=$(psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST/$POSTGRES_DB" \
164164
-c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public'" | sed -n 3p | sed 's/ //g')
165165
# After import there are more than 70 tables
166-
167-
if [ $hasData \> 70 ]; then
166+
echo "$hasData tables in the DB"
167+
if ([ $hasData \> 70 ] && [[ ! -f /mnt/data/init_done ]]); then
168168
echo "Update the DB with osm data"
169169
updateData
170170
else
171-
if [[ ! -f /mnt/data/init_done ]]; then
172-
echo "Import PBF data to DB"
173-
getData
174-
if [ -f $PBFFile ]; then
175-
echo "Start importing the data"
176-
importData \
177-
&& touch /mnt/data/init_done
178-
fi
179-
else
180-
echo "Data has already imported"
171+
echo "Import PBF data to DB"
172+
getData
173+
if [ -f $PBFFile ]; then
174+
echo "Start importing the data"
175+
importData
181176
fi
182177
fi
183178
done

images/tiler-server/cache_cleaner.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
flag=true
3+
while "$flag" = true; do
4+
pg_isready -h $POSTGRES_HOST -p 5432 >/dev/null 2>&2 || continue
5+
flag=false
6+
./tile_cache_downloader.sh & ./expire-watcher.sh
7+
done

osm-seed/templates/tiler-db-statefulset.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ spec:
4545
value: {{ default "postgres" .Values.tilerDb.env.POSTGRES_USER | quote }}
4646
- name: PGDATA
4747
value: {{ .Values.tilerDb.persistenceDisk.mountPath }}
48+
- name: POSTGRES_DB_MAX_CONNECTIONS
49+
value: {{ default 100 .Values.tilerDb.env.POSTGRES_DB_MAX_CONNECTIONS | quote }}
50+
- name: POSTGRES_DB_SHARED_BUFFERS
51+
value: {{ default "128MB" .Values.tilerDb.env.POSTGRES_DB_SHARED_BUFFERS | quote }}
52+
- name: POSTGRES_DB_WORK_MEM
53+
value: {{ default "4MB" .Values.tilerDb.env.POSTGRES_DB_WORK_MEM | quote }}
54+
- name: POSTGRES_DB_MAINTENANCE_WORK_MEM
55+
value: {{ default "64MB" .Values.tilerDb.env.POSTGRES_DB_MAINTENANCE_WORK_MEM | quote }}
56+
- name: POSTGRES_DB_EFFECTIVE_CACHE_SIZE
57+
value: {{ default "4GB" .Values.tilerDb.env.POSTGRES_DB_EFFECTIVE_CACHE_SIZE | quote }}
4858
- name: POD_IP
4959
valueFrom: { fieldRef: { fieldPath: status.podIP } }
5060
livenessProbe:
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{{- if .Values.tilerServer.enabled -}}
2+
{{ if eq .Values.tilerServer.env.TILER_CACHE_TYPE "s3" }}
3+
{{- if .Values.tilerServerCacheCleaner.enabled -}}
4+
apiVersion: apps/v1
5+
kind: Deployment
6+
metadata:
7+
name: {{ .Release.Name }}-tiler-server-cache-cleaner
8+
labels:
9+
app: {{ template "osm-seed.name" . }}
10+
component: tiler-server-cache-cleaner
11+
environment: {{ .Values.environment }}
12+
release: {{ .Release.Name }}
13+
spec:
14+
replicas: {{ .Values.tilerServerCacheCleaner.replicaCount }}
15+
selector:
16+
matchLabels:
17+
app: {{ template "osm-seed.name" . }}
18+
template:
19+
metadata:
20+
labels:
21+
app: {{ template "osm-seed.name" . }}
22+
spec:
23+
containers:
24+
- name: {{ .Release.Name }}-tiler-server-cache-cleaner-deployment
25+
image: {{ .Values.tilerServer.image.name }}:{{ .Values.tilerServer.image.tag }}
26+
command: [{{.Values.tilerServerCacheCleaner.command}}]
27+
{{- if .Values.tilerServerCacheCleaner.resources.enabled }}
28+
resources:
29+
requests:
30+
memory: {{ .Values.tilerServerCacheCleaner.resources.requests.memory }}
31+
cpu: {{ .Values.tilerServerCacheCleaner.resources.requests.cpu }}
32+
limits:
33+
memory: {{ .Values.tilerServerCacheCleaner.resources.limits.memory }}
34+
cpu: {{ .Values.tilerServerCacheCleaner.resources.limits.cpu }}
35+
{{- end }}
36+
env:
37+
# tiler-db env variables
38+
- name: POSTGRES_HOST
39+
value: {{ .Release.Name }}-tiler-db
40+
- name: POSTGRES_DB
41+
value: {{ .Values.tilerDb.env.POSTGRES_DB }}
42+
- name: POSTGRES_PASSWORD
43+
value: {{ quote .Values.tilerDb.env.POSTGRES_PASSWORD }}
44+
- name: POSTGRES_USER
45+
value: {{ .Values.tilerDb.env.POSTGRES_USER }}
46+
- name: POSTGRES_PORT
47+
value: {{ .Values.tilerDb.env.POSTGRES_PORT | quote }}
48+
# tiler-server env variables
49+
- name: TILER_SERVER_PORT
50+
value: {{ .Values.tilerServer.env.TILER_SERVER_PORT | quote }}
51+
- name: TILER_CACHE_TYPE
52+
value: {{ .Values.tilerServer.env.TILER_CACHE_TYPE }}
53+
- name: TILER_CACHE_REGION
54+
value: {{ .Values.tilerServer.env.TILER_CACHE_REGION }}
55+
- name: TILER_CACHE_BUCKET
56+
value: {{ .Values.tilerServer.env.TILER_CACHE_BUCKET }}
57+
- name: TILER_CACHE_BASEPATH
58+
value: {{ quote .Values.tilerServer.env.TILER_CACHE_BASEPATH }}
59+
- name: TILER_CACHE_AWS_ACCESS_KEY_ID
60+
value: {{ quote .Values.tilerServer.env.TILER_CACHE_AWS_ACCESS_KEY_ID }}
61+
- name: TILER_CACHE_AWS_SECRET_ACCESS_KEY
62+
value: {{ quote .Values.tilerServer.env.TILER_CACHE_AWS_SECRET_ACCESS_KEY }}
63+
- name: TILER_CACHE_MAX_ZOOM
64+
value: {{ quote .Values.tilerServer.env.TILER_CACHE_MAX_ZOOM }}
65+
- name: CLOUDPROVIDER
66+
value: {{ .Values.cloudProvider }}
67+
# In case cloudProvider=aws
68+
{{- if eq .Values.cloudProvider "aws" }}
69+
- name: AWS_S3_BUCKET
70+
value: {{ .Values.AWS_S3_BUCKET }}
71+
{{- end }}
72+
# In case cloudProvider=gcp
73+
{{- if eq .Values.cloudProvider "gcp" }}
74+
- name: GCP_STORAGE_BUCKET
75+
value: {{ .Values.GCP_STORAGE_BUCKET }}
76+
{{- end }}
77+
{{- if .Values.tilerServerCacheCleaner.nodeSelector.enabled }}
78+
nodeSelector:
79+
{{ .Values.tilerServerCacheCleaner.nodeSelector.label_key }} : {{ .Values.tilerServerCacheCleaner.nodeSelector.label_value }}
80+
{{- end }}
81+
{{- end }}
82+
{{- end }}
83+
{{- end }}

0 commit comments

Comments
 (0)