@@ -18,37 +18,31 @@ def _sizeof_fmt(num: float, suffix: str = "B") -> str:
1818 num /= 1024.0
1919 return f"{ num :.1f} Yi{ suffix } "
2020
21+ GDAL_IMAGE = "ghcr.io/osgeo/gdal:alpine-small-3.12.3"
2122
2223def _run_dockerized_ogr2ogr (database_url , directory : Path , path : Path , options : list ):
2324 assert directory .is_absolute ()
2425 assert path .is_absolute ()
2526
26- # Make ogr2ogr access database tunnel connection open on the host
27- # https://stackoverflow.com/a/43541732
28- urlobj = urlparse (database_url )
29- database_url_from_container = urlobj ._replace (
30- netloc = f"{ urlobj .username } :{ urlobj .password } @host.docker.internal:{ urlobj .port } "
31- ).geturl ()
32-
3327 command = [
3428 "docker" ,
35- "compose" ,
36- "-f" ,
37- "docker-compose.yml" ,
38- "--profile" ,
39- "gdal" ,
4029 "run" ,
41- "--rm" , # Do not leave dead containers
30+ "--rm" ,
31+ "--init" , # Forward signals such as Ctrl+C
32+ # Use host networking so the container can directly access
33+ # database tunnels open on localhost.
34+ "--network" ,
35+ "host" ,
4236 "-v" ,
4337 f"{ directory } :/home/data" ,
44- "gdal" ,
38+ GDAL_IMAGE ,
4539 "ogr2ogr" ,
4640 # Setup connection to the PostgreSQL database
4741 # See specific PostgreSQL options here:
4842 # https://gdal.org/drivers/vector/pg.html
4943 "-f" ,
5044 "PostgreSQL" ,
51- f"PG:{ database_url_from_container } " ,
45+ f"PG:{ database_url } " ,
5246 * options ,
5347 str (Path ("/home/data" ) / path .relative_to (directory )),
5448 ]
0 commit comments