From 9c69c4ee1ae5836dc6e0354abcf81a2fec77dab7 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Fri, 6 May 2016 17:23:04 -0500 Subject: [PATCH] Added in mysql conf files; trying to get correct php extensions for magento to run --- .gitignore | 1 + docker-compose.yaml | 15 ++-- mysql/Dockerfile | 5 ++ mysql/mage-dbdump.sh | 197 +++++++++++++++++++++++++++++++++++++++++++ mysql/my.cnf | 28 ++++++ nginx/default.cnf | 2 +- php/Dockerfile | 24 +++++- 7 files changed, 263 insertions(+), 9 deletions(-) create mode 100644 .gitignore create mode 100644 mysql/Dockerfile create mode 100644 mysql/mage-dbdump.sh create mode 100644 mysql/my.cnf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7bf449e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +public_html/* \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 092b2f1..cd29463 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -17,20 +17,23 @@ php: - app app: - image: php:7.0-fpm + image: php:5.6-fpm volumes: - ./public_html:/var/www/html command: "true" mysql: - image: mysql:latest + build: ./mysql/ volumes_from: - data + - app + ports: + - 3306:3306 environment: - MYSQL_ROOT_PASSWORD: password - MYSQL_DATABASE: project - MYSQL_USER: project - MYSQL_PASSWORD: project + MYSQL_ROOT_PASSWORD: 123123 + MYSQL_DATABASE: magento + MYSQL_USER: magento + MYSQL_PASSWORD: magento data: image: mysql:latest diff --git a/mysql/Dockerfile b/mysql/Dockerfile new file mode 100644 index 0000000..fd56f3f --- /dev/null +++ b/mysql/Dockerfile @@ -0,0 +1,5 @@ +FROM mysql:latest +RUN apt-get update -y && apt-get install -y vim +COPY ./my.cnf /etc/mysql/my.cnf +COPY ./mage-dbdump.sh /opt/mage-dbdump.sh +RUN chmod 644 /etc/mysql/my.cnf \ No newline at end of file diff --git a/mysql/mage-dbdump.sh b/mysql/mage-dbdump.sh new file mode 100644 index 0000000..a1ebd95 --- /dev/null +++ b/mysql/mage-dbdump.sh @@ -0,0 +1,197 @@ +#!/bin/bash + +IGNORE_TABLES=( dataflow_batch_export dataflow_batch_import log_customer log_quote log_summary log_summary_type log_url log_url_info log_visitor log_visitor_info log_visitor_online report_event index_event enterprise_logging_event_changes core_cache core_cache_tag core_session core_cache_tag ) +IGNORE_TABLES_AGGRESSIVE=( report_compared_product_index report_viewed_product_index sales_flat_quote_address sales_flat_quote_shipping_rate enterprise_customer_sales_flat_quote enterprise_customer_sales_flat_quote_address sales_flat_quote ) +TRUNCATE_TABLES=( dataflow_batch_export dataflow_batch_import log_customer log_quote log_summary log_summary_type log_url log_url_info log_visitor log_visitor_info log_visitor_online report_viewed_product_index report_compared_product_index report_event index_event index_process_event ) +CONFIG_FILE="./app/etc/local.xml" +DUMP_FILE="./var/db.sql" + +function usage() +{ +cat < prompt + -c Clean log and index tables + +EOF +} + +function error() +{ + echo -e "Error: $1" + [[ ! "$2" == "noexit" ]] && exit 1 +} + +function getParam() +{ + RETVAL=$(grep -Eoh "<$1>()?<\/$1>" $TMP_FILE | sed "s#<$1><\/$1>##g") + if [[ "$2" == "sanitise" ]]; then + RETVAL=$(echo "$RETVAL" | sed 's/"/\\\"/g') + fi + echo -e "$RETVAL" +} + +function compress() +{ + while read DATA; do + [[ ! "$OPT_z" == "" ]] && (echo "$DATA" | $GZIP_CMD -) || echo "$DATA" + done +} + +function mysqldumpit() +{ + + if [[ "$OPT_f" == "" ]]; then + [[ ! "$OPT_A" == "" ]] && IGNORE_TABLES=( ${IGNORE_TABLES[@]} ${IGNORE_TABLES_AGGRESSIVE[@]} ) + [[ ! "$OPT_B" == "" ]] && IGNORE_TABLES=( ${IGNORE_TABLES[@]} $OPT_B ) + for TABLE in "${IGNORE_TABLES[@]}"; do + IGNORE_STRING="$IGNORE_STRING --ignore-table=$DBNAME.$TABLE_PREFIX$TABLE" + done + fi + + # We use --single-transaction in favour of --lock-tables=false , its slower, but less potential for unreliable dumps + echo "SET SESSION sql_mode='NO_AUTO_VALUE_ON_ZERO';" + ( mysqldump -p"$DBPASS" $MYSQL_ARGS --no-data --routines --triggers --single-transaction; \ + mysqldump -p"$DBPASS" $MYSQL_ARGS $IGNORE_STRING --no-create-db --single-transaction ) | sed 's/DEFINER=[^*]*\*/\*/g' +} + +function question() +{ + [[ ! "$OPT_F" == "" ]] && return 0 + echo -n "$1 [y/N]: " + read CONFIRM + [[ "$CONFIRM" == "y" ]] || [[ "$CONFIRM" == "Y" ]] && return 0 + return 1 +} + +function message() +{ + STRIP=$(for i in {1..38}; do echo -n "#"; done) + echo -e "$STRIP\n$1\n$STRIP" +} + +function banner() +{ +cat </dev/null 2>&1 +[ $? -eq 0 ] && TMP_FILE=$(mktemp ./var/local.xml.XXXXX) || TMP_FILE="./var/.tmp.local.xml" +sed -ne '/default_setup/,/\/default_setup/p' $CONFIG_FILE > $TMP_FILE + +which pigz >/dev/null 2>&1 +[ $? -eq 0 ] && GZIP_CMD="pigz" || GZIP_CMD="gzip" + +IGNORE_STRING="" +DBHOST=$(getParam "host") +DBUSER=$(getParam "username") +DBPASS=$(getParam "password" "sanitise" ) +DBNAME=$(getParam "dbname") +TABLE_PREFIX=$(getParam "table_prefix") +[ -f $TMP_FILE ] && rm $TMP_FILE +[[ ! "$OPT_z" == "" ]] && DUMP_FILE="$DUMP_FILE"".gz" + +MYSQL_ARGS="-f -h $DBHOST -u $DBUSER $DBNAME" +[[ ! "$OPT_e" == "" ]] && MYSQL_ARGS="$MYSQL_ARGS --extended-insert=FALSE --complete-insert=TRUE" + +if [[ ! "$OPT_r" == "" ]]; then + + [ ! -f "$DUMP_FILE" ] && error "SQL file does not exist" + question "Are you sure you want to restore $DUMP_FILE to $DBNAME?" + if [ $? -eq 0 ]; then + [[ ! "$OPT_z" == "" ]] && $GZIP_CMD -d <$DUMP_FILE | mysql $MYSQL_ARGS -p"$DBPASS" || mysql $MYSQL_ARGS -p"$DBPASS" <$DUMP_FILE + message "MYSQL IMPORT COMPLETE" + banner + fi + exit 0 + +elif [[ ! "$OPT_c" == "" ]]; then + + for TABLE in ${TRUNCATE_TABLES[@]}; do + echo "Cleaning $TABLE ..." + mysql $MYSQL_ARGS -p"$DBPASS" -e "TRUNCATE ${TABLE_PREFIX}$TABLE" + done + +elif [[ ! "$OPT_i" == "" ]]; then + + mysql $MYSQL_ARGS -p"$DBPASS" + +elif [[ ! "$OPT_d" == "" ]]; then + + [[ ! "$OPT_z" == "" ]] && mysqldumpit | $GZIP_CMD > $DUMP_FILE || mysqldumpit > $DUMP_FILE + message "MYSQL DUMP COMPLETE" + exit 0 + +fi diff --git a/mysql/my.cnf b/mysql/my.cnf new file mode 100644 index 0000000..e94c1c5 --- /dev/null +++ b/mysql/my.cnf @@ -0,0 +1,28 @@ +[client] +port = 3306 +socket = /var/run/mysqld/mysqld.sock + +[mysqld_safe] +pid-file = /var/run/mysqld/mysqld.pid +socket = /var/run/mysqld/mysqld.sock +nice = 0 + +[mysqld] +skip-host-cache +skip-name-resolve +user = mysql +pid-file = /var/run/mysqld/mysqld.pid +socket = /var/run/mysqld/mysqld.sock +port = 3306 +basedir = /usr +datadir = /var/lib/mysql +tmpdir = /tmp +lc-messages-dir = /usr/share/mysql +explicit_defaults_for_timestamp +max_allowed_packet = 1024M + +log-error = /var/log/mysql/error.log + +symbolic-links=0 + +!includedir /etc/mysql/conf.d/ \ No newline at end of file diff --git a/nginx/default.cnf b/nginx/default.cnf index ae4a5a3..126b9a8 100644 --- a/nginx/default.cnf +++ b/nginx/default.cnf @@ -1,7 +1,7 @@ server { listen 80 default_server; root /var/www/html; - index index.html index.php; + index index.php; charset utf-8; diff --git a/php/Dockerfile b/php/Dockerfile index dd05f2e..8ad25d0 100644 --- a/php/Dockerfile +++ b/php/Dockerfile @@ -1,3 +1,23 @@ -FROM php:7.0-fpm +FROM php:5.6-fpm -RUN docker-php-ext-install pdo_mysql \ No newline at end of file +# Install required php extensions +RUN apt-get update -y && apt-get install -y php5-mysql php5-gd php5-curl php5-mcrypt + +# Install composer +RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \ + php -r "if (hash_file('SHA384', 'composer-setup.php') === '92102166af5abdb03f49ce52a40591073a7b859a86e8ff13338cf7db58a19f7844fbc0bb79b2773bf30791e935dbd938') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \ + php composer-setup.php --install-dir=/usr/bin --filename=composer && \ + php -r "unlink('composer-setup.php');" + +# Install magerun +RUN apt-get install -y wget && \ + wget https://files.magerun.net/n98-magerun.phar && \ + apt-get purge -y wget && \ + mv n98-magerun.phar /usr/bin/ && \ + echo 'alias magerun="php -f /usr/bin/n98-magerun.phar --"' >> /root/.bashrc + +# Install Accolade Magerun Tools +RUN apt-get install -y git && \ +mkdir -p /usr/local/share/n98-magerun/modules && \ +cd /usr/local/share/n98-magerun/modules && \ +git clone https://github.com/Accolades/MagerunTools.git \ No newline at end of file