Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<build>(docker): refactor our dockerfile according to best practice #51

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
__pycache__
.mypy_cache
.pytest_cache
.vscode
bower_components
venv
node_modules
.git
.github
32 changes: 26 additions & 6 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

set -e

LOG="$PWD/berrynet-install.log"
INFO_LOG="$PWD/berrynet-install.log"
LOG="$PWD/berrynet-install-error.log"
DISTRIBUTIONID=`lsb_release -i -s`
CODENAME=`lsb_release -c -s`
INSTALL_TENSORFLOW="Y"
Expand Down Expand Up @@ -285,6 +286,9 @@ install_caffe2() {

update_system_service() {
sudo service mosquitto restart
# [BUG]: error: <class 'socket.error'>, [Errno 2] No such file or directory: file: /usr/lib/python2.7/socket.py line: 228
# [ref]: https://github.com/Supervisor/supervisor/issues/376
sudo supervisord
sudo supervisorctl reload
sudo a2enconf berrynet-dashboard
}
Expand All @@ -303,7 +307,7 @@ if [ "$INSTALL_TENSORFLOW" = "Y" ]; then
install_model mobilenet-1.0-224-quantized-tflite 2>&1 | tee -a $LOG
install_model mobilenet-ssd-coco-tflite 2>&1 | tee -a $LOG
else
echo "Not install TensorFlow" >> $LOG
echo "Not install TensorFlow" >> $INFO_LOG
fi

if [ "$INSTALL_OPENVINO" = "Y" ]; then
Expand All @@ -312,25 +316,41 @@ if [ "$INSTALL_OPENVINO" = "Y" ]; then
install_model mobilenet-1.0-224-fp16-openvino 2>&1 | tee -a $LOG
install_model mobilenet-ssd-openvino 2>&1 | tee -a $LOG
else
echo "Not install OpenVINO" >> $LOG
echo "Not install OpenVINO" >> $INFO_LOG
fi

if [ "$INSTALL_DARKNET" = "Y" ]; then
install_darknet 2>&1 | tee -a $LOG
install_model tinyyolovoc 2>&1 | tee -a $LOG
else
echo "Not install Darknet NNPACK" >> $LOG
echo "Not install Darknet NNPACK" >> $INFO_LOG
fi

if [ "$INSTALL_CAFFE2" = "Y" ]; then
install_caffe2 2>&1 | tee -a $LOG
download_classifier_model_caffe2 2>&1 | tee -a $LOG
else
echo "Not install Caffe2" >> $LOG
echo "Not install Caffe2" >> $INFO_LOG
fi

update_system_service 2>&1 | tee -a $LOG

# if these string exists in $LOG, throw exception
if grep -i "error" $LOG
then
exit 1
fi

if grep -i "not found" $LOG
then
exit 1
fi

if grep -i "exception" $LOG
then
exit 1
fi

{
echo "Installation is completed successfully!"
echo ""
Expand All @@ -344,4 +364,4 @@ update_system_service 2>&1 | tee -a $LOG
echo " /usr/local/berrynet/npm-debug.log"
echo ""
echo "We are happy to check and fix it, thank you!"
} | tee -a $LOG
} | tee -a $INFO_LOG
64 changes: 34 additions & 30 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
# We start from Debian Buster. Can be rebase to Raspbian because they are
# similar
FROM debian:buster
FROM python:3.7-slim-buster
LABEL maintainer="[email protected]"
LABEL project="Berrynet"
LABEL version="3.7.0"

# Update apt
RUN apt-get update

# Install dependencies
RUN apt-get install -y git sudo wget lsb-release software-properties-common

# Install build-essential
RUN apt-get install -y build-essential curl

# Install systemd
RUN apt-get install -y systemd systemd-sysv

# Install python
RUN apt-get install -y python3 python3-dev
ENV POETRY_VIRTUALENVS_CREATE=false \
POETRY_CACHE_DIR='/var/cache/pypoetry'

# Install python libs
RUN apt-get install -y python3-wheel python3-setuptools python3-pip
RUN apt-get install -y python3-paho-mqtt python3-logzero python3-astor
RUN apt-get install -y python3-opengl python3-six python3-grpcio
RUN apt-get install -y python3-keras-applications python3-keras-preprocessing
RUN apt-get install -y python3-protobuf python3-termcolor python3-numpy

# Install daemons
RUN apt-get install -y mosquitto mosquitto-clients
RUN apt-get install -y apache2

# Install tensorflow
RUN pip3 install tensorflow
# Update apt
RUN apt-get update \
# Install dependencies
&& apt-get install -y --no-install-recommends git sudo wget lsb-release software-properties-common gnupg \
# Install build-essential
build-essential curl \
# Install systemd
systemd systemd-sysv \
# Install daemons
mosquitto mosquitto-clients \
apache2

# Install python dependencies
WORKDIR /app
COPY poetry.lock poetry.lock
COPY pyproject.toml pyproject.toml
# [WORKAROUND]: pip3 20.2.1 in 3.7 image would raise "ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE"
# REF: https://stackoverflow.com/questions/61551480/clean-docker-pip-install-results-in-error-these-packages-do-not-match-the-hashe
RUN pip3 install pip==20.0.2 \
&& pip3 install --no-cache-dir poetry \
&& poetry install --no-interaction --no-ansi --no-dev \
# Cleaning poetry installation's cache for production:
&& rm -rf "$POETRY_CACHE_DIR" \
&& pip3 uninstall -yq poetry

# Install BerryNet
RUN git clone https://github.com/DT42/BerryNet.git
RUN cd BerryNet; ./configure
WORKDIR /app/BerryNet
COPY . .
RUN ./configure

# remote redundant packages
RUN apt-get remove --auto-remove --purge -y git wget lsb-release software-properties-common curl build-essential \
&& rm -rf /var/lib/apt/lists/*
Loading