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:
parent
a9ebcd6e8a
commit
214d9898a3
91
Dockerfile
91
Dockerfile
|
@ -1,24 +1,75 @@
|
|||
# ZoneMinder
|
||||
# ZoneMinder, you need the GIT repository code and submodules (git submodule update --init --recursive)
|
||||
|
||||
FROM ubuntu:xenial
|
||||
MAINTAINER Markos Vakondios <mvakondios@gmail.com>
|
||||
|
||||
# Resynchronize the package index files
|
||||
RUN apt-get update && \
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
||||
libpolkit-gobject-1-dev build-essential libmysqlclient-dev libssl-dev libbz2-dev libpcre3-dev \
|
||||
libdbi-perl libarchive-zip-perl libdate-manip-perl libdevice-serialport-perl libmime-perl libpcre3 \
|
||||
libwww-perl libdbd-mysql-perl libsys-mmap-perl yasm cmake libjpeg-turbo8-dev \
|
||||
libjpeg-turbo8 libtheora-dev libvorbis-dev libvpx-dev libx264-dev libmp4v2-dev libav-tools mysql-client \
|
||||
apache2 php php-mysql libapache2-mod-php php-cli \
|
||||
mysql-server libvlc-dev libvlc5 libvlccore-dev libvlccore8 vlc-data libcurl4-openssl-dev \
|
||||
libavformat-dev libswscale-dev libavutil-dev libavcodec-dev libavfilter-dev \
|
||||
libavresample-dev libavdevice-dev libpostproc-dev libv4l-dev libtool libnetpbm10-dev \
|
||||
libmime-lite-perl dh-autoreconf dpatch \
|
||||
&& apt-get clean
|
||||
RUN apt-get update \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||
apache2 \
|
||||
build-essential \
|
||||
cmake \
|
||||
dh-autoreconf \
|
||||
dpatch \
|
||||
libapache2-mod-php \
|
||||
libarchive-zip-perl \
|
||||
libavcodec-dev \
|
||||
libavdevice-dev \
|
||||
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
|
||||
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
|
||||
WORKDIR /ZoneMinder
|
||||
|
@ -39,18 +90,20 @@ RUN ./zmlinkcontent.sh
|
|||
# Adding the start script
|
||||
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/
|
||||
|
||||
# Adding apache virtual hosts file
|
||||
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 80
|
||||
|
||||
# Initial database and apache setup:
|
||||
RUN "/ZoneMinder/utils/docker/setup.sh"
|
||||
VOLUME /var/lib/zoneminder/images /var/lib/zoneminder/events /var/lib/mysql /var/log/zm
|
||||
|
||||
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
|
||||
|
|
|
@ -1,46 +1,75 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Start MySQL
|
||||
# For Xenial the following won't start mysqld
|
||||
#/usr/bin/mysqld_safe &
|
||||
# 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
|
||||
setup_mysql_first_time(){
|
||||
if [ "$(ls /var/lib/mysql)" ]; then
|
||||
return
|
||||
fi
|
||||
let SECONDS_LEFT=SECONDS_LEFT-1
|
||||
|
||||
# If we have waited >120 seconds, give up
|
||||
# ZM should never have a database that large!
|
||||
# if $COUNTER -lt 120
|
||||
if [ $SECONDS_LEFT -eq 0 ];then
|
||||
return -1;
|
||||
fi
|
||||
done
|
||||
# Set MySQL in the volume
|
||||
rm -rf /var/lib/mysql/*
|
||||
chown -R mysql:mysql /var/lib/mysql
|
||||
mysqld --initialize-insecure
|
||||
|
||||
# Create the ZoneMinder database
|
||||
mysql -u root < db/zm_create.sql
|
||||
# Start MySQL
|
||||
# For Xenial the following won't start mysqld
|
||||
#/usr/bin/mysqld_safe &
|
||||
# Use this instead:
|
||||
service mysql start
|
||||
|
||||
# Add the ZoneMinder DB user
|
||||
mysql -u root -e "grant insert,select,update,delete,lock tables,alter on zm.* to 'zmuser'@'localhost' identified by 'zmpass';"
|
||||
# Give MySQL time to wake up
|
||||
SECONDS_LEFT=120
|
||||
while true; do
|
||||
sleep 1
|
||||
mysqladmin ping
|
||||
if [ $? -eq 0 ];then
|
||||
break; # Success
|
||||
fi
|
||||
let SECONDS_LEFT=SECONDS_LEFT-1
|
||||
|
||||
# Make ZM_LOGDIR
|
||||
mkdir /var/log/zm
|
||||
# If we have waited >120 seconds, give up
|
||||
# ZM should never have a database that large!
|
||||
# if $COUNTER -lt 120
|
||||
if [ $SECONDS_LEFT -eq 0 ];then
|
||||
return -1;
|
||||
fi
|
||||
done
|
||||
|
||||
# Activate CGI
|
||||
a2enmod cgi
|
||||
# Create the ZoneMinder database
|
||||
mysql -u root < db/zm_create.sql
|
||||
|
||||
# Activate modrewrite
|
||||
a2enmod rewrite
|
||||
# Add the ZoneMinder DB user
|
||||
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
|
||||
# Shut down mysql cleanly:
|
||||
kill $(cat /var/run/mysqld/mysqld.pid)
|
||||
sleep 5
|
||||
}
|
||||
|
||||
setup_mysql() {
|
||||
# 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
|
||||
}
|
||||
|
||||
setup_php() {
|
||||
# Activate CGI
|
||||
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
|
||||
|
|
|
@ -35,7 +35,7 @@ done
|
|||
service apache2 restart
|
||||
|
||||
# Start ZoneMinder
|
||||
/usr/local/bin/zmpkg.pl start
|
||||
/usr/local/bin/zmpkg.pl start && echo "Zone Minder started"
|
||||
|
||||
while :
|
||||
do
|
||||
|
|
Loading…
Reference in New Issue