From 6363585b431f41c4ba40fb0102cc0e20be3debc1 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Fri, 4 Oct 2024 16:56:51 -0400 Subject: [PATCH] Create Dockerfile --- .dockerignore | 7 ++++++ Dockerfile | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5857fba --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +# Ignore everything +* + +# Except: +!/src +!/Cargo.lock +!/Cargo.toml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8ac01ef --- /dev/null +++ b/Dockerfile @@ -0,0 +1,69 @@ +FROM rust:slim as builder + +WORKDIR /app + +RUN rustup default nightly + +# Install a few dependencies +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + pkg-config \ + clang \ + build-essential \ + libssl-dev \ + libpq-dev \ + wget; \ + rm -rf /var/lib/apt/lists/* + +# Install ImageMagick +RUN cd / && \ + wget https://github.com/ImageMagick/ImageMagick/archive/refs/tags/7.1.1-38.tar.gz && \ + tar xf 7.1.1-38.tar.gz && \ + rm 7.1.1-38.tar.gz && \ + cd ImageMagick-7.1.1-38 && \ + ./configure && \ + make install -j $(nproc) && \ + cd .. && \ + rm -rf ImageMagick-7.1.1-38 + +# Copy project dependency manifests +COPY Cargo.toml Cargo.lock /app/ + +# Create dummy file to force cargo to build the dependencies +RUN mkdir /app/src && echo "fn main() {}" > /app/src/main.rs + +# Prebuild dependencies +RUN cargo build --release + +RUN rm -rf /app/src +COPY src /app/src + +# Touch main to force rebuild +RUN touch /app/src/main.rs + +# Actually build the binary +RUN cargo build --release + +# Use ldd to list all dependencies of /app/target/release/ingest, then copy them to /app/libs +# Setting LD_LIBRARY_PATH is necessary to find the ImageMagick libraries +RUN mkdir /app/libs && LD_LIBRARY_PATH=/usr/local/lib ldd /app/target/release/ingest | grep "=> /" | \ + awk '{print $3}' | xargs -I '{}' cp '{}' /app/libs + +# Build the final image +FROM scratch + +LABEL license="MIT" +LABEL description="LibreTunes, an open-source browser audio player and \ +library manager built for collaborative listening." + +# Copy the binary and the compressed assets to the "site root" +COPY --from=builder /app/target/release/ingest /ingest + +# Copy libraries to /lib64 +COPY --from=builder /app/libs /lib64 +COPY --from=builder /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2 + +ENV LD_LIBRARY_PATH=/lib64 + +ENTRYPOINT [ "/ingest" ]