-
-
Notifications
You must be signed in to change notification settings - Fork 101
/
Dockerfile.bullseye
120 lines (104 loc) · 5.7 KB
/
Dockerfile.bullseye
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
# 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:10-bullseye 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.9-bullseye 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"
# 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/ bullseye main contrib non-free rpi" > /etc/apt/sources.list.d/raspberrypi.list \
&& echo "deb http://archive.raspberrypi.org/debian/ bullseye main" >> /etc/apt/sources.list.d/raspberrypi.list \
&& apt-key adv --keyserver 185.125.188.26 --recv-keys 9165938D90FDDD2E 82B129927FA3303E
RUN python -m venv /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 .
# 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 \
&& 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 \
&& 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.9-bullseye 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.9-slim-bullseye 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.1 /usr/local/lib/libsispmctl.so \
&& ln -s /usr/local/lib/libsispmctl.so.0.2.1 /usr/local/lib/libsispmctl.so.0 \
&& echo "/opt/vc/lib" > /etc/ld.so.conf.d/00-vmcs.conf \
&& 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 libxslt1.1 libftdi1 libatlas3-base libopenblas0 libgfortran5 libraspberrypi-bin ${JAVA} \
&& 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
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"]