From 543353cdccf9f154250c22cdfa78b59a3e336e3b Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Tue, 7 May 2024 15:39:24 -0700 Subject: [PATCH] First pass at cutting down image size --- selfhosted.Dockerfile | 103 ++++++++++++++++++++++++++---------------- 1 file changed, 63 insertions(+), 40 deletions(-) diff --git a/selfhosted.Dockerfile b/selfhosted.Dockerfile index 9a9d96b..ce5b017 100644 --- a/selfhosted.Dockerfile +++ b/selfhosted.Dockerfile @@ -21,30 +21,43 @@ ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}" FROM ${BUILDER_IMAGE} as builder # install build dependencies -RUN apt-get update -y && apt-get install -y build-essential git curl \ - && apt-get clean && rm -f /var/lib/apt/lists/*_* +RUN apt-get update -y && \ + # System packages + apt-get install -y \ + build-essential \ + git \ + curl && \ + # Node.js and Yarn + curl -sL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh && \ + bash nodesource_setup.sh && \ + apt-get install -y nodejs && \ + npm install -g yarn && \ + # Hex and Rebar + mix local.hex --force && \ + mix local.rebar --force && \ + # Cleanup + apt-get clean && \ + rm -f /var/lib/apt/lists/*_* + +# TODO: make this pull a different version of ffmpeg based on the architecture +# TODO: add to local dockerfile +# TODO: update docs +# TODO: update actions runner +RUN export FFMPEG_DOWNLOAD="https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linuxarm64-gpl.tar.xz" && \ + curl -L ${FFMPEG_DOWNLOAD} --output /tmp/ffmpeg.tar.xz && \ + tar -xf /tmp/ffmpeg.tar.xz --strip-components=2 --no-anchored -C /usr/local/bin/ "ffmpeg" && \ + tar -xf /tmp/ffmpeg.tar.xz --strip-components=2 --no-anchored -C /usr/local/bin/ "ffprobe" # prepare build dir WORKDIR /app -# Install nodejs -RUN curl -sL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh -RUN bash nodesource_setup.sh -RUN apt-get install -y nodejs -RUN npm install -g yarn - -# install hex + rebar -RUN mix local.hex --force && \ - mix local.rebar --force - # set build ENV ENV MIX_ENV="prod" ENV ERL_FLAGS="+JPperf true" # install mix dependencies COPY mix.exs mix.lock ./ -RUN mix deps.get --only $MIX_ENV -RUN mkdir config +RUN mix deps.get --only $MIX_ENV && mkdir config # copy compile-time config files before we compile dependencies # to ensure any relevant config change will trigger the dependencies @@ -53,17 +66,11 @@ COPY config/config.exs config/${MIX_ENV}.exs config/ RUN mix deps.compile COPY priv priv - COPY lib lib - COPY assets assets -# compile assets -RUN yarn --cwd assets install -RUN mix assets.deploy - -# Compile the release -RUN mix compile +# Compile assets +RUN yarn --cwd assets install && mix assets.deploy && mix compile # Changes to config/runtime.exs don't require recompiling the code COPY config/runtime.exs config/ @@ -71,30 +78,46 @@ COPY config/runtime.exs config/ COPY rel rel RUN mix release -# start a new build stage so that the final image will only contain -# the compiled release and other runtime necessities +## -- Release Stage -- + FROM ${RUNNER_IMAGE} ARG PORT=8945 -RUN apt-get update -y -RUN apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \ - ffmpeg curl git openssh-client nano python3 python3-pip jq procps -RUN apt-get clean && rm -f /var/lib/apt/lists/*_* +COPY --from=builder ./usr/local/bin/ffmpeg /usr/bin/ffmpeg +COPY --from=builder ./usr/local/bin/ffprobe /usr/bin/ffprobe -# Download and update YT-DLP -RUN curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp -RUN chmod a+rx /usr/local/bin/yt-dlp -RUN yt-dlp -U +RUN apt-get update -y && \ + # System packages + apt-get install -y \ + libstdc++6 \ + openssl \ + libncurses5 \ + locales \ + ca-certificates \ + python3-mutagen \ + curl \ + openssh-client \ + nano \ + python3 \ + pipx \ + jq \ + procps && \ + # Apprise + export PIPX_HOME=/opt/pipx && \ + export PIPX_BIN_DIR=/usr/local/bin && \ + pipx install apprise && \ + # yt-dlp + curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp && \ + chmod a+rx /usr/local/bin/yt-dlp && \ + yt-dlp -U && \ + # Set the locale + sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen && \ + # Clean up + apt-get clean && \ + rm -rf /var/lib/apt/lists/* -# Download Apprise -RUN python3 -m pip install -U apprise --break-system-packages - -# Download Mutagen for music thumbnail generation -RUN python3 -m pip install -U mutagen --break-system-packages - -# Set the locale -RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen +# More locale setup ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8