Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiler server/database and cache cleaning refactoring #424

Merged
merged 84 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
9ce15b3
Add filter for water_lines
Rub21 Nov 27, 2024
c281393
Add script to merge layers for imposm config
Rub21 Nov 28, 2024
03a96cf
Deploy image for imposm
Rub21 Nov 28, 2024
0579a2e
Update config to create layer for water areas and lines - imposm
Rub21 Nov 28, 2024
69c4273
Split layers in each json file
Rub21 Nov 28, 2024
ec4c375
Update water line and are layers - imposm
Rub21 Nov 29, 2024
0799a2e
Filter admin lines for maritime
Rub21 Nov 29, 2024
d1302d0
Disable index for water tables
Rub21 Nov 29, 2024
051649e
Update water lines, areas and admin line maritime - vtiles
Rub21 Nov 29, 2024
eb64b33
Enable admin lines zoom 13 to 20 - imposm
Rub21 Nov 29, 2024
f97ad2b
Update ebs tiler-db staging
Rub21 Nov 29, 2024
c4fa022
Merge pull request #417 from OpenHistoricalMap/imposm/tables
Rub21 Nov 29, 2024
03bd13b
Set new ebs for tiler - staging
Rub21 Nov 29, 2024
bc7fc43
Update EBS id - tiler db
Rub21 Nov 29, 2024
7821ba9
Update tiler-db ebs ids
Rub21 Nov 29, 2024
84fda92
Add env vars EXECUTE_VACUUM_ANALYZE and EXECUTE_REINDEX for tiler server
Rub21 Nov 29, 2024
8c4f9fc
Add missing tags got water areas
Rub21 Nov 29, 2024
32e8de1
Fix LENGUAGES layer issue
Rub21 Nov 29, 2024
ef23359
Update ebs - staging
Rub21 Nov 29, 2024
75423d9
Update imposm3 continaer
Rub21 Dec 2, 2024
3c1d586
Update chartpress
Rub21 Dec 2, 2024
34bae99
Update imposm admin_areas import
Rub21 Dec 2, 2024
713df56
Remove config for previous-water-lines
Rub21 Dec 2, 2024
0b2ae9b
Add columns for start_date and end_date for admin areas
Rub21 Dec 2, 2024
6cf7480
Rename tables names
Rub21 Dec 2, 2024
dc09ae7
Update centroid for water areas
Rub21 Dec 2, 2024
efec82c
Rename table name for boundary lines
Rub21 Dec 2, 2024
3eba4b0
Update tiler server layers
Rub21 Dec 2, 2024
cb8a9c9
Remove tolerance for centroids
Rub21 Dec 2, 2024
dc78768
Update layers water areas
Rub21 Dec 2, 2024
de2561d
Update id column for layers
Rub21 Dec 3, 2024
73a3659
Update ebs for tiler imposm
Rub21 Dec 3, 2024
c90b629
Merge pull request #418 from OpenHistoricalMap/imposm3
Rub21 Dec 3, 2024
530883f
Update ebs for tiler db - staging
Rub21 Dec 3, 2024
a8bd8b4
Merge pull request #419 from OpenHistoricalMap/imposm3
Rub21 Dec 3, 2024
a159c7c
Remove indexing the tables
Rub21 Dec 3, 2024
a0137c6
Merge pull request #420 from OpenHistoricalMap/imposm3
Rub21 Dec 3, 2024
7032745
Enable tiler server - staging
Rub21 Dec 3, 2024
e1019be
Change tilerdb to a xlarge node - staging
Rub21 Dec 3, 2024
37f39fa
Remove triggers before apply transformation
Rub21 Dec 3, 2024
ca48cd6
Add config to import routes - relation
Rub21 Dec 3, 2024
85a9009
Update queries and import routes
Rub21 Dec 4, 2024
5af3c09
Update cetroids script for admin boundaries
Rub21 Dec 4, 2024
319e756
Fixed reference issue for transform gemetry
Rub21 Dec 5, 2024
797479f
Update docker-compose config for tiler
Rub21 Dec 6, 2024
32ea85e
Update routes lines layer
Rub21 Dec 6, 2024
6f536f6
Update boundaries centroid
Rub21 Dec 6, 2024
2504cdb
Merge pull request #422 from OpenHistoricalMap/imposm/routes
Rub21 Dec 6, 2024
9f39fb2
Enable tiler seeding
Rub21 Dec 6, 2024
0f067d8
Update tiler image
Rub21 Dec 6, 2024
75499f5
Update water areas centroid zoom 16-20
Rub21 Dec 6, 2024
6b93cea
Update reade for dev mode - compose
Rub21 Dec 6, 2024
394d543
Tiler use external DB
Rub21 Dec 6, 2024
3c9f638
Update config map for tiler seed an purge
Rub21 Dec 6, 2024
fed29cf
Update osm-seed - charts for tiler
Rub21 Dec 7, 2024
4eea8ce
Fix config issues in seed and purge templates
Rub21 Dec 7, 2024
4acc631
Fix name of the db that runs in kubernets env
Rub21 Dec 7, 2024
dc9b6ea
Enable external tiler db
Rub21 Dec 7, 2024
1a21167
Update osm-seed version
Rub21 Dec 7, 2024
de6a049
Enable vacuum and reindex db - tiler db
Rub21 Dec 7, 2024
45e5613
Set node for seed and purge large
Rub21 Dec 7, 2024
4b663ce
Update node and imposm date funcion
Rub21 Dec 7, 2024
70d9469
Disable backup for db - staging
Rub21 Dec 7, 2024
f42eef5
Update water areas simplification
Rub21 Dec 7, 2024
6f73f1b
Fix path for datefunctions in imposm container
Rub21 Dec 7, 2024
0ce8da5
Add tiler db configmap for purge tiler script
Rub21 Dec 7, 2024
443c95c
Filter only water cetroids that has name
Rub21 Dec 9, 2024
f0885e7
Simplification for transport lines
Rub21 Dec 9, 2024
587d63d
Update layers for admin, water and transport
Rub21 Dec 9, 2024
2856c2c
Fix ref to transport_lines_z13_15
Rub21 Dec 9, 2024
53bd032
Update ref for transport_lines_z12
Rub21 Dec 9, 2024
0f4c894
Fix transport lines layers
Rub21 Dec 10, 2024
483bb97
Setting for staging/production db
Rub21 Dec 10, 2024
2e138d4
Merge pull request #423 from OpenHistoricalMap/transport_lines
Rub21 Dec 10, 2024
c790ff2
Disable tiler seed and purge
Rub21 Dec 10, 2024
dd84456
Update config external db for production
Rub21 Dec 10, 2024
4567ce0
Fix admin boundaries centroids query
Rub21 Dec 10, 2024
f044a4a
New tiler data import
Rub21 Dec 10, 2024
5ac0238
Import data to tiler db
Rub21 Dec 10, 2024
983736a
Enable tiler server
Rub21 Dec 10, 2024
a4a4e60
Update imposm config
Rub21 Dec 10, 2024
dd84c14
Imposm config ebs - staging
Rub21 Dec 10, 2024
0da8dd3
Update production config
Rub21 Dec 10, 2024
ef2b3fc
Disable purge/seed tiler production for deployment
Rub21 Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/chartpress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- 'main'
- 'staging'
- 'development'
- 'tiler-cache'
- 'transport_lines'
jobs:
build:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -56,6 +56,8 @@ jobs:
DEVELOPMENT_OAUTH_KEY: ${{ secrets.STAGING_OAUTH_KEY }}
DEVELOPMENT_S3_BUCKET: osmseed-dev
## tiler

DEVELOPMENT_TILER_DB_HOST: ${{ secrets.STAGING_TILER_DB_HOST }}
DEVELOPMENT_TILER_DB_PASSWORD: ${{ secrets.STAGING_TILER_DB_PASSWORD }}
DEVELOPMENT_TILER_CACHE_AWS_ACCESS_KEY_ID: ${{ secrets.STAGING_TILER_CACHE_AWS_ACCESS_KEY_ID }}
DEVELOPMENT_TILER_CACHE_AWS_SECRET_ACCESS_KEY: ${{ secrets.STAGING_TILER_CACHE_AWS_SECRET_ACCESS_KEY }}
Expand Down Expand Up @@ -99,6 +101,7 @@ jobs:
STAGING_OAUTH_KEY: ${{ secrets.STAGING_OAUTH_KEY }}
STAGING_S3_BUCKET: ${{ secrets.STAGING_S3_BUCKET }}
## tiler
STAGING_TILER_DB_HOST: ${{ secrets.STAGING_TILER_DB_HOST }}
STAGING_TILER_DB_PASSWORD: ${{ secrets.STAGING_TILER_DB_PASSWORD }}
STAGING_TILER_CACHE_AWS_ACCESS_KEY_ID: ${{ secrets.STAGING_TILER_CACHE_AWS_ACCESS_KEY_ID }}
STAGING_TILER_CACHE_AWS_SECRET_ACCESS_KEY: ${{ secrets.STAGING_TILER_CACHE_AWS_SECRET_ACCESS_KEY }}
Expand Down Expand Up @@ -146,6 +149,7 @@ jobs:
PRODUCTION_S3_BUCKET: ${{ secrets.PRODUCTION_S3_BUCKET }}
PRODUCTION_DB_BACKUP_S3_BUCKET: ${{ secrets.PRODUCTION_DB_BACKUP_S3_BUCKET }}
## tiler
PRODUCTION_TILER_DB_HOST: ${{ secrets.PRODUCTION_TILER_DB_HOST }}
PRODUCTION_TILER_DB_PASSWORD: ${{ secrets.PRODUCTION_TILER_DB_PASSWORD }}
PRODUCTION_TILER_CACHE_AWS_ACCESS_KEY_ID: ${{ secrets.PRODUCTION_TILER_CACHE_AWS_ACCESS_KEY_ID }}
PRODUCTION_SQS_QUEUE_URL: ${{ secrets.PRODUCTION_SQS_QUEUE_URL }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ envs/.env.web
config.toml
.DS_Store
*/.DS_Store
.env
.env
values.dev.staging.yaml
9 changes: 9 additions & 0 deletions compose/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Development Mode

Compose files are for development mode, e.g.:

- Tiler DB

```sh
docker compose -f compose/tiler.yml run --service-ports tiler bash
```
32 changes: 12 additions & 20 deletions compose/tiler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ services:
dockerfile: Dockerfile
ports:
- "5432:5432"
# volumes:
# - ../data/tiler-db-data:/var/lib/postgresql/data
volumes:
- ../data/tiler-db-data2:/var/lib/postgresql/data
env_file:
- ../envs/.env.tiler
restart: always
imposm:
image: ohm-tiler-imposm:v1
image: rub21/tiler-imposm:v15
build:
context: ../images/tiler-imposm
dockerfile: Dockerfile
# volumes:
# - ../data/tiler-imposm-data:/mnt/data
# - ../images/tiler-imposm:/app
# command:
# - sh
# - -c
# - "sleep 60 && ./start.sh"
volumes:
- ../data/tiler-imposm-data2:/mnt/data
- ../images/tiler-imposm:/app
command:
- sh
- -c
- "sleep 20 && ./start.sh"
env_file:
- ../envs/.env.tiler
tiler:
Expand All @@ -31,19 +31,11 @@ services:
context: ../images/tiler-server
dockerfile: Dockerfile
volumes:
# - ../data/tiler-server-data:/mnt/data
- ../data/tiler-server-data:/mnt/data
- ../images/tiler-server:/app
ports:
- "9090:9090"
env_file:
- ../envs/.env.tiler
restart: always
tilercache:
image: ohm-tiler-cache:v1
build:
context: ../images/tiler-cache
dockerfile: Dockerfile
volumes:
# - ../data/tiler-cache-data:/mnt/data
- ../images/tiler-cache:/app


2 changes: 1 addition & 1 deletion images/tiler-cache/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/openhistoricalmap/tiler-server:0.0.1-0.dev.git.1734.h5b4d15d
FROM ghcr.io/openhistoricalmap/tiler-server:0.0.1-0.dev.git.1880.h0f4c894

RUN apk update && apk add --no-cache \
proj \
Expand Down
6 changes: 4 additions & 2 deletions images/tiler-cache/purge.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def get_active_jobs_count():

def create_kubernetes_job(file_url, file_name):
"""Create a Kubernetes Job to process a file."""
config_map_name = f"{ENVIRONMENT}-tiler-server-cm"
configmap_tiler_server = f"{ENVIRONMENT}-tiler-server-cm"
configmap_tiler_db = f"{ENVIRONMENT}-tiler-db-cm"

job_name = f"{JOB_NAME_PREFIX}-{file_name}"
job_manifest = {
"apiVersion": "batch/v1",
Expand All @@ -103,7 +105,7 @@ def create_kubernetes_job(file_url, file_name):
"name": "tiler-purge-seed",
"image": DOCKER_IMAGE,
"command": ["sh", "./purge_and_seed.sh"],
"envFrom": [{"configMapRef": {"name": config_map_name}}],
"envFrom": [{"configMapRef": {"name": configmap_tiler_server}},{"configMapRef": {"name": configmap_tiler_db}}],
"env": [
{"name": "IMPOSM_EXPIRED_FILE", "value": file_url},
{"name": "EXECUTE_PURGE", "value": str(EXECUTE_PURGE)},
Expand Down
30 changes: 10 additions & 20 deletions images/tiler-imposm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM osgeo/gdal:ubuntu-small-3.2.3

RUN apt-get -y update
RUN apt-get install -y \
RUN apt-get -y update && apt-get install -y \
g++ \
libboost-dev \
libboost-system-dev \
Expand All @@ -22,46 +21,37 @@ RUN apt-get install -y \
software-properties-common && \
rm -rf /var/lib/apt/lists/*

# Install python
RUN add-apt-repository ppa:deadsnakes/ppa && \
apt-get update && \
apt-get install -y build-essential python3.6 python3.6-dev python3-pip && \
apt-get install -y python3.9 python3.9-dev python3-pip && \
rm -rf /var/lib/apt/lists/* && \
python3 -m pip install pip --upgrade && \
python3 -m pip install wheel

# Install postgresql-client
RUN apt-get update && apt-get install -y postgresql-client && \
rm -rf /var/lib/apt/lists/*

# Install Go
RUN wget -c https://dl.google.com/go/go1.21.0.linux-amd64.tar.gz -O - | tar -xz -C /usr/local
ENV PATH $PATH:/usr/local/go/bin

RUN git clone https://github.com/OpenHistoricalMap/DateFunctions-plpgsql.git /usr/local/datefunctions

WORKDIR /go
ENV GOPATH /go

# Clone the repository directly
RUN git clone https://github.com/omniscale/imposm3.git $GOPATH/src/github.com/omniscale/imposm3

WORKDIR $GOPATH/src/github.com/omniscale/imposm3
RUN git checkout v0.14.0

# Fix cache package conflict
RUN sed -i '/setMaxFileSize/d' cache/ldb_pre_121.go

# Apply fixes or patches (if necessary)
RUN sed -i '/setMaxFileSize/d' cache/ldb_pre_121.go
RUN go install github.com/omniscale/imposm3/cmd/imposm
ENV PATH $PATH:$GOPATH/bin

# Install awscli and gsutil to get the pbf file
RUN pip3 install -U setuptools
RUN pip3 install awscli

ENV IMPOSMDATA /mnt/data
RUN mkdir -p $IMPOSMDATA && chmod 777 -R $IMPOSMDATA
WORKDIR $IMPOSMDATA
VOLUME $IMPOSMDATA

# Install AWS CLI for downloading files
RUN pip3 install -U setuptools awscli psycopg2
WORKDIR /osm
COPY . .
CMD ./start.sh
RUN chmod +x ./start.sh
CMD ["./start.sh"]
88 changes: 88 additions & 0 deletions images/tiler-imposm/build_imposm3_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import json
import os
import logging

# Configure logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
logger = logging.getLogger(__name__)

def load_json(file_path):
"""Load a JSON file."""
try:
with open(file_path, 'r', encoding='utf-8') as file:
return json.load(file)
except FileNotFoundError:
logger.error(f"File not found: {file_path}")
raise
except json.JSONDecodeError as e:
logger.error(f"Error parsing JSON in file {file_path}: {e}")
raise

def merge_configs(template, configs):
"""Merge multiple JSON configs into the template."""
merged = template.copy()
for config in configs:
if 'generalized_tables' in config:
merged['generalized_tables'].update(config['generalized_tables'])
if 'tables' in config:
merged['tables'].update(config['tables'])
return merged

def main(folder_path, template_path, output_path):
"""Main function to merge JSON configs."""
logger.info("Loading template configuration...")
template = load_json(template_path)

import_layers = os.getenv("IMPOSM3_IMPORT_LAYERS", "all").strip()
logger.info(f"IMPOSM3_IMPORT_LAYERS: {import_layers}")

configs = []
if "all" in import_layers:
logger.info("Importing all layer files.")
# Import all JSON files in the folder
json_files = [f for f in os.listdir(folder_path) if f.endswith('.json')]
for json_file in json_files:
file_path = os.path.join(folder_path, json_file)
try:
logger.info(f"Importing {file_path}")
configs.append(load_json(file_path))
except Exception as e:
logger.error(f"Error reading {file_path}: {e}")
else:
# Import only specified layers
layer_names = [layer.strip() for layer in import_layers.split(",") if layer.strip()]
if not layer_names:
logger.error("No layers specified in IMPOSM3_IMPORT_LAYERS. Exiting.")
return

for layer_name in layer_names:
file_path = os.path.join(folder_path, f"{layer_name}.json")
if os.path.exists(file_path):
try:
logger.info(f"Importing {file_path}")
configs.append(load_json(file_path))
except Exception as e:
logger.error(f"Error reading {file_path}: {e}")
else:
logger.warning(f"Layer config file {file_path} not found. Skipping.")

if not configs:
logger.error("No valid layer configurations found. Exiting.")
return

logger.info("Merging configurations...")
merged_config = merge_configs(template, configs)
try:
with open(output_path, 'w', encoding='utf-8') as output_file:
json.dump(merged_config, output_file, indent=2)
logger.info(f"Merged configuration saved to {output_path}")
except Exception as e:
logger.error(f"Error writing merged configuration to {output_path}: {e}")
raise

if __name__ == "__main__":
folder_path = "./config/layers"
template_path = "./config/imposm3.template.json"
output_path = "./config/imposm3.json"
main(folder_path, template_path, output_path)

Loading
Loading