diff --git a/j2vm3_full/Dockerfile b/j2vm3_full/Dockerfile index bf7a67d9243a4764ecb0388a460f0ec3dbce85c3..d7d14bcd0e962ae209fbfe00eaac25d1326ddb04 100644 --- a/j2vm3_full/Dockerfile +++ b/j2vm3_full/Dockerfile @@ -4,9 +4,10 @@ MAINTAINER Reinhold Kainhofer <reinhold@kainhofer.com> # Enable Apache Rewrite Module RUN a2enmod rewrite +RUN apt-get update # Install PHP extensions -RUN apt-get update && apt-get install -y libpng12-dev libjpeg-dev zip unzip && rm -rf /var/lib/apt/lists/* \ +RUN apt-get install -y libpng12-dev libjpeg-dev zip unzip \ && docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \ && docker-php-ext-install gd RUN docker-php-ext-install mysqli @@ -14,7 +15,12 @@ RUN docker-php-ext-install mysqli VOLUME /var/www/html # Install MySQL (will only be started if needed) -# RUN apt-get update && apt-get install -y mysql-server && rm -rf /var/lib/apt/lists/* +# RUN export DEBIAN_FRONTEND=noninteractive +RUN echo "mysql-server-5.5 mysql-server/root_password password root" | debconf-set-selections +RUN echo "mysql-server-5.5 mysql-server/root_password_again password root" | debconf-set-selections +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server + +RUN apt-get install -y supervisor # Define Joomla version and expected SHA1 signature @@ -29,10 +35,17 @@ RUN curl -o virtuemart.zip -SL http://dev.virtuemart.net/attachments/download/98 && unzip virtuemart.zip -d /usr/src/virtuemart \ && rm virtuemart.zip \ && chown -R www-data:www-data /usr/src/virtuemart + +RUN echo "[program:mysql]\ncommand=/usr/bin/pidproxy /run/mysqld/mysqld.pid /usr/bin/mysqld_safe \nautorestart=true\n" > /etc/supervisor/conf.d/mysql.conf.save + + +# Clean up the apt cache etc. +RUN rm -rf /var/lib/apt/lists/* # Copy init scripts and custom .htaccess COPY docker-entrypoint.sh /entrypoint.sh COPY makedb.php /makedb.php +ADD supervisord.conf /etc/supervisor/supervisord.conf ENTRYPOINT ["/entrypoint.sh"] -CMD ["apache2-foreground"] +CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"] diff --git a/j2vm3_full/docker-entrypoint.sh b/j2vm3_full/docker-entrypoint.sh index e00b2bb7077a9a378bae37686d850488975e563a..ba5ddae36c7ade6fb20909fa0c875d586df93717 100755 --- a/j2vm3_full/docker-entrypoint.sh +++ b/j2vm3_full/docker-entrypoint.sh @@ -2,102 +2,132 @@ set -e -if [[ "$1" == apache2* ]]; then - if [ -n "$MYSQL_PORT_3306_TCP" ]; then - if [ -z "$JOOMLA_DB_HOST" ]; then - JOOMLA_DB_HOST='mysql' - else - echo >&2 "warning: both JOOMLA_DB_HOST and MYSQL_PORT_3306_TCP found" - echo >&2 " Connecting to JOOMLA_DB_HOST ($JOOMLA_DB_HOST)" - echo >&2 " instead of the linked mysql container" - fi - fi +if [[ ! -e "/etc/opentools-docker-configured" ]]; then + # This docker container has not been configured yet, use the env variables + # to set up the MYSQL server or linked container - # If the DB user is 'root' then use the MySQL root password env var - : ${JOOMLA_DB_USER:=root} - if [ "$JOOMLA_DB_USER" = 'root' ]; then - : ${JOOMLA_DB_PASSWORD:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD} - fi - if [ -z "$JOOMLA_DB_HOST" ]; then - echo >&2 "Neither linked database container nor mysql dabase server host given. " - echo >&2 " Assuming local installation. An instance of the MySQL server will be installed locally." - MYSQL_LOCAL=1 - JOOMLA_DB_HOST="127.0.0.1" - if [ -z "${JOOMLA_DB_PASSWORD}" ]; then - JOOMLA_DB_PASSWORD='root' - echo >&2 "No MySQL root password given. Assuming password 'root'." + # check if a MYSQL container is linked: + if [ -n "$MYSQL_PORT_3306_TCP" ]; then + if [ -z "$JOOMLA_DB_HOST" ]; then + JOOMLA_DB_HOST='mysql' + else + echo >&2 "warning: both JOOMLA_DB_HOST and MYSQL_PORT_3306_TCP found" + echo >&2 " Connecting to JOOMLA_DB_HOST ($JOOMLA_DB_HOST)" + echo >&2 " instead of the linked mysql container" + fi + fi + + # If the DB user is 'root' and no DB password is given, then use the MySQL root password env var + : ${JOOMLA_DB_USER:=root} + if [ "$JOOMLA_DB_USER" = 'root' ]; then + : ${JOOMLA_DB_PASSWORD:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD} + fi + + # Check for local MySQL installation: + if [ -z "$JOOMLA_DB_HOST" ]; then + # No linked container and no explicit DB host => local MySQL installation + echo >&2 "Neither linked database container nor mysql dabase server host given. " + echo >&2 " Assuming local installation. An instance of the MySQL server will be installed locally." + MYSQL_LOCAL=1 + JOOMLA_DB_HOST="127.0.0.1" + if [ -z "${JOOMLA_DB_PASSWORD}" ]; then + JOOMLA_DB_PASSWORD='root' + echo >&2 "No MySQL root password given. Assuming password 'root'." + fi + echo >&2 " Root password is ${JOOMLA_DB_PASSWORD}." + + # Temporarily start the mysql daemon to set up the database and shut it + # down again (supervisord will start it at the very end) + echo "Starting local mysql server temporarily to set up the database..." + /usr/bin/mysqld_safe > /dev/null 2>&1 & + timeout=30 + echo -n "Waiting for database server to accept connections" + while ! /usr/bin/mysqladmin --user=root --password=root status > /dev/null 2>&1; do + timeout=$(($timeout-1)) + if [ $timeout -eq 0 ]; then + echo -e "\n Unable to connecto the database server. Aborting..." + exit 1 fi - echo >&2 " Root password is ${JOOMLA_DB_PASSWORD}." - - export DEBIAN_FRONTEND=noninteractive + echo -n "." + sleep 1 + done + echo + mysqladmin --password=root password "${JOOMLA_DB_PASSWORD}" + + # enable mysqld in the supervisor config + cp /etc/supervisor/conf.d/mysql.conf.save /etc/supervisor/conf.d/mysql.conf + fi - echo "mysql-server-5.5 mysql-server/root_password password ${JOOMLA_DB_PASSWORD}" | debconf-set-selections - echo "mysql-server-5.5 mysql-server/root_password_again password ${JOOMLA_DB_PASSWORD}" | debconf-set-selections -# echo 'phpmyadmin phpmyadmin/dbconfig-install boolean true' | debconf-set-selections -# echo 'phpmyadmin phpmyadmin/app-password-confirm password ${JOOMLA_DB_PASSWORD}' | debconf-set-selections -# echo 'phpmyadmin phpmyadmin/mysql/admin-pass password ${JOOMLA_DB_PASSWORD}' | debconf-set-selections -# echo 'phpmyadmin phpmyadmin/mysql/app-pass password ${JOOMLA_DB_PASSWORD}' | debconf-set-selections -# echo 'phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2' | debconf-set-selections - - dpkg -s mysql-server > /dev/null 2>&1 || ( apt-get -q update && apt-get -y -q install mysql-server && rm -rf /var/lib/apt/lists/* ) -# echo >&2 "error: missing JOOMLA_DB_HOST and MYSQL_PORT_3306_TCP environment variables" -# echo >&2 " Did you forget to --link some_mysql_container:mysql or set an external db" -# echo >&2 " with -e JOOMLA_DB_HOST=hostname:port?" -# exit 1 - fi - if [ -n "$MYSQL_LOCAL" ]; then - echo >&2 "Starting MySQL daemon..." - service mysql restart - fi + + # Now set up the Database for Joomla/VirtueMart: + : ${JOOMLA_DB_NAME:=virtuemart} - : ${JOOMLA_DB_NAME:=virtuemart} + if [ -z "$JOOMLA_DB_PASSWORD" ]; then + echo >&2 "error: missing required JOOMLA_DB_PASSWORD environment variable" + echo >&2 " Did you forget to -e JOOMLA_DB_PASSWORD=... or link to a container?" + echo >&2 + echo >&2 " (Also of interest might be JOOMLA_DB_USER and JOOMLA_DB_NAME.)" + exit 1 + fi + # Ensure the MySQL Database is created + php /makedb.php "$JOOMLA_DB_HOST" "$JOOMLA_DB_USER" "$JOOMLA_DB_PASSWORD" "$JOOMLA_DB_NAME" + + if [ "$MYSQL_LOCAL" = "1" ]; then + # Local installation, so shut down MySQL again, will later be started through supervisord + /usr/bin/mysqladmin --user=root --password="${JOOMLA_DB_PASSWORD}" shutdown + fi - if [ -z "$JOOMLA_DB_PASSWORD" ]; then - echo >&2 "error: missing required JOOMLA_DB_PASSWORD environment variable" - echo >&2 " Did you forget to -e JOOMLA_DB_PASSWORD=... ?" - echo >&2 - echo >&2 " (Also of interest might be JOOMLA_DB_USER and JOOMLA_DB_NAME.)" - exit 1 - fi - if ! [ -e index.php -a -e libraries/cms/version/version.php ]; then - echo >&2 "Virtuemart/Joomla not found in $(pwd) - copying now..." + # Now set up the Joomla/VirtueMart installation files in apache's directory: + if ! [ -e index.php -a -e libraries/cms/version/version.php ]; then + echo >&2 "Virtuemart/Joomla not found in $(pwd) - copying now..." - if [ "$(ls -A)" ]; then - echo >&2 "WARNING: $(pwd) is not empty - press Ctrl+C now if this is an error!" - ( set -x; ls -A; sleep 10 ) - fi + if [ "$(ls -A)" ]; then + echo >&2 "WARNING: $(pwd) is not empty - press Ctrl+C now if this is an error!" + ( set -x; ls -A; sleep 10 ) + fi - tar cf - --one-file-system -C /usr/src/virtuemart . | tar xf - + tar cf - --one-file-system -C /usr/src/virtuemart . | tar xf - + + # Some versions of the full installer hae an additional subdir in the ZIP file. + # Search for joomla.xml and mv everything from that directory to the webroot + if [ ! -e joomla.xml ]; then + for jmanifest in */joomla.xml; do + jdir=$(dirname $jmanifest) + echo + mv $jdir/** . + rm -rf $jdir + done + fi - if [ ! -e .htaccess ]; then - # NOTE: The "Indexes" option is disabled in the php:apache base image so remove it as we enable .htaccess - sed -r 's/^(Options -Indexes.*)$/#\1/' htaccess.txt > .htaccess - chown www-data:www-data .htaccess - fi - - sed 's/default="localhost"/default="'$JOOMLA_DB_HOST'"/; - s/\(db_user.*\)$/\1 default="'$JOOMLA_DB_USER'"/; - s/\(db_pass.*\)$/\1 default="'$JOOMLA_DB_PASSWORD'"/; - s/\(db_name.*\)$/\1 default="'$JOOMLA_DB_NAME'"/' installation/models/forms/database.xml > installation/models/forms/database.xml.new - mv installation/models/forms/database.xml.new installation/models/forms/database.xml + if [ -e htaccess.txt -a ! -e .htaccess ]; then + # NOTE: The "Indexes" option is disabled in the php:apache base image so remove it as we enable .htaccess + sed -r 's/^(Options -Indexes.*)$/#\1/' htaccess.txt > .htaccess + chown www-data:www-data .htaccess + fi - echo >&2 "Complete! Virtuemart has been successfully copied to $(pwd)" - fi + sed 's/default="localhost"/default="'$JOOMLA_DB_HOST'"/; + s/\(db_user.*\)$/\1 default="'$JOOMLA_DB_USER'"/; + s/\(db_pass.*\)$/\1 default="'$JOOMLA_DB_PASSWORD'"/; + s/\(db_name.*\)$/\1 default="'$JOOMLA_DB_NAME'"/' installation/models/forms/database.xml > installation/models/forms/database.xml.new + mv installation/models/forms/database.xml.new installation/models/forms/database.xml - # Ensure the MySQL Database is created - php /makedb.php "$JOOMLA_DB_HOST" "$JOOMLA_DB_USER" "$JOOMLA_DB_PASSWORD" "$JOOMLA_DB_NAME" + echo >&2 "Complete! Virtuemart has been successfully copied to $(pwd)" + fi - echo >&2 "========================================================================" - echo >&2 - echo >&2 "This server is now configured to run Joomla!" - echo >&2 "You will need the following database information to install Joomla:" - echo >&2 "Host Name: $JOOMLA_DB_HOST" - echo >&2 "Database Name: $JOOMLA_DB_NAME" - echo >&2 "Database Username: $JOOMLA_DB_USER" - echo >&2 "Database Password: $JOOMLA_DB_PASSWORD" - echo >&2 - echo >&2 "========================================================================" + echo >&2 "========================================================================" + echo >&2 + echo >&2 "This server is now configured to run Joomla!" + echo >&2 "You will need the following database information to install Joomla:" + echo >&2 "Host Name: $JOOMLA_DB_HOST" + echo >&2 "Database Name: $JOOMLA_DB_NAME" + echo >&2 "Database Username: $JOOMLA_DB_USER" + echo >&2 "Database Password: $JOOMLA_DB_PASSWORD" + echo >&2 + echo >&2 "========================================================================" + + # create the file to indicate this container has been configured: + touch /etc/opentools-docker-configured fi exec "$@" diff --git a/j2vm3_full/supervisord.conf b/j2vm3_full/supervisord.conf new file mode 100644 index 0000000000000000000000000000000000000000..d5d19a313ccd350bf7ed729de8ae6a1e0a1de4bc --- /dev/null +++ b/j2vm3_full/supervisord.conf @@ -0,0 +1,10 @@ +[supervisord] +nodaemon=true + +[program:apache] +command=/usr/local/bin/apache2-foreground +autorestart=true + +[include] +files = /etc/supervisor/conf.d/*.conf +