Dockerfile for osm2pgsql #1428
Replies: 5 comments 6 replies
-
You can use the |
Beta Was this translation helpful? Give feedback.
-
my2c:
simple example: Now:
Dockerfile
build: |
Beta Was this translation helpful? Give feedback.
-
I think we could do this work in 2 steps:
This feature could really help develop a container-based workflow for ingesting data into postgis. |
Beta Was this translation helpful? Give feedback.
-
V2. "extreme minimalized version" . ~ 47.5MB
not tested .. ( imho: need a full test for the native optimisation ) # experimental; save as a 'Dockerfile'
# build: docker build -t osm2pgsql_luajit .
FROM alpine:edge as alpine_build
RUN apk --update-cache add cmake make git g++ boost-dev expat-dev bzip2-dev zlib-dev libpq proj-dev postgresql-dev luajit # lua5.3-dev
# build osm2pgsql latest master
RUN git clone --depth 1 --branch master https://github.com/openstreetmap/osm2pgsql.git
WORKDIR /osm2pgsql/build
RUN mkdir -p /osm2pgsql/build
############################
# <CARGO CULT ON>
# .. cpu native + lto optimization .. only for the local testing .. not portable!
# .. not recomended for normal users.
ARG COMPILE_FLAGS=" -march=native -O3 -flto -fno-semantic-interposition -ffat-lto-objects "
ENV CFLAGS=${COMPILE_FLAGS}
ENV CXXFLAGS=${COMPILE_FLAGS}
ENV OBJCFLAGS=${COMPILE_FLAGS}
ENV FFLAGS=${COMPILE_FLAGS}
ENV LDFLAGS="-flto=auto"
# <CARGO CULT OFF>
#######################
RUN cmake .. -D WITH_LUA=OFF -D WITH_LUAJIT=ON
RUN make -j$(nproc)
RUN make install
RUN /usr/local/bin/osm2pgsql --help
RUN ldd /usr/local/bin/osm2pgsql
# "ldd tricks" - credit: https://gist.github.com/bcardiff/85ae47e66ff0df35a78697508fcb49af#gistcomment-2078660
RUN ldd /usr/local/bin/osm2pgsql | tr -s '[:blank:]' '\n' | grep '^/' | \
xargs -I % sh -c 'mkdir -p $(dirname deps%); cp % deps%;'
FROM alpine:edge
# copy deps .. generated by "ldd tricks"
COPY --from=alpine_build /osm2pgsql/build/deps /
# copy osm2pgsql
COPY --from=alpine_build /usr/local/bin/osm2pgsql /usr/local/bin/osm2pgsql
COPY --from=alpine_build /usr/local/share/osm2pgsql/default.style /usr/local/share/osm2pgsql/default.style
COPY --from=alpine_build /usr/local/share/osm2pgsql/empty.style /usr/local/share/osm2pgsql/empty.style
COPY --from=alpine_build /usr/local/share/man/man1/osm2pgsql.1 /usr/local/share/man/man1/osm2pgsql.1
# smoke test
RUN /usr/local/bin/osm2pgsql --help
RUN ldd /usr/local/bin/osm2pgsql
CMD ["/usr/local/bin/osm2pgsql"] |
Beta Was this translation helpful? Give feedback.
-
I think it would be great if dockerfile is maintained by osm2pgqsl community or the shared docker library. I see several benefits:
Note that this is the same discussion as happened at PostGIS community, and despite some initial resistance, we now have a well maintained variety of postgis images for multiple platforms. |
Beta Was this translation helpful? Give feedback.
-
As part of the MapDiscover project we are planning to use osm2pgsql to create a POI database. The Lua integration is just perfect for this use case. Thanks for this one! MapDiscover consists of multiple services, each represented as a container image.
So we tried to build a container image using Docker + Dockerfile and the build instructions of the README.md. As mentioned in #1427 the image size is very large (unoptimized ~1,4 GB with debian-slim-buster). I tried to use multi-stage builds and so on, but only could get to 700 MB by manually (using try and error) removing several dependencies (still not sure if everything works):
There are also no official docs which libraries are needed to run the binary release once you built it.
Today we got the first working docker image with several additions:
I am somehow used to Golang where you built an application and just put it in the container. Of course this doesn't work with C++ - I know. But I think having 700+ MB of dependencies for running an application seems just too much.
EDIT: I understand that providing a Dockerfile as part of the project requires time to maintain. Although I think clear build instructions and information about dependencies should be mentioned somewhere.
Beta Was this translation helpful? Give feedback.
All reactions