Repository navigation
Expand file tree
/
Copy pathDockerfile.buster.java
More file actions
111 lines (100 loc) · 6.12 KB
/
Copy pathDockerfile.buster.java
File metadata and controls
111 lines (100 loc) · 6.12 KB
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
# Build for raspberry pi
# docker buildx build --platform linux/arm/v7 --progress=plain -t theyosh/terrariumpi:4.0.0 -f Dockerfile --push .
# python builder, help keep image small
FROM python:3.7-buster 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 /opt/venv
RUN pip install --upgrade pip==24.0 && pip install --upgrade wheel==0.42.0
COPY requirements.txt contrib/python3-voltcraft-sem6000.patch.diff contrib/python3-as7331.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/pip==.*/pip==24.0/g' requirements.txt \
&& sed -i 's/setuptools==.*/setuptools==68.0.0/g' requirements.txt \
&& sed -i 's/wheel==.*/wheel==0.42.0/g' requirements.txt \
&& sed -i 's/yoyo-migrations==.*/yoyo-migrations==8.2.0/g' requirements.txt \
&& sed -i 's/python-dotenv==.*/python-dotenv==0.21.1/g' requirements.txt \
&& sed -i 's/gevent==.*/gevent==22.10.2/g' requirements.txt \
&& sed -i 's/bcrypt==.*/bcrypt==4.1.3/g' requirements.txt \
&& sed -i 's/cryptography==.*/cryptography==45.0.7/g' requirements.txt \
&& sed -i 's/Pillow==.*/Pillow==9.5.0/g' requirements.txt \
&& sed -i 's/numpy==.*/numpy==1.21.4/g' requirements.txt \
&& sed -i 's/opencv-python-headless==.*/opencv-python-headless==4.6.0.66/g' requirements.txt \
&& sed -i 's/gpiozero==.*/gpiozero==1.6.2/g' requirements.txt \
&& sed -i 's/requests==.*/requests==2.31.0/g' requirements.txt \
&& sed -i 's/pylibftdi==.*/pylibftdi==0.23.0/g' requirements.txt \
&& sed -i 's/python-kasa==.*/python-kasa==0.5.1/g' requirements.txt \
&& sed -i 's/meross-iot==.*/meross-iot==0.4.7.5/g' requirements.txt \
&& sed -i 's/pywemo==.*/pywemo==0.9.2/g' requirements.txt \
&& sed -i 's/sensirion-i2c-driver==.*/sensirion-i2c-driver==1.0.0/g' requirements.txt \
&& sed -i 's/Adafruit-Blinka==.*/Adafruit-Blinka==8.43.0/g' requirements.txt \
&& sed -i 's/icalevents==.*/icalevents==0.1.25/g' requirements.txt \
&& sed -i 's/psutil==.*/psutil==6.0.0/g' requirements.txt \
&& sed -i 's/packaging==.*/packaging==24.0/g' requirements.txt \
&& sed -i 's/pyfiglet==.*/pyfiglet==0.8.post1/g' requirements.txt \
&& sed -i 's/emails==.*/emails==0.6/g' requirements.txt \
&& sed -i 's/cbor2==.*/cbor2==5.4.6/g' requirements.txt \
&& sed -i 's/luma.oled==.*/luma.oled==3.13.0/g' requirements.txt \
&& sed -i 's/python-telegram-bot\[socks,http2\]==.*/python-telegram-bot\[socks,http2\]==20.3/g' requirements.txt \
&& sed -i 's/adafruit-circuitpython-typing==.*/adafruit-circuitpython-typing==1.10.1/g' requirements.txt \
&& sed -i 's/pydantic==.*/pydantic==1.10.9/g' requirements.txt \
&& 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" \
&& git clone https://github.com/iorodeo/iorodeo-as7331.git --depth 1 "3rdparty/iorodeo-as7331" \
&& patch -N -s -r /dev/null 3rdparty/python3-voltcraft-sem6000/sem6000/repeat_on_failure_decorator.py < /python3-voltcraft-sem6000.patch.diff >/dev/null \
&& patch -N -u -l -s -r /dev/null 3rdparty/iorodeo-as7331/iorodeo_as7331/iorodeo_as7331.py < /python3-as7331.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.7-buster 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 theyosh/terrariumpi:4.15.0-buster-java AS finalimage
ARG GITHUB_SHA="development"
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=python_builder /opt/venv /opt/venv
COPY --from=python_builder /TerrariumPI/3rdparty /TerrariumPI/3rdparty
COPY --from=sourcecode /TerrariumPI /TerrariumPI
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"]