-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
96 lines (75 loc) · 2.89 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# syntax=docker/dockerfile:1
# Build Arguments
ARG KLIPPERSCREEN_URL="https://github.com/jordanruthe/KlipperScreen"
# ARG KLIPPERSCREEN_VERSION="heads/master"
ARG KLIPPERSCREEN_REF="tags/v0.3.1"
# Build Stage
FROM python:3 as build
# Re-export the build arguments
ARG KLIPPERSCREEN_URL
ARG KLIPPERSCREEN_REF
# Install dependencies
RUN apt-get update && \
apt-get install -y \
libgirepository1.0-dev \
libdbus-glib-1-dev \
cmake && \
apt-get clean
# Set default working directory
WORKDIR /opt/klipperscreen
# Download KlipperScreen
RUN mkdir -p /opt/klipperscreen/KlipperScreen && \
curl -sL ${KLIPPERSCREEN_URL}/archive/refs/${KLIPPERSCREEN_REF}.tar.gz | tar -zxvf - -C KlipperScreen --strip-components=1
# Create a virtual Python environment for KlipperScreen
RUN python -m venv venv
# Install KlipperScreen dependencies
RUN venv/bin/pip install -r KlipperScreen/scripts/KlipperScreen-requirements.txt
# Run Stage
FROM python:3-slim as run
# Set default environment variables
ENV XAUTHORITY="/tmp/.Xauthority"
ENV XDG_RUNTIME_DIR="/tmp"
ENV DISPLAY=":0"
ENV PULSE_SERVER=""
ENV KLIPPERSCREEN_RESTART_DELAY="60"
# Install dependencies
RUN apt-get update && \
apt-get install -y \
git \
curl \
bash \
xdotool \
x11-xserver-utils \
libglib2.0-0 \
libgirepository-1.0-1 \
gir1.2-gtk-3.0 \
libopenjp2-7 \
fonts-freefont-ttf \
libcairo2 \
libatlas3-base \
libdbus-glib-1-2 \
libmpv1 && \
apt-get clean
# Set default working directory
WORKDIR /opt/klipperscreen
# Copy KlipperScreen and the virtual python environment from the build stage
COPY --from=build /opt /opt
# Define volumes
VOLUME [ "/opt/klipperscreen/config" ]
# Create a custom wrapper script for handling KlipperScreen restarts and graceful exits
RUN echo '#!/usr/bin/env bash' > /opt/klipperscreen/start.sh && \
echo 'set -x' && \
echo 'trap "echo; echo \"NOTICE: Exit signal received, terminating ...\"; exit 0" SIGINT SIGTERM' >> /opt/klipperscreen/start.sh && \
echo 'while true; do' >> /opt/klipperscreen/start.sh && \
echo ' echo' && \
echo ' echo "NOTICE: Starting KlipperScreen ..."' && \
echo ' cd /opt/klipperscreen' && \
echo ' /opt/klipperscreen/venv/bin/python /opt/klipperscreen/KlipperScreen/screen.py "$@"' >> /opt/klipperscreen/start.sh && \
echo ' echo "WARNING: KlipperScreen exited with code $?, restarting in ${KLIPPERSCREEN_RESTART_DELAY} seconds..."' >> /opt/klipperscreen/start.sh && \
echo ' sleep ${KLIPPERSCREEN_RESTART_DELAY}' >> /opt/klipperscreen/start.sh && \
echo 'done' >> /opt/klipperscreen/start.sh && \
chmod +x /opt/klipperscreen/start.sh
# Set the custom wrapper script as the default entrypoint
ENTRYPOINT [ "/opt/klipperscreen/start.sh" ]
# Set default command to start KlipperScreen with a configuration file
CMD [ "-c", "/opt/klipperscreen/config/klipperscreen.conf" ]