This commit is contained in:
Zsolt Ero
2023-12-21 02:35:20 +01:00
parent 2d9e5f2f4f
commit 48736bf87b
7 changed files with 49 additions and 16 deletions

View File

@@ -11,7 +11,7 @@ from ssh_lib.kernel import set_cpu_governor, setup_kernel_settings
from ssh_lib.nginx import certbot, nginx from ssh_lib.nginx import certbot, nginx
from ssh_lib.pkg_base import pkg_base, pkg_clean, pkg_upgrade from ssh_lib.pkg_base import pkg_base, pkg_clean, pkg_upgrade
from ssh_lib.planetiler import TILE_GEN_BIN, install_planetiler from ssh_lib.planetiler import TILE_GEN_BIN, install_planetiler
from ssh_lib.utils import add_user, enable_sudo, put, reboot, setup_time, sudo_cmd from ssh_lib.utils import add_user, apt_get_install, enable_sudo, put, reboot, setup_time, sudo_cmd
def prepare_shared(c): def prepare_shared(c):
@@ -30,6 +30,9 @@ def prepare_shared(c):
def prepare_tile_gen(c): def prepare_tile_gen(c):
install_planetiler(c) install_planetiler(c)
apt_get_install(c, 'btrfs-progs')
c.sudo('chown -R ofm:ofm /data/ofm')
for file in [ for file in [
'extract_btrfs.sh', 'extract_btrfs.sh',
@@ -38,7 +41,7 @@ def prepare_tile_gen(c):
'prepare-virtualenv.sh', 'prepare-virtualenv.sh',
'upload_cloudflare.sh', 'upload_cloudflare.sh',
'extract_mbtiles/extract_mbtiles.py', 'extract_mbtiles/extract_mbtiles.py',
'shrink_btrfs/shrink_btrfs.py', 'shrink_btrfs/extract_mbtiles.py',
]: ]:
put( put(
c, c,
@@ -48,6 +51,24 @@ def prepare_tile_gen(c):
owner='ofm', owner='ofm',
) )
put(
c,
scripts / 'tile_gen' / 'extract_mbtiles' / 'extract_mbtiles.py',
TILE_GEN_BIN / 'extract_mbtiles',
permissions='755',
owner='ofm',
target_is_dir=True,
)
put(
c,
scripts / 'tile_gen' / 'shrink_btrfs' / 'shrink_btrfs.py',
TILE_GEN_BIN / 'shrink_btrfs',
permissions='755',
owner='ofm',
target_is_dir=True,
)
sudo_cmd(c, f'cd {TILE_GEN_BIN} && source prepare-virtualenv.sh', user='ofm') sudo_cmd(c, f'cd {TILE_GEN_BIN} && source prepare-virtualenv.sh', user='ofm')

View File

@@ -1,14 +1,14 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
export TILE_GEN_BIN=/data/ofm/tile_gen/bin TILE_GEN_BIN=/data/ofm/tile_gen/bin
export VENV_PYTHON=$TILE_GEN_BIN/venv/python VENV_PYTHON=$TILE_GEN_BIN/venv/bin/python
sudo umount mnt_rw 2> /dev/null || true sudo umount mnt_rw 2> /dev/null || true
sudo umount mnt_rw2 2> /dev/null || true sudo umount mnt_rw2 2> /dev/null || true
rm -rf mnt_rw* tmp_* rm -rf mnt_rw* tmp_*
rm -f "*.btrfs" "*.gz" rm -f -- *.btrfs *.gz
rm -f "*.log" "*.txt" rm -f -- *.log *.txt
# make an empty file that's definitely bigger then the current OSM output # make an empty file that's definitely bigger then the current OSM output
fallocate -l 200G image.btrfs fallocate -l 200G image.btrfs

View File

@@ -34,6 +34,7 @@ def cli(mbtiles_path: Path, dir_path: Path):
write_dedupl_files(c, dir_path=dir_path) write_dedupl_files(c, dir_path=dir_path)
write_tile_files(c, dir_path=dir_path) write_tile_files(c, dir_path=dir_path)
# planetiler has missing tiles by design, so disabling this
# if it's a full planet run, # if it's a full planet run,
# make sure there are exactly the right number of files generated # make sure there are exactly the right number of files generated
# if 'planet' in mbtiles_path.resolve().parent.name: # if 'planet' in mbtiles_path.resolve().parent.name:
@@ -56,12 +57,14 @@ def write_metadata(c, *, dir_path):
def write_dedupl_files(c, *, dir_path): def write_dedupl_files(c, *, dir_path):
# dedupl files """
# write out the tiles_data files into a multi-level folder dedupl files
write out the tiles_data files into a multi-level folder
"""
total = c.execute('select count(*) from tiles_data').fetchone()[0] total = c.execute('select count(*) from tiles_data').fetchone()[0]
c.execute('select tile_data_id, tile_data from tiles_data') c.execute('select tile_data_id, tile_data from tiles_data')
for i, row in enumerate(c, start=1): for i, row in enumerate(c, start=1):
dedupl_id = row[0] dedupl_id = row[0]
dedupl_path = dir_path / 'dedupl' / dedupl_helper_path(dedupl_id) dedupl_path = dir_path / 'dedupl' / dedupl_helper_path(dedupl_id)
@@ -146,7 +149,7 @@ def calculate_tiles(zoom_level):
def calculate_tiles_sum(zoom_level): def calculate_tiles_sum(zoom_level):
""" """
Tiles up to zoom level (geometric series) Sum of tiles up to zoom level (geometric series)
""" """
return (4 ** (zoom_level + 1) - 1) // 3 return (4 ** (zoom_level + 1) - 1) // 3

View File

@@ -1,10 +1,12 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
DATE=$(date +"%Y%m%d_%H%M%S")
TILE_GEN_BIN=/data/ofm/tile_gen/bin TILE_GEN_BIN=/data/ofm/tile_gen/bin
DATE=$(date +"%Y%m%d_%H%M%S")
RUN_FOLDER="/data/ofm/tile_gen/runs/monaco/${DATE}_pt" RUN_FOLDER="/data/ofm/tile_gen/runs/monaco/${DATE}_pt"
mkdir -p "$RUN_FOLDER" mkdir -p "$RUN_FOLDER"
cd "$RUN_FOLDER" || exit cd "$RUN_FOLDER" || exit
@@ -22,3 +24,6 @@ java -Xmx1g \
--force \ --force \
> "planetiler_out.log" 2> "planetiler_err.log" > "planetiler_out.log" 2> "planetiler_err.log"
rm -r data
$TILE_GEN_BIN/extract_btrfs.sh

View File

@@ -1,10 +1,12 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
DATE=$(date +"%Y%m%d_%H%M%S")
TILE_GEN_BIN=/data/ofm/tile_gen/bin TILE_GEN_BIN=/data/ofm/tile_gen/bin
DATE=$(date +"%Y%m%d_%H%M%S")
RUN_FOLDER="/data/ofm/tile_gen/runs/planet/${DATE}_pt" RUN_FOLDER="/data/ofm/tile_gen/runs/planet/${DATE}_pt"
mkdir -p "$RUN_FOLDER" mkdir -p "$RUN_FOLDER"
cd "$RUN_FOLDER" || exit cd "$RUN_FOLDER" || exit
@@ -24,3 +26,5 @@ java -Xmx30g \
--force \ --force \
> "planetiler_out.log" 2> "planetiler_err.log" > "planetiler_out.log" 2> "planetiler_err.log"
rm -r data

View File

@@ -19,5 +19,3 @@ def install_planetiler(c):
) )
c.sudo(f'java -jar {PLANETILER_PATH} --help', hide=True) c.sudo(f'java -jar {PLANETILER_PATH} --help', hide=True)
c.sudo('chown -R ofm:ofm /data/ofm')

View File

@@ -3,11 +3,13 @@ import secrets
import string import string
def put(c, local_path, remote_path, permissions=None, owner='root', group=None): def put(
c, local_path, remote_path, permissions=None, owner='root', group=None, target_is_dir=False
):
tmp_path = f'/tmp/fabtmp_{random_string(8)}' tmp_path = f'/tmp/fabtmp_{random_string(8)}'
c.put(local_path, tmp_path) c.put(local_path, tmp_path)
if is_dir(c, remote_path): if is_dir(c, remote_path) or target_is_dir:
if not remote_path.endswith('/'): if not remote_path.endswith('/'):
remote_path += '/' remote_path += '/'