Enchancing Dockerfile and docker execution (#1898)

* Enchancing Dockerfile and docker execution

* Setting database if does not exist\nSolving SQL problem when adding monitor

* Sharing events and images

* Dockerfile a little bit more flexible

* Setting better start command
This commit is contained in:
Ravaka Razafimanantsoa 2017-06-07 02:22:37 +02:00 committed by Isaac Connor
parent a9ebcd6e8a
commit 214d9898a3
3 changed files with 136 additions and 54 deletions

View File

@ -1,24 +1,75 @@
# ZoneMinder # ZoneMinder, you need the GIT repository code and submodules (git submodule update --init --recursive)
FROM ubuntu:xenial FROM ubuntu:xenial
MAINTAINER Markos Vakondios <mvakondios@gmail.com> MAINTAINER Markos Vakondios <mvakondios@gmail.com>
# Resynchronize the package index files # Resynchronize the package index files
RUN apt-get update && \ RUN apt-get update \
DEBIAN_FRONTEND=noninteractive apt-get install -y \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
libpolkit-gobject-1-dev build-essential libmysqlclient-dev libssl-dev libbz2-dev libpcre3-dev \ apache2 \
libdbi-perl libarchive-zip-perl libdate-manip-perl libdevice-serialport-perl libmime-perl libpcre3 \ build-essential \
libwww-perl libdbd-mysql-perl libsys-mmap-perl yasm cmake libjpeg-turbo8-dev \ cmake \
libjpeg-turbo8 libtheora-dev libvorbis-dev libvpx-dev libx264-dev libmp4v2-dev libav-tools mysql-client \ dh-autoreconf \
apache2 php php-mysql libapache2-mod-php php-cli \ dpatch \
mysql-server libvlc-dev libvlc5 libvlccore-dev libvlccore8 vlc-data libcurl4-openssl-dev \ libapache2-mod-php \
libavformat-dev libswscale-dev libavutil-dev libavcodec-dev libavfilter-dev \ libarchive-zip-perl \
libavresample-dev libavdevice-dev libpostproc-dev libv4l-dev libtool libnetpbm10-dev \ libavcodec-dev \
libmime-lite-perl dh-autoreconf dpatch \ libavdevice-dev \
&& apt-get clean libavfilter-dev \
libavformat-dev \
libavresample-dev \
libav-tools \
libavutil-dev \
libbz2-dev \
libcurl4-openssl-dev \
libdate-manip-perl \
libdbd-mysql-perl \
libdbi-perl \
libdevice-serialport-perl \
libjpeg-turbo8 \
libjpeg-turbo8-dev \
libmime-lite-perl \
libmime-perl \
libmp4v2-dev \
libmysqlclient-dev \
libnetpbm10-dev \
libpcre3 \
libpcre3-dev \
libpolkit-gobject-1-dev \
libpostproc-dev \
libssl-dev \
libswscale-dev \
libsys-mmap-perl \
libtheora-dev \
libtool \
libv4l-dev \
libvlc5 \
libvlccore8 \
libvlccore-dev \
libvlc-dev \
libvorbis-dev \
libvpx-dev \
libwww-perl \
libx264-dev \
mysql-client \
mysql-server \
php \
php-cli \
php-mysql \
vlc-data \
yasm \
&& rm -rf /var/lib/apt/lists/*
# Copy local code into our container # Copy local code into our container
ADD . /ZoneMinder ADD cmake /ZoneMinder/cmake/
ADD db /ZoneMinder/db/
ADD misc /ZoneMinder/misc/
ADD onvif /ZoneMinder/onvif/
ADD scripts /ZoneMinder/scripts/
ADD src /ZoneMinder/src/
ADD umutils /ZoneMinder/umutils/
ADD web /ZoneMinder/web/
ADD cmakecacheimport.sh CMakeLists.txt version zm.conf.in zmconfgen.pl.in zmlinkcontent.sh.in zoneminder-config.cmake /ZoneMinder/
# Change into the ZoneMinder directory # Change into the ZoneMinder directory
WORKDIR /ZoneMinder WORKDIR /ZoneMinder
@ -39,18 +90,20 @@ RUN ./zmlinkcontent.sh
# Adding the start script # Adding the start script
ADD utils/docker/start.sh /tmp/start.sh ADD utils/docker/start.sh /tmp/start.sh
# give files in /usr/local/share/zoneminder/ # Settings rights for /usr/local/share/zoneminder/
RUN chown -R www-data:www-data /usr/local/share/zoneminder/ RUN chown -R www-data:www-data /usr/local/share/zoneminder/
# Adding apache virtual hosts file # Adding apache virtual hosts file
RUN cp misc/apache.conf /etc/apache2/sites-available/000-default.conf RUN cp misc/apache.conf /etc/apache2/sites-available/000-default.conf
ADD utils/docker/phpdate.ini /etc/php5/apache2/conf.d/25-phpdate.ini
# Expose http port # Expose http port
EXPOSE 80 EXPOSE 80
# Initial database and apache setup: VOLUME /var/lib/zoneminder/images /var/lib/zoneminder/events /var/lib/mysql /var/log/zm
RUN "/ZoneMinder/utils/docker/setup.sh"
CMD ["/ZoneMinder/utils/docker/start.sh"] # To speed up configuration testing, we put it here
ADD utils/docker /ZoneMinder/utils/docker/
CMD /ZoneMinder/utils/docker/setup.sh && /ZoneMinder/utils/docker/start.sh >/var/log/start.log 2>&1 & /bin/bash
# Run example docker run -it -p 1080:80 -e PHP_TIMEZONE='Europe/Paris' -v /disk/zoneminder/events:/var/lib/zoneminder/events -v /disk/zoneminder/images:/var/lib/zoneminder/images -v /disk/zoneminder/mysql:/var/lib/mysql -v /disk/zoneminder/logs:/var/log/zm --name zoneminder zoneminder/zoneminder

View File

@ -1,46 +1,75 @@
#!/bin/bash #!/bin/bash
# Start MySQL setup_mysql_first_time(){
# For Xenial the following won't start mysqld if [ "$(ls /var/lib/mysql)" ]; then
#/usr/bin/mysqld_safe & return
# Use this instead:
service mysql start
# Give MySQL time to wake up
SECONDS_LEFT=120
while true; do
sleep 1
mysqladmin ping
if [ $? -eq 0 ];then
break; # Success
fi fi
let SECONDS_LEFT=SECONDS_LEFT-1
# If we have waited >120 seconds, give up # Set MySQL in the volume
# ZM should never have a database that large! rm -rf /var/lib/mysql/*
# if $COUNTER -lt 120 chown -R mysql:mysql /var/lib/mysql
if [ $SECONDS_LEFT -eq 0 ];then mysqld --initialize-insecure
return -1;
fi # Start MySQL
done # For Xenial the following won't start mysqld
#/usr/bin/mysqld_safe &
# Use this instead:
service mysql start
# Create the ZoneMinder database # Give MySQL time to wake up
mysql -u root < db/zm_create.sql SECONDS_LEFT=120
while true; do
sleep 1
mysqladmin ping
if [ $? -eq 0 ];then
break; # Success
fi
let SECONDS_LEFT=SECONDS_LEFT-1
# Add the ZoneMinder DB user # If we have waited >120 seconds, give up
mysql -u root -e "grant insert,select,update,delete,lock tables,alter on zm.* to 'zmuser'@'localhost' identified by 'zmpass';" # ZM should never have a database that large!
# if $COUNTER -lt 120
if [ $SECONDS_LEFT -eq 0 ];then
return -1;
fi
done
# Make ZM_LOGDIR # Create the ZoneMinder database
mkdir /var/log/zm mysql -u root < db/zm_create.sql
# Activate CGI # Add the ZoneMinder DB user
a2enmod cgi mysql -u root -e "grant insert,select,update,delete,lock tables,alter on zm.* to 'zmuser'@'localhost' identified by 'zmpass';"
# Shut down mysql cleanly:
kill $(cat /var/run/mysqld/mysqld.pid)
sleep 5
}
# Activate modrewrite setup_mysql() {
a2enmod rewrite # To configure MySQL if no container did it before
setup_mysql_first_time
# Add configuration to avoid SQL error when adding monitor
echo "sql_mode=NO_ENGINE_SUBSTITUTION" >> /etc/mysql/mysql.conf.d/mysqld.cnf
}
# Shut down mysql cleanly: setup_php() {
kill $(cat /var/run/mysqld/mysqld.pid) # Activate CGI
sleep 5 a2enmod cgi
# Activate modrewrite
a2enmod rewrite
# Setting timezone
sed -i "s#;date.timezone =#date.timezone = $PHP_TIMEZONE#" /etc/php/7.0/apache2/php.ini
# Settings rights for volume
chown -R www-data:www-data /var/lib/zoneminder/events
chown -R www-data:www-data /var/lib/zoneminder/images
}
setup_mysql
setup_php
exit 0 exit 0

View File

@ -35,7 +35,7 @@ done
service apache2 restart service apache2 restart
# Start ZoneMinder # Start ZoneMinder
/usr/local/bin/zmpkg.pl start /usr/local/bin/zmpkg.pl start && echo "Zone Minder started"
while : while :
do do