I’m trying to deploy Rust with Image magic support via docker, can’t seem to get image magic to work.
Here is the docker
FROM ubuntu:20.04
# Change package repository to a different mirror
RUN sed -i 's/archive.ubuntu.com/us.archive.ubuntu.com/g' /etc/apt/sources.list
# Update
RUN apt-get -y update --fix-missing
RUN apt install -y wget
RUN apt-get -y install curl
# For video compression
RUN apt install -y ffmpeg
# For querying files
RUN apt-get install -y ffmpeg
# Create app directory
RUN mkdir -p /app
WORKDIR /app
# PNG ,JPG ,Tiff & WebP support
# Consider adding more support with testing https://gist.github.com/hurricup/e14ae5bc47705fca6b1680e7a1fb6580
RUN apt-get install -y --fix-missing libjpeg-dev
RUN apt-get install -y --fix-missing libpng-dev
RUN apt-get install -y --fix-missing libtiff-dev
RUN apt-get install -y --fix-missing libwebp-dev
RUN apt-get install -y --fix-missing libheif-dev
# Install image magic
RUN apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev openssl pkg-config libmagickwand-dev
RUN apt-get -y install wget && apt-get install -y ruby-full && ruby -v
RUN DEBIAN_FRONTEND="noninteractive" UBUNTU_FRONTEND="noninteractive" apt-get install imagemagick -y
# Install ImageMagick
RUN DEBIAN_FRONTEND="noninteractive" UBUNTU_FRONTEND="noninteractive" apt-get install imagemagick -y
# Install Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup default stable
# Move app and build app
WORKDIR /app
COPY . /app
# Compile rust app
RUN cargo build --release
# Remove the source so no one can steal it.
RUN rm -r -d src
RUN rm -r -d k8s
ENV DOCKER isdocker
ENV PORT 8080
# Start the app.
EXPOSE 8080
CMD ["/app/poem_test"]
On RUN cargo build –release
I get
.7 Caused by:
677.7 process didn't exit successfully: `/app/target/release/build/magick_rust-a30fa2e709188d5a/build-script-build` (exit status: 101)
677.7 --- stdout
677.7 cargo:rerun-if-env-changed=IMAGE_MAGICK_LIB_DIRS
677.7 cargo:rerun-if-env-changed=IMAGE_MAGICK_DIR
677.7 cargo:rerun-if-env-changed=MAGICKWAND_NO_PKG_CONFIG
677.7 cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
677.7 cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
677.7 cargo:rerun-if-env-changed=HOST_PKG_CONFIG
677.7 cargo:rerun-if-env-changed=PKG_CONFIG
677.7 cargo:rerun-if-env-changed=MAGICKWAND_STATIC
677.7 cargo:rerun-if-env-changed=MAGICKWAND_DYNAMIC
677.7 cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
677.7 cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
677.7 cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
677.7 cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
677.7 cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
677.7 cargo:rerun-if-env-changed=PKG_CONFIG_PATH
677.7 cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
677.7 cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
677.7 cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
677.7 cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
677.7 cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
677.7 cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
677.7 cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
677.7 cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
677.7
677.7 --- stderr
677.7 thread 'main' panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/magick_rust-0.19.1/build.rs:249:10:
677.7 called `Result::unwrap()` on an `Err` value:
677.7 pkg-config exited with status code 1
677.7 > PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --libs --cflags MagickWand MagickWand >= 7.0
677.7
677.7 The system library `MagickWand` required by crate `magick_rust` was not found.
677.7 The file `MagickWand.pc` needs to be installed and the PKG_CONFIG_PATH environment variable must contain its parent directory.
677.7 The PKG_CONFIG_PATH environment variable is not set.
677.7
677.7 HINT: if you have installed the library, try setting PKG_CONFIG_PATH to the directory containing `MagickWand.pc`.
677.7
677.7 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
677.7 warning: build failed, waiting for other jobs to finish...
------
Dockerfile:48
--------------------
46 |
47 | # Compile rust app
48 | >>> RUN cargo build --release
2
Answers
Switching to Debian and upgrading the version helped. Here is the script that works on production.
You are installing ImageMagick 6, but the crate requires you to install ImageMagick 7.
You can either build ImageMagick 7 from source or build upon other docker images already packaging ImageMagic 7: