Skip to content

Commit

Permalink
Merge pull request #66 from CGDogan/patch-4
Browse files Browse the repository at this point in the history
Build libvips ALSO without openslide
  • Loading branch information
birm authored Jul 18, 2023
2 parents 44551b7 + a2a57c9 commit ac6dad3
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,64 @@ WORKDIR /var/www
RUN apt-get update
RUN apt-get -q update --fix-missing
RUN apt-get -q install -y openslide-tools python3-openslide vim openssl
RUN apt-get -q install -y libvips libvips-dev

# Tony has a future use case where we may adapt caMic to GIS visualization
# install libvips-dev for pyvips. No need for libvips.
RUN apt-get -q install -y libvips-dev

# But, build libvips instead of using libvips-dev from apt
# Build without OpenSlide to open images with rather ImageMagick to handle
# images without pyramids. Otherwise opens e.g. DICOM with OpenSlide so conversion
# of files OpenSlide cannot open does not help at all.
# So, we'll have two copies on openslide on the system.
# By changing LD_LIBRARY_PATH before we launch python
# we can choose which openslide to run
# TODO: replace libjpeg-dev with libjpeg-turbo8-dev when current apt repo has it; for performance
RUN apt-get -q install -y meson libjpeg-dev libexif-dev libgsf-1-dev libtiff-dev libfftw3-dev liblcms2-dev libpng-dev libmagickcore-dev libmagickwand-dev liborc-0.4-dev libopenjp2-7 libgirepository1.0-dev
WORKDIR /root/src
RUN git clone https://github.com/libvips/libvips.git --depth=1 --branch=8.14
RUN mkdir /root/src/libvips/build
WORKDIR /root/src/libvips
RUN mkdir /usr/local/vips-no-openslide/
# normally --prefix=/usr/local/ --libdir=lib build
RUN meson setup -Dopenslide=disabled --buildtype=release --prefix=/usr/local/vips-no-openslide/ --libdir=lib build
RUN meson compile -C build
RUN meson test -C build
RUN meson install -C build

RUN pip install pyvips
RUN pip install flask
RUN pip install gunicorn
RUN pip install greenlet
RUN pip install gunicorn[eventlet]

# verify pyvips can call libvips
RUN python3 -c "import pyvips"

# verify that the apt libvips has openslide
ADD test_imgs/CMU-1-Small-Region.svs .
RUN python3 -c "import pyvips; pyvips.Image.openslideload(('CMU-1-Small-Region.svs'))"

# back up previous ld_library_path
ENV LD_LIBRARY_PATH_ORIG="${LD_LIBRARY_PATH}"

# now, prioritize openslideless libvips
# the path shown in output lines of "meson install" where .so.42 are installed
# normally /usr/local/lib/:
ENV LD_LIBRARY_PATH="/usr/local/vips-no-openslide/lib/:${LD_LIBRARY_PATH}"

# verify that this libvips has no openslide
RUN ! python3 -c "import pyvips; pyvips.Image.openslideload(('CMU-1-Small-Region.svs'))"

# ok, so to recap,
# there are two libvips are installed and which one pyvips connects to
# is chosen when "import pyvips" is run.
# at this point in this dockerfile,
# ld_library_path is set so that no-openslide version is run
# but if you do LD_LIBRARY_PATH="${LD_LIBRARY_PATH_ORIG}" python a.py
# or likewise using docker ENV command or os.environ in python before
# importing, this will remove the no-openslide libvips from path.

run openssl version -a

ENV FLASK_ENV development
Expand Down

0 comments on commit ac6dad3

Please sign in to comment.