Add Dockerfile
This commit is contained in:
99
Dockerfile
Normal file
99
Dockerfile
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
FROM rust:slim AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install a few dependencies
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y --no-install-recommends \
|
||||||
|
git \
|
||||||
|
curl \
|
||||||
|
unzip && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN rustup target add wasm32-unknown-unknown
|
||||||
|
|
||||||
|
# Install dioxus-cli
|
||||||
|
RUN curl -sSL https://dioxus.dev/install.sh | bash
|
||||||
|
|
||||||
|
ENV DAISYUI_PATH=/opt/daisyui/daisyui/
|
||||||
|
ENV DAISYUI_THEME_PATH=/opt/daisyui/theme/
|
||||||
|
ENV NODE_PATH=$DAISYUI_PATH:$DAISYUI_THEME_PATH
|
||||||
|
|
||||||
|
# Install DaisyUI bundles
|
||||||
|
RUN mkdir -p $DAISYUI_PATH $DAISYUI_THEME_PATH && \
|
||||||
|
cd $DAISYUI_PATH && \
|
||||||
|
curl -sLO https://github.com/saadeghi/daisyui/releases/latest/download/daisyui.js && \
|
||||||
|
cd $DAISYUI_THEME_PATH && \
|
||||||
|
curl -sLO https://github.com/saadeghi/daisyui/releases/latest/download/daisyui-theme.js
|
||||||
|
|
||||||
|
# Install Tailwind CSS CLI
|
||||||
|
RUN curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 && \
|
||||||
|
install tailwindcss-linux-x64 /usr/local/bin/tailwindcss && \
|
||||||
|
rm tailwindcss-linux-x64
|
||||||
|
|
||||||
|
# Include Rust binaries in PATH
|
||||||
|
ENV PATH="/root/.cargo/bin:${PATH}"
|
||||||
|
|
||||||
|
# Copy project dependency manifests
|
||||||
|
COPY Cargo.toml Cargo.lock Dioxus.toml /app/
|
||||||
|
|
||||||
|
# Create dummy files to force cargo to build the dependencies
|
||||||
|
# main() content fixes "failed to find intrinsics to enable `clone_ref` function"
|
||||||
|
# See https://github.com/trunk-rs/trunk/issues/951#issuecomment-2816819963
|
||||||
|
RUN mkdir /app/src && \
|
||||||
|
echo "fn main() { dioxus::logger::initialize_default(); }" > /app/src/main.rs && \
|
||||||
|
echo "fn main() {}" > /app/src/build.rs
|
||||||
|
|
||||||
|
# Prebuild dependencies
|
||||||
|
RUN dx build --release --locked --web
|
||||||
|
|
||||||
|
# Remove assets from the initial build
|
||||||
|
RUN rm -rf /app/target/dx/libretunes/release/web/public
|
||||||
|
|
||||||
|
RUN rm -rf /app/src
|
||||||
|
|
||||||
|
COPY --exclude=assets/tailwind.css assets /app/assets
|
||||||
|
COPY style /app/style
|
||||||
|
COPY migrations /app/migrations
|
||||||
|
COPY src /app/src
|
||||||
|
|
||||||
|
# Copy necessary git files for getting build version
|
||||||
|
RUN mkdir /app/.git
|
||||||
|
COPY .git/HEAD .git/refs /app/.git
|
||||||
|
|
||||||
|
# dx build will run tailwindcss anyways, but doing it first here is faster and clearer if it fails
|
||||||
|
RUN tailwindcss --input style/tailwind.css --output assets/tailwind.css
|
||||||
|
|
||||||
|
# Touch files to force rebuild
|
||||||
|
RUN touch /app/src/main.rs && touch /app/src/build.rs
|
||||||
|
|
||||||
|
# Actually build
|
||||||
|
RUN dx build --release --locked --web
|
||||||
|
|
||||||
|
# Use ldd to list all dependencies of the server, then copy them to /app/libs
|
||||||
|
RUN mkdir /app/libs && ldd /app/target/dx/libretunes/release/web/server | 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 assets to the final image
|
||||||
|
COPY --from=builder /app/target/dx/libretunes/release/web/server /libretunes
|
||||||
|
COPY --from=builder /app/target/dx/libretunes/release/web/public /public
|
||||||
|
|
||||||
|
ENV LIBRETUNES_SERVER_PUBLIC_PATH=/public
|
||||||
|
ENV DIOXUS_PUBLIC_PATH=/public
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
ENTRYPOINT [ "/libretunes" ]
|
||||||
Reference in New Issue
Block a user