Skip to content

Commit

Permalink
docker: shrink image sizes for klipper, moonraker and ustreamer
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuf committed Dec 1, 2022
1 parent 82675dd commit c43891d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
33 changes: 17 additions & 16 deletions docker/klipper/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ WORKDIR /opt

RUN git clone ${REPO} klipper \
&& cd klipper \
&& git checkout ${VERSION}
&& git checkout ${VERSION} \
&& rm -rf .git

RUN virtualenv -p python2 venv \
&& venv/bin/pip install -r klipper/scripts/klippy-requirements.txt \
Expand All @@ -20,15 +21,15 @@ RUN virtualenv -p python2 venv \
FROM python:2-slim as run

WORKDIR /opt
COPY --from=build /opt/klipper ./klipper
COPY --from=build /opt/venv ./venv

RUN mkdir -p printer_data/run printer_data/gcodes printer_data/logs printer_data/config
RUN groupadd klipper --gid 1000 \
&& useradd klipper --uid 1000 --gid klipper \
&& usermod klipper --append --groups dialout \
&& usermod klipper --append --groups dialout
RUN mkdir -p printer_data/run printer_data/gcodes printer_data/logs printer_data/config \
&& chown -R klipper:klipper /opt/*

COPY --chown=klipper:klipper --from=build /opt/klipper ./klipper
COPY --chown=klipper:klipper --from=build /opt/venv ./venv

USER klipper
VOLUME ["/opt/printer_data/run", "/opt/printer_data/gcodes", "/opt/printer_data/logs", "/opt/printer_data/config"]
ENTRYPOINT ["/opt/venv/bin/python", "klipper/klippy/klippy.py"]
Expand All @@ -38,9 +39,6 @@ CMD ["-I", "printer_data/run/klipper.tty", "-a", "printer_data/run/klipper.sock"
FROM ubuntu:18.04 as mcu

WORKDIR /opt
COPY --from=build /opt/klipper ./klipper
COPY --from=build /opt/venv ./venv

ARG DEBIAN_FRONTEND=noninteractive
RUN apt update \
&& apt install -y \
Expand All @@ -53,6 +51,9 @@ RUN apt update \
python3-numpy python3-matplotlib \
&& apt clean

COPY --chown=klipper:klipper --from=build /opt/klipper ./klipper
COPY --chown=klipper:klipper --from=build /opt/venv ./venv

## Build klipper.elf for Simulavr and Simulavr itself
FROM mcu as build-simulavr

Expand All @@ -67,17 +68,17 @@ COPY config.simulavr .config
RUN make

WORKDIR /opt
RUN mkdir run
RUN groupadd simulavr --gid 1000 \
&& useradd simulavr --uid 1000 --gid simulavr \
&& usermod simulavr --append --groups dialout

RUN git clone git://git.savannah.nongnu.org/simulavr.git \
&& cd simulavr \
&& git checkout release-1.1.0 \
&& make python \
&& make build

RUN mkdir run
RUN groupadd simulavr --gid 1000 \
&& useradd simulavr --uid 1000 --gid simulavr \
&& usermod simulavr --append --groups dialout \
&& chown -R simulavr:simulavr /opt/*
&& make build \
&& chown -R simulavr:simulavr /opt/simulavr

USER simulavr
ENV PYTHONPATH=/opt/simulavr/build/pysimulavr/
Expand Down
13 changes: 7 additions & 6 deletions docker/moonraker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ WORKDIR /opt

RUN git clone ${REPO} moonraker \
&& cd moonraker \
&& git checkout ${VERSION}
&& git checkout ${VERSION} \
&& rm -rf .git

RUN python -m venv venv \
&& venv/bin/pip install -r moonraker/scripts/moonraker-requirements.txt
Expand All @@ -35,15 +36,15 @@ RUN apt update \
&& apt clean

WORKDIR /opt
COPY --from=build /opt/moonraker ./moonraker
COPY --from=build /opt/venv ./venv

RUN mkdir -p printer_data/run printer_data/gcodes printer_data/logs printer_data/database printer_data/config
RUN groupadd moonraker --gid 1000 \
&& useradd moonraker --uid 1000 --gid moonraker \
&& usermod moonraker --append --groups dialout \
&& usermod moonraker --append --groups dialout
RUN mkdir -p printer_data/run printer_data/gcodes printer_data/logs printer_data/database printer_data/config \
&& chown -R moonraker:moonraker /opt/*

COPY --chown=moonraker:moonraker --from=build /opt/moonraker ./moonraker
COPY --chown=moonraker:moonraker --from=build /opt/venv ./venv

RUN ln -s /bin/systemctl /sbin/shutdown \
&& ln -s /bin/systemctl /sbin/reboot \
&& echo -n "moonraker ALL = NOPASSWD: /bin/systemctl, /sbin/shutdown, /sbin/reboot" > /etc/sudoers.d/moonraker
Expand Down
10 changes: 5 additions & 5 deletions docker/ustreamer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ RUN apt update \

RUN git clone ${REPO} ustreamer \
&& cd ustreamer \
&& git checkout ${VERSION}
&& git checkout ${VERSION} \
&& rm -rf .git

RUN cd ustreamer \
&& make
Expand All @@ -39,12 +40,11 @@ RUN apt update \
&& apt clean

WORKDIR /opt
COPY --from=build /opt/ustreamer ./ustreamer

RUN groupadd ustreamer --gid 1000 \
&& useradd ustreamer --uid 1000 --gid ustreamer \
&& usermod ustreamer --append --groups video \
&& chown -R ustreamer:ustreamer /opt/*
&& usermod ustreamer --append --groups video

COPY --chown=ustreamer:ustreamer --from=build /opt/ustreamer ./ustreamer

## Start ustreamer
USER ustreamer
Expand Down

0 comments on commit c43891d

Please sign in to comment.