From 867833d715d92974e989abb4fcdf0f67b90bf025 Mon Sep 17 00:00:00 2001 From: pierreozoux <pierre@ozoux.net> Date: Wed, 18 Feb 2015 20:15:42 +0000 Subject: [PATCH] Adds piwik \o/, closes #8 --- dockerfiles/services/piwik/Dockerfile | 24 ++ dockerfiles/services/piwik/nginx-piwik.conf | 51 +++++ dockerfiles/services/piwik/startup-piwik.sh | 237 ++++++++++++++++++++ scripts/provision.sh | 9 +- 4 files changed, 320 insertions(+), 1 deletion(-) create mode 100644 dockerfiles/services/piwik/Dockerfile create mode 100644 dockerfiles/services/piwik/nginx-piwik.conf create mode 100644 dockerfiles/services/piwik/startup-piwik.sh diff --git a/dockerfiles/services/piwik/Dockerfile b/dockerfiles/services/piwik/Dockerfile new file mode 100644 index 0000000..c967a46 --- /dev/null +++ b/dockerfiles/services/piwik/Dockerfile @@ -0,0 +1,24 @@ +FROM pierreozoux/nginx-php + +RUN apt-get update && apt-get install -y \ + php5-gd \ + php5-geoip \ + php-apc && \ + rm -rf /var/lib/apt/lists/* && \ + curl "http://builds.piwik.org/piwik-latest.tar.gz" | tar xz && \ + mv /piwik/config /piwik-config && \ + sed -i 's/# exec CMD/# exec CMD\n\/opt\/startup-piwik.sh/g' /opt/entrypoint.sh + +# install nginx piwik config +ADD nginx-piwik.conf /etc/nginx/conf.d/nginx-piwik.conf + +# add startup.sh +ADD startup-piwik.sh /opt/startup-piwik.sh +RUN chmod a+x /opt/startup-piwik.sh + +# Expose environment variables +ENV DB_NAME piwik +ENV DB_USER admin + +VOLUME "/piwik/config/" + diff --git a/dockerfiles/services/piwik/nginx-piwik.conf b/dockerfiles/services/piwik/nginx-piwik.conf new file mode 100644 index 0000000..37aece9 --- /dev/null +++ b/dockerfiles/services/piwik/nginx-piwik.conf @@ -0,0 +1,51 @@ +server { + listen 80; + + root /usr/share/nginx/html; + index index.php index.html index.htm; + + location / { + try_files $uri $uri/ =404; + } + + error_page 404 /404.html; + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass unix:/var/run/php5-fpm.sock; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } +} + +server { + listen 80; + + root /usr/share/nginx/html; + index index.php index.html index.htm; + + location / { + try_files $uri $uri/ =404; + } + + error_page 404 /404.html; + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass unix:/var/run/php5-fpm.sock; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } +} diff --git a/dockerfiles/services/piwik/startup-piwik.sh b/dockerfiles/services/piwik/startup-piwik.sh new file mode 100644 index 0000000..4decf3a --- /dev/null +++ b/dockerfiles/services/piwik/startup-piwik.sh @@ -0,0 +1,237 @@ +#!/bin/bash -eux + +source /etc/environment + +echo ">> adding softlink from /piwik to /" +rm -rf /usr/share/nginx/html +ln -s /piwik /usr/share/nginx/html +mkdir /usr/share/nginx/html/tmp + +chown -R www-data:www-data /usr/share/nginx/html/ +chmod -R 755 /usr/share/nginx/html/tmp + +if [ -z ${DB_PASS+x} ] || [ -z ${DB_USER+x} ] +then + echo ">> piwik started, initial setup needs to be done in browser!" + echo ">> be fast! - anyone with access to your server can configure it!" + exit 0 +fi + +echo +echo ">> #####################" +echo ">> init piwik" +echo ">> #####################" +echo + +nginx 2> /tmp/nginx.log > /tmp/nginx.log & + +/opt/mysql-check.sh + +if [ `echo "SHOW TABLES FROM $DB_NAME;" | mysql -h $DB_HOST -P $DB_PORT -u $DB_USER -p$DB_PASS | grep "piwik_" | wc -l` -lt 1 ] +then + echo ">> no DB installed, MYSQL User or Password specified - seems like the first start" + + #cat /config.ini.php | sed "s/PIWIK_MYSQL_PORT/$DB_PORT/g" | sed "s/PIWIK_MYSQL_USER/$DB_USER/g" | sed "s/PIWIK_MYSQL_PASSWORD/$DB_PASS/g" | sed "s/PIWIK_MYSQL_DBNAME/$DB_NAME/g" > /piwik/config/config.ini.php + + cp -R /piwik-config/* /piwik/config/ + chown -R www-data:www-data /usr/share/nginx/html/ + + echo ">> init Piwik" + if [ -z ${EMAIL+x} ] + then + PIWIK_ADMIN="admin" + echo ">> piwik admin user: $EMAIL" + fi + + if [ -z ${PIWIK_ADMIN_PASSWORD+x} ] + then + PIWIK_ADMIN_PASSWORD=`perl -e 'my @chars = ("A".."Z", "a".."z"); my $string; $string .= $chars[rand @chars] for 1..10; print $string;'` + echo ">> generated piwik admin password: $PIWIK_ADMIN_PASSWORD" + fi + + if [ -z ${PIWIK_SUBSCRIBE_NEWSLETTER+x} ] + then + PIWIK_SUBSCRIBE_NEWSLETTER=0 + fi + + if [ -z ${PIWIK_SUBSCRIBE_PRO_NEWSLETTER+x} ] + then + PIWIK_SUBSCRIBE_PRO_NEWSLETTER=0 + fi + + if [ -z ${EMAIL+x} ] + then + EMAIL="no@no.tld" + PIWIK_SUBSCRIBE_NEWSLETTER=0 + PIWIK_SUBSCRIBE_PRO_NEWSLETTER=0 + fi + + if [ -z ${SITE_NAME+x} ] + then + SITE_NAME="My local Website" + fi + + if [ -z ${SITE_URL+x} ] + then + SITE_URL="http://${URL}" + fi + + if [ -z ${SITE_TIMEZONE+x} ] + then + SITE_TIMEZONE="Europe/Paris" + fi + + if [ -z ${SITE_ECOMMERCE+x} ] + then + SITE_ECOMMERCE=0 + fi + + if [ -z ${ANONYMISE_IP+x} ] + then + ANONYMISE_IP=1 + fi + + if [ -z ${DO_NOT_TRACK+x} ] + then + DO_NOT_TRACK=1 + fi + + echo ">> piwik wizard: #1 open installer" + + curl "http://${URL}/" \ + -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' --compressed \ + 2> /dev/null | grep " % Done" + + sleep 5 + + echo ">> piwik wizard: #2 open system check" + + curl "http://${URL}/index.php?action=systemCheck&trackerStatus=0" \ + -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://${URL}/' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' --compressed \ + 2> /dev/null | grep " % Done" + + sleep 5 + + echo ">> piwik wizard: #3 open database settings" + + curl "http://${URL}/index.php?action=databaseSetup&trackerStatus=0" \ + -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://${URL}/index.php?action=systemCheck&trackerStatus=0' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' --compressed \ + 2> /dev/null | grep " % Done" + + sleep 5 + + echo ">> piwik wizard: #4 store database settings" + + curl "http://${URL}/index.php?action=databaseSetup&trackerStatus=0" \ + -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Origin: http://${URL}/' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Referer: http://${URL}/index.php?action=databaseSetup&trackerStatus=0' -H 'Connection: keep-alive' --compressed \ + --data-urlencode host="$DB_HOST:$DB_PORT" \ + --data-urlencode username="$DB_USER" \ + --data-urlencode password="$DB_PASS" \ + --data-urlencode dbname="$DB_NAME" \ + --data-urlencode tables_prefix="piwik_" \ + --data 'adapter=PDO%5CMYSQL&submit=Next+%C2%BB' \ + 2> /dev/null + + curl "http://${URL}/index.php?action=tablesCreation&trackerStatus=0&module=Installation" \ + -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://${URL}/index.php?action=databaseSetup&trackerStatus=0' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --compressed \ + 2> /dev/null | grep " % Done" + + sleep 5 + + echo ">> piwik wizard: #5 open piwik settings" + + curl "http://${URL}/index.php?action=setupSuperUser&trackerStatus=0&module=Installation" \ + -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://${URL}/index.php?action=tablesCreation&trackerStatus=0&module=Installation' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' --compressed \ + 2> /dev/null | grep " % Done" + + sleep 5 + + echo ">> piwik wizard: #6 store piwik settings" + + curl "http://${URL}/index.php?action=setupSuperUser&trackerStatus=0&module=Installation" \ + -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Origin: http://${URL}' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Referer: http://${URL}/index.php?action=setupSuperUser&trackerStatus=0&module=Installation' -H 'Connection: keep-alive' --compressed \ + --data-urlencode login="$EMAIL" \ + --data-urlencode password="$PIWIK_ADMIN_PASSWORD" \ + --data-urlencode password_bis="$PIWIK_ADMIN_PASSWORD" \ + --data-urlencode email="$EMAIL" \ + --data-urlencode subscribe_newsletter_piwikorg="$PIWIK_SUBSCRIBE_NEWSLETTER" \ + --data-urlencode subscribe_newsletter_piwikpro="$PIWIK_SUBSCRIBE_PRO_NEWSLETTER" \ + --data 'submit=Next+%C2%BB' \ + 2> /dev/null + + curl "http://${URL}/index.php?action=firstWebsiteSetup&trackerStatus=0&module=Installation" \ + -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://${URL}/index.php?action=setupSuperUser&trackerStatus=0&module=Installation' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --compressed \ + 2> /dev/null | grep " % Done" + + sleep 5 + + echo ">> piwik wizard: #7 store piwik site settings" + + curl "http://${URL}/index.php?action=firstWebsiteSetup&trackerStatus=0&module=Installation" \ + -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Origin: http://${URL}' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Referer: http://${URL}/index.php?action=firstWebsiteSetup&trackerStatus=0&module=Installation' -H 'Connection: keep-alive' --compressed \ + --data-urlencode siteName="$SITE_NAME" \ + --data-urlencode url="$SITE_URL" \ + --data-urlencode timezone="$SITE_TIMEZONE" \ + --data-urlencode ecommerce="$SITE_ECOMMERCE" \ + --data 'submit=Next+%C2%BB' \ + 2> /dev/null + + curl "http://${URL}/index.php?action=trackingCode&trackerStatus=0&module=Installation&site_idSite=1&site_name=default" \ + -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://${URL}/index.php?action=firstWebsiteSetup&trackerStatus=0&module=Installation' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --compressed \ + 2> /dev/null | grep " % Done" + + sleep 5 + + echo ">> piwik wizard: #8 skip js page" + + curl "http://${URL}/index.php?action=finished&trackerStatus=0&module=Installation&site_idSite=1&site_name=default" \ + -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://${URL}/index.php?action=trackingCode&trackerStatus=0&module=Installation&site_idSite=1&site_name=justabot' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' --compressed \ + 2> /dev/null | grep " % Done" + + sleep 5 + + echo ">> piwik wizard: #9 final settings" + + curl "http://${URL}/index.php?action=finished&trackerStatus=0&module=Installation&site_idSite=1&site_name=default" \ + -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Origin: http://${URL}/' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Referer: http://${URL}/index.php?action=finished&trackerStatus=0&module=Installation&site_idSite=1&site_name=justabot' -H 'Connection: keep-alive' --compressed \ + --data-urlencode do_not_track="$DO_NOT_TRACK" \ + --data-urlencode anonymise_ip="$ANONYMISE_IP" \ + --data 'submit=Continue+to+Piwik+%C2%BB' \ + 2> /dev/null + + curl "http://${URL}/index.php" \ + -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://${URL}/index.php?action=finished&trackerStatus=0&module=Installation&site_idSite=1&site_name=justabot' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --compressed \ + 2> /dev/null + + sleep 5 + +fi + +echo ">> update CorePlugins" +curl "http://${URL}/index.php?updateCorePlugins=1" \ + 2> /dev/null + +sleep 2 + +killall nginx + +cat <<EOF +Add the following JS-Code to your Site -> don't forget to change the URLs ;) + +<!-- Piwik --> +<script type="text/javascript"> + var _paq = _paq || []; + _paq.push(['trackPageView']); + _paq.push(['enableLinkTracking']); + (function() { + var u="//!!!YOUR-URL!!!/"; + _paq.push(['setTrackerUrl', u+'piwik.php']); + _paq.push(['setSiteId', 1]); + var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; + g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); + })(); +</script> +<noscript><p><img src="//!!!YOUR-URL!!!/piwik.php?idsite=1" style="border:0;" alt="" /></p></noscript> +<!-- End Piwik Code --> +EOF + diff --git a/scripts/provision.sh b/scripts/provision.sh index 7a35800..96dfb1e 100755 --- a/scripts/provision.sh +++ b/scripts/provision.sh @@ -79,7 +79,7 @@ function call_API () { } function scaffold () { - supported_applications=( "static" "wordpress" "known" "owncloud") + supported_applications=( "static" "wordpress" "known" "owncloud" "piwik") if [ $(contains "${supported_applications[@]}" "${arg_a}") == "n" ]; then error "Application ${arg_a} is not yet supported." exit 1 @@ -117,6 +117,13 @@ function scaffold () { -v ${APP_FOLDER}/data:/var/www/owncloud/data \ --env-file ${APP_FOLDER}/.env" >> ${FOLDER}/.env ;; + "piwik" ) + echo APPLICATION=${arg_a} >> ${FOLDER}/.env + echo DOCKER_ARGUMENTS="--link mysql-${arg_u}:db \ + -v ${APP_FOLDER}/config:/piwik/config \ + --env-file ${APP_FOLDER}/.env" >> ${FOLDER}/.env + ;; + esac -- GitLab