From f2dbb1fe08e9369f642ef6ec8d69da92ff1fc127 Mon Sep 17 00:00:00 2001 From: Hamilton Turner Date: Fri, 18 Apr 2014 02:41:18 -0400 Subject: [PATCH] Dockerfile works properly, documentation updated - Dockerfile now builds properly - Dockerfile now ADDs files from local directory. This allows you to either pull from github (for master) or to build locally (for development) - Removes some dependencies from container (wget, git) - Removes pulling apache virtual host file from github - Upgrades MySQL start check to actually check instead of just sleeping --- Dockerfile | 21 ++++++++++++--------- README.md | 6 ++++++ utils/docker/README.md | 38 ++++++++++++++++++++++++++++++++------ utils/docker/apache-vhost | 13 +++++++++++++ utils/docker/start.sh | 23 ++++++++++++++++++----- 5 files changed, 81 insertions(+), 20 deletions(-) create mode 100644 utils/docker/apache-vhost diff --git a/Dockerfile b/Dockerfile index 6b5c5da97..5d0a4314c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,16 +12,13 @@ RUN apt-get update RUN apt-get upgrade -y # Install the prerequisites -RUN apt-get install -y 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 subversion automake autoconf libjpeg-turbo8-dev libjpeg-turbo8 libtheora-dev libvorbis-dev libvpx-dev libx264-dev libmp4v2-dev ffmpeg git wget mysql-client apache2 php5 php5-mysql apache2-mpm-prefork libapache2-mod-php5 php5-cli openssh-server mysql-server libvlc-dev libvlc5 libvlccore-dev libvlccore5 vlc-data vlc libcurl4-openssl-dev +RUN apt-get install -y 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 subversion automake autoconf libjpeg-turbo8-dev libjpeg-turbo8 libtheora-dev libvorbis-dev libvpx-dev libx264-dev libmp4v2-dev ffmpeg mysql-client apache2 php5 php5-mysql apache2-mpm-prefork libapache2-mod-php5 php5-cli openssh-server mysql-server libvlc-dev libvlc5 libvlccore-dev libvlccore5 vlc-data vlc libcurl4-openssl-dev -# Grab the latest ZoneMinder code in master -RUN git clone https://github.com/kylejohnson/ZoneMinder.git +# Copy local code into our container +ADD . /ZoneMinder # Change into the ZoneMinder directory -WORKDIR ZoneMinder - -# Check out the release-1.27 branch -RUN git checkout release-1.27 +WORKDIR /ZoneMinder # Setup the ZoneMinder build environment RUN aclocal && autoheader && automake --force-missing --add-missing && autoconf @@ -38,9 +35,16 @@ RUN make install # Adding the start script ADD utils/docker/start.sh /tmp/start.sh -# Make start script executable +# Ensure we can run this +# TODO - Files ADD'ed have 755 already...why do we need this? RUN chmod 755 /tmp/start.sh +# Creating SSH privledge escalation dir +RUN mkdir /var/run/sshd + +# Adding apache virtual hosts file +ADD utils/docker/apache-vhost /etc/apache2/sites-enabled/000-default + # Set the root passwd RUN echo 'root:root' | chpasswd @@ -48,5 +52,4 @@ RUN echo 'root:root' | chpasswd EXPOSE 80 EXPOSE 22 - CMD "/tmp/start.sh" diff --git a/README.md b/README.md index a86a75cfe..3d23a0981 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,12 @@ perl-IO-Zlib perl-MailTools perl-MIME-Lite perl-MIME-tools perl-MIME-Types perl- perl-TimeDate perl-YAML-Syck php php-cli php-mysql subversion x264 vlc-devel vlc-core libcurl libcurl-devel ``` +#### Docker + +Docker is a system to run applications inside isolated containers. ZoneMinder, and the ZM webserver, will run using the +Dockerfile contained in this repository. However, there is still work needed to ensure that the main ZM features work +properly and are documented. + ### ffmpeg This release of ZoneMinder has been tested on and works with ffmpeg version N-55540-g93f4277. diff --git a/utils/docker/README.md b/utils/docker/README.md index 310651155..4ca100b66 100644 --- a/utils/docker/README.md +++ b/utils/docker/README.md @@ -1,21 +1,47 @@ # Overview -Docker allows you to quickly spin up containers. The ZoneMinder dockerfile will spin -up an Ubuntu 12.04 container with mysql, apache, php and then compile and install ZoneMinder (from master). +[Docker](https://www.docker.io/) allows you to quickly spin up application containers, +which are similar to very lightweight virtual machines. The ZoneMinder Dockerfile will +start an Ubuntu 12.04 container with MySql, Apache, and PHP properly configured, and +will then compile and install ZoneMinder. -Afterwards you can connect to this container over SSH to check out the latest code. +It will also start an SSH server that you can use to log into the container. This is still a bit of a work in progress. ## How To Use -1. Pull it -```sudo docker pull ubuntu:precise``` -2. Built it +1. Install [Docker](https://www.docker.io/) +2. Build ZoneMinder container ```sudo docker build -t yourname/zoneminder github.com/ZoneMinder/ZoneMinder``` 3. Run it ```CID=$(sudo docker run -d -p 222:22 -p 8080:80 -name zoneminder yourname/zoneminder)``` 4. Use it -- you can now SSH to port 222 on your host as user root with password root. You can also browse to your host on port 8080 to access the zoneminder web interface +## Developing With Docker + +If you wish to contribute to ZoneMinder, Docker can be helpful. By re-running +```docker build``` in your working directory, any code modifications you have +made will be pulled into a new container, compiled, and started, all without +modifying your base system. + +Development is not totally without annoyances, as any change +to the project will require a full rebuild of all C++. Docker notices that the +directory which has been ADD'ed is now different, and therefore all steps after +the ADD command must be recomputed. A fix for this is to update the Dockerfile to +move the configure and make commands into start.sh, and then use a volume mount +to cache the build directory (I think it's ```/tmp```) on your host filesystem. +This would be really useful for a developer, and would remove the annoying build +problem, but some of the Docker push/pull benefits would be lost. + +Docker containers can be both CPU and memory limited, so this can be a practical +method to compile or run multiple development builds of ZoneFinder simultaneously +without taxing your host system. + ## Use Cases + +## TODO +- Describe how to connect to monitors by mounting devices +- Create a 'development' dockerfile to remove the need to rebuild the entire project + after each small change diff --git a/utils/docker/apache-vhost b/utils/docker/apache-vhost new file mode 100644 index 000000000..622e4b5e4 --- /dev/null +++ b/utils/docker/apache-vhost @@ -0,0 +1,13 @@ + + DocumentRoot /var/www/zm + DirectoryIndex index.php + + ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ + + AllowOverride None + Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch + Order allow,deny + Allow from all + + + diff --git a/utils/docker/start.sh b/utils/docker/start.sh index 9f9000ce9..76ad3dcbb 100644 --- a/utils/docker/start.sh +++ b/utils/docker/start.sh @@ -2,7 +2,24 @@ # Start MySQL /usr/bin/mysqld_safe & -sleep 5 + +# 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 + + # 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 # Create the ZoneMinder database mysql -u root < db/zm_create.sql @@ -10,9 +27,6 @@ mysql -u root < db/zm_create.sql # Add the ZoneMinder DB user mysql -u root -e "grant insert,select,update,delete,lock tables,alter on zm.* to 'zm'@'localhost' identified by 'zm'" -# Install the ZoneMinder apache vhost file -wget --quiet https://raw.github.com/kylejohnson/puppet-zoneminder/master/files/zoneminder -O /etc/apache2/sites-enabled/000-default - # Restart apache service apache2 restart @@ -20,5 +34,4 @@ service apache2 restart /usr/local/bin/zmpkg.pl start # Start SSHD -mkdir /var/run/sshd /usr/sbin/sshd -D