Add a basic Klipper and OctoPrint Dockerfile

This commit is contained in:
Sillyfrog 2018-06-07 22:57:30 +10:00
parent c84da24975
commit 81ba26b808
3 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,61 @@
FROM python:2.7
EXPOSE 8080
RUN apt-get update && \
apt-get install -y sudo
EXPOSE 5000
ENV CURA_VERSION=15.04.6
ARG tag=master
WORKDIR /opt/octoprint
#install ffmpeg
RUN cd /tmp \
&& wget -O ffmpeg.tar.xz https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-32bit-static.tar.xz \
&& mkdir -p /opt/ffmpeg \
&& tar xvf ffmpeg.tar.xz -C /opt/ffmpeg --strip-components=1 \
&& rm -Rf /tmp/*
#install Cura
RUN cd /tmp \
&& wget https://github.com/Ultimaker/CuraEngine/archive/${CURA_VERSION}.tar.gz \
&& tar -zxf ${CURA_VERSION}.tar.gz \
&& cd CuraEngine-${CURA_VERSION} \
&& mkdir build \
&& make \
&& mv -f ./build /opt/cura/ \
&& rm -Rf /tmp/*
#Create an octoprint user
RUN useradd -ms /bin/bash octoprint && adduser octoprint dialout
RUN chown octoprint:octoprint /opt/octoprint
USER octoprint
#This fixes issues with the volume command setting wrong permissions
RUN mkdir /home/octoprint/.octoprint
#Install Octoprint
RUN git clone --branch $tag https://github.com/foosel/OctoPrint.git /opt/octoprint \
&& virtualenv venv \
&& ./venv/bin/python setup.py install \
&& echo 2
VOLUME /home/octoprint/.octoprint
### Klipper setup ###
USER root
COPY klippy.sudoers /etc/sudoers.d/klippy
RUN useradd -ms /bin/bash klippy
USER octoprint
WORKDIR /home/octoprint
RUN git clone https://github.com/KevinOConnor/klipper \
&& ./klipper/scripts/install-octopi.sh
COPY klippyoctostart.py /
CMD ["/klippyoctostart.py"]

View File

@ -29,3 +29,22 @@ docker run --name octoprint2 -d -v /etc/localtime:/etc/localtime:ro -v /home/use
Your Klipper `printer.cfg` should be kept in the OctoPrint config directory (this is where it looks for it at startup). Your Klipper `printer.cfg` should be kept in the OctoPrint config directory (this is where it looks for it at startup).
If you have any questions, feel free to log an issue on this project, and I'll see if I can help. If you have any questions, feel free to log an issue on this project, and I'll see if I can help.
## No MJPG
Also included is a cut down Dockerfile with no `mjpg` or OctoPrint plugins included.
This can be built with:
```
docker build . --file Dockerfile.KlipperOctoprint -t ko
```
And run with something like:
```
docker run -d -v /etc/localtime:/etc/localtime:ro -v /home/user/Documents/octoprint-config:/home/octoprint/.octoprint \
--device /dev/ttyUSB0:/dev/ttyUSB0 \
-p 5000:5000 \
ko
```
This is basically untested, but maybe a good start for someone who wants a simpler based container.

23
klippyoctostart.py Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env python
import subprocess
import time
import os
OCTOPRINT = ["/opt/octoprint/venv/bin/octoprint", "serve"]
def main():
os.environ['HOME'] = '/home/octoprint'
# Start klipper
klipper = subprocess.Popen(['/home/octoprint/klippy-env/bin/python', '/home/octoprint/klipper/klippy/klippy.py', '/home/octoprint/.octoprint/printer.cfg'])
# Run in a loop so Octoprint can restart in the container
while 1:
Poctoprint = subprocess.Popen(OCTOPRINT)
Poctoprint.wait()
time.sleep(1)
if __name__ == '__main__':
main()