-
-
Notifications
You must be signed in to change notification settings - Fork 101
/
Dockerfile.bookworm
125 lines (111 loc) · 6.41 KB
/
Dockerfile.bookworm
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Build for raspberry pi
# docker buildx build --platform linux/arm/v7 --progress=plain -t theyosh/terrariumpi:4.0.0 -f Dockerfile --push .
# build sispmctl 4.12
FROM gcc:12-bookworm as sispmctl_builder
ARG SISPMCTL_VERSION="4.12"
WORKDIR /sispmctl
RUN apt-get update \
&& apt-get install -y --no-install-recommends libusb-dev \
&& wget https://sourceforge.net/projects/sispmctl/files/sispmctl/sispmctl-${SISPMCTL_VERSION}/sispmctl-${SISPMCTL_VERSION}.tar.gz/download -O sispmctl-${SISPMCTL_VERSION}.tar.gz \
&& tar zxvf sispmctl-${SISPMCTL_VERSION}.tar.gz --strip 1 \
&& ./configure \
&& make \
&& make install
# python builder, help keep image small
FROM python:3.11-bookworm as python_builder
ENV PIP_DEFAULT_TIMEOUT=100 \
# Allow statements and log messages to immediately appear
PYTHONUNBUFFERED=1 \
# disable a pip version check to reduce run-time & log-spam
PIP_DISABLE_PIP_VERSION_CHECK=1 \
# cache is useless in docker image, so disable to reduce image size
PIP_NO_CACHE_DIR=1 \
# do not create __pycache__/ files
PYTHONDONTWRITEBYTECODE=1
ENV PATH="/opt/venv/bin:$PATH"
RUN python -m venv --system-site-packages /opt/venv
RUN pip install --upgrade pip==24.1.2 && pip install --upgrade wheel==0.43.0
COPY requirements.txt .
COPY contrib/python3-voltcraft-sem6000.patch.diff .
# Some strange DNS issues with installing PGP keys. keyserver.ubuntu.com => 185.125.188.26
RUN apt-get update \
&& apt-get install -y --no-install-recommends gnupg \
&& echo "deb http://raspbian.raspberrypi.org/raspbian/ bookworm main contrib non-free rpi" > /etc/apt/sources.list.d/raspberrypi.list \
&& echo "deb http://archive.raspberrypi.org/debian/ bookworm main" >> /etc/apt/sources.list.d/raspberrypi.list \
&& apt-key adv --keyserver 185.125.188.26 --recv-keys 9165938D90FDDD2E 82B129927FA3303E \
&& apt-get update \
&& apt-get full-upgrade -y --no-install-recommends \
&& apt-get install -y --no-install-recommends libasound2-dev libglib2.0-dev libbluetooth-dev make
# requirements are slightly different for docker
# overruling does not work here, pip will exit with non 0 which will stop the build
RUN sed -i 's/paho-mqtt==.*//g' requirements.txt \
&& sed -i 's/icalendar==.*//g' requirements.txt \
&& sed -i 's/opencv-python-headless==.*//g' requirements.txt \
&& sed -i 's/git+https:\/\/github.com\/IanHarvey\/bluepy/git+https:\/\/github.com\/Mausy5043\/bluepy3/g' requirements.txt \
&& pip install smbus==1.1.post2 --extra-index-url https://www.piwheels.org/simple \
&& pip install -r requirements.txt --extra-index-url https://www.piwheels.org/simple \
&& sed -i 's/BLUEZ_VERSION: str = get_btctl_version.*/BLUEZ_VERSION: str = "5.66"/' /opt/venv/lib/python3.11/site-packages/bluepy3/helpermaker.py \
&& python -c "import bluepy3.btle" \
&& find /opt/venv -type d -name "test*" | xargs rm -rf \
&& find /opt/venv -type d -name "__pycache__" | xargs rm -rf \
&& find /opt/venv -type d -name ".git" | xargs rm -rf \
&& find /opt/venv -type f -name "*.pyc" -delete
WORKDIR /TerrariumPI
# Just clone the libraries, ignore docker cache...
RUN git clone https://github.com/ageir/chirp-rpi.git --depth 1 "3rdparty/chirp-rpi" \
&& git clone https://github.com/perryflynn/energenie-connect0r.git --depth 1 "3rdparty/energenie-connect0r" \
&& git clone https://github.com/SequentMicrosystems/relay8-rpi.git --depth 1 "3rdparty/relay8-rpi" \
&& git clone https://github.com/AtlasScientific/Raspberry-Pi-sample-code.git --depth 1 "3rdparty/AtlasScientific" \
&& git clone https://github.com/moormaster/python3-voltcraft-sem6000.git --depth 1 "3rdparty/python3-voltcraft-sem6000" \
&& patch -N -s -r /dev/null 3rdparty/python3-voltcraft-sem6000/sem6000/repeat_on_failure_decorator.py < /python3-voltcraft-sem6000.patch.diff >/dev/null \
&& rm -Rf 3rdparty/Bright-Pi/Documents \
&& find . -type d -name "__pycache__" -exec rm -r {} + \
&& find . -type f -name "*.pyc" -delete \
&& find . -type d -name ".git" -exec rm -r {} +
# Sourcecode cleanup and pre-prep
FROM python:3.11-bookworm as sourcecode
WORKDIR /TerrariumPI
COPY . .
# remove git and 3rdparty dir from code copy to help keep image smaller
# 3rdparty is coming from the builder image
RUN rm -Rf .git 3rdparty gui package*.json postcss.config.js rollup.config.js .env.* html-template.js requirements.txt yarn.lock
# actual image
FROM python:3.11-slim-bookworm as finalimage
ARG GITHUB_SHA="development"
ARG JAVA=""
ENV PIP_DEFAULT_TIMEOUT=100 \
# Allow statements and log messages to immediately appear
PYTHONUNBUFFERED=1 \
# disable a pip version check to reduce run-time & log-spam
PIP_DISABLE_PIP_VERSION_CHECK=1 \
# cache is useless in docker image, so disable to reduce image size
PIP_NO_CACHE_DIR=1 \
# do not create __pycache__/ files
PYTHONDONTWRITEBYTECODE=1
ENV DEBIAN_FRONTEND=noninteractive
ENV PATH="/opt/venv/bin:$PATH"
COPY --from=sispmctl_builder /usr/local/lib/libsispmctl* /usr/local/lib/.
COPY --from=sispmctl_builder /usr/local/bin/sispmctl /usr/local/bin/sispmctl
COPY --from=python_builder /etc/apt /etc/apt
COPY --from=python_builder /opt/venv /opt/venv
COPY --from=python_builder /TerrariumPI/3rdparty /TerrariumPI/3rdparty
COPY --from=sourcecode /TerrariumPI /TerrariumPI
RUN rm /usr/local/lib/libsispmctl.so /usr/local/lib/libsispmctl.so.0 \
&& ln -s /usr/local/lib/libsispmctl.so.0.2.2 /usr/local/lib/libsispmctl.so \
&& ln -s /usr/local/lib/libsispmctl.so.0.2.2 /usr/local/lib/libsispmctl.so.0 \
&& ldconfig
RUN apt-get update \
&& apt-get full-upgrade -y --no-install-recommends \
&& apt-get install -y --no-install-recommends sudo netcat-openbsd procps bluez pigpio ffmpeg libssl1.1 libxslt1.1 libftdi1 libatlas3-base libopenblas0 libgfortran5 libraspberrypi-bin rpicam-apps ${JAVA} python3-opencv \
&& apt-get --purge autoremove -y \
&& apt-get autoclean \
&& rm -rf /var/lib/apt/lists/* \
&& find /var/log/ -type f -delete \
&& find /var/cache/ -type f -delete \
&& ln -s /usr/lib/python3/dist-packages/cv2.cpython-311-arm-linux-gnueabihf.so /opt/venv/lib/python3.11/site-packages/cv2.cpython-311-arm-linux-gnueabihf.so
WORKDIR /TerrariumPI
# Set git version in a temp file
RUN echo "${GITHUB_SHA}" > .gitversion && echo '[ ! -z "$TERM" -a -r /TerrariumPI/motd.sh ] && /TerrariumPI/motd.sh' >> /etc/bash.bashrc
HEALTHCHECK --interval=180s --timeout=5s --start-period=120s CMD python contrib/docker_health.py
ENTRYPOINT ["/bin/bash", "/TerrariumPI/run.sh"]
CMD ["/opt/venv/bin/python", "/TerrariumPI/terrariumPI.py"]