From 75537dae0a1c72baf780e8a400343b8fdaa1057e Mon Sep 17 00:00:00 2001 From: pierreozoux <pierre@ozoux.net> Date: Wed, 18 Feb 2015 17:25:44 +0000 Subject: [PATCH] Adds owncloud \o/ closes #7 --- dockerfiles/services/owncloud/Dockerfile | 30 +++++ .../services/owncloud/nginx-owncloud.conf | 57 +++++++++ .../services/owncloud/startup-owncloud.sh | 114 ++++++++++++++++++ scripts/provision.sh | 11 +- 4 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 dockerfiles/services/owncloud/Dockerfile create mode 100644 dockerfiles/services/owncloud/nginx-owncloud.conf create mode 100644 dockerfiles/services/owncloud/startup-owncloud.sh diff --git a/dockerfiles/services/owncloud/Dockerfile b/dockerfiles/services/owncloud/Dockerfile new file mode 100644 index 0000000..cad3da9 --- /dev/null +++ b/dockerfiles/services/owncloud/Dockerfile @@ -0,0 +1,30 @@ +FROM pierreozoux/nginx-php + +# install owncloud +RUN echo 'deb http://download.opensuse.org/repositories/isv:/ownCloud:/community/Debian_7.0/ /' >> /etc/apt/sources.list.d/owncloud.list && \ + curl -L http://download.opensuse.org/repositories/isv:ownCloud:community/Debian_7.0/Release.key | apt-key add - && \ + apt-get update && apt-get install -y \ + owncloud \ + php5-imap \ + sendmail && \ + apt-get install -y --no-install-recommends \ + libreoffice && \ + rm -rf /var/lib/apt/lists/* && \ + php5enmod imap && \ + mv /var/www/owncloud/apps /owncloud-apps && \ + sed -i 's/^post_max_size =.*/post_max_size = 0/g' /etc/php5/fpm/php.ini && \ + sed -i 's/^upload_max_filesize =.*/upload_max_filesize = 25G/g' /etc/php5/fpm/php.ini && \ + sed -i 's/^max_file_uploads =.*/max_file_uploads = 100/g' /etc/php5/fpm/php.ini && \ + sed -i 's/# exec CMD/# exec CMD\n\/opt\/startup-owncloud.sh/g' /opt/entrypoint.sh + +# install nginx owncloud config +ADD nginx-owncloud.conf /etc/nginx/conf.d/nginx-owncloud.conf + +# add startup.sh +ADD startup-owncloud.sh /opt/startup-owncloud.sh +RUN chmod a+x /opt/startup-owncloud.sh + +# Expose environment variables +ENV DB_NAME owncloud +ENV DB_USER admin + diff --git a/dockerfiles/services/owncloud/nginx-owncloud.conf b/dockerfiles/services/owncloud/nginx-owncloud.conf new file mode 100644 index 0000000..eab7b5c --- /dev/null +++ b/dockerfiles/services/owncloud/nginx-owncloud.conf @@ -0,0 +1,57 @@ +server { + listen 80; + + root /var/www/owncloud; + index index.php index.html index.htm; + + client_max_body_size 0; # 0=unlimited - set max upload size + fastcgi_buffers 64 4K; + + rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect; + rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect; + rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect; + + index index.php; + error_page 403 /core/templates/403.php; + error_page 404 /core/templates/404.php; + + location = /robots.txt { + allow all; + log_not_found off; + access_log off; + } + + location ~ ^/(data|config|\.ht|db_structure\.xml|README) { + deny all; + } + + location / { + # The following 2 rules are only needed with webfinger + rewrite ^/.well-known/host-meta /public.php?service=host-meta last; + rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last; + + rewrite ^/.well-known/carddav /remote.php/carddav/ redirect; + rewrite ^/.well-known/caldav /remote.php/caldav/ redirect; + + rewrite ^(/core/doc/[^\/]+/)$ $1/index.html; + + try_files $uri $uri/ index.php; + } + + location ~ ^(.+?\.php)(/.*)?$ { + try_files $1 =404; + + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$1; + fastcgi_param PATH_INFO $2; + fastcgi_param HTTPS on; + fastcgi_pass unix:/var/run/php5-fpm.sock; + } + + # Optional: set long EXPIRES header on static assets + location ~* ^.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ { + expires 30d; + # Optional: Don't log access to assets + access_log off; + } +} diff --git a/dockerfiles/services/owncloud/startup-owncloud.sh b/dockerfiles/services/owncloud/startup-owncloud.sh new file mode 100644 index 0000000..4f52210 --- /dev/null +++ b/dockerfiles/services/owncloud/startup-owncloud.sh @@ -0,0 +1,114 @@ +#!/bin/bash -eux +### +# Check Pre Install +### + +if [ -f /var/www/owncloud/config/config.php ] +then + echo ">> owncloud already configured - skipping initialization" + exit 0 +fi + +if [ ! -z ${OWNCLOUD_DO_NOT_INITIALIZE+x} ] +then + echo ">> OWNCLOUD_DO_NOT_INITIALIZE set - skipping initialization" + exit 0 +fi + +source /etc/environment + +### +# Variables +### + +if [ -z ${OWNCLOUD_IMAP_HOST+x} ] +then + OWNCLOUD_IMAP_HOST=mail +fi + +if [ -z ${DB_PORT+x} ] +then + DB_PORT=3306 +fi + +if [ -z ${DB_NAME+x} ] +then + DB_NAME=owncloud +fi + +if [ -z ${EMAIL+x} ] +then + EMAIL="admin" + echo ">> owncloud admin user: $EMAIL" +fi + +if [ -z ${ADMIN_PASSWORD+x} ] +then + ADMIN_PASSWORD=`perl -e 'my @chars = ("A".."Z", "a".."z"); my $string; $string .= $chars[rand @chars] for 1..10; print $string;'` + echo ">> generated owncloud admin password: $ADMIN_PASSWORD" +fi + +### +# Pre Install +### + +if [ ! -z ${OWNCLOUD_HSTS_HEADERS_ENABLE+x} ] +then + echo ">> HSTS Headers enabled" + sed -i 's/#add_header Strict-Transport-Security/add_header Strict-Transport-Security/g' /etc/nginx/conf.d/nginx-owncloud.conf + + if [ ! -z ${OWNCLOUD_HSTS_HEADERS_ENABLE_NO_SUBDOMAINS+x} ] + then + echo ">> HSTS Headers configured without includeSubdomains" + sed -i 's/; includeSubdomains//g' /etc/nginx/conf.d/nginx-owncloud.conf + fi +else + echo ">> HSTS Headers disabled" +fi + +### +# Headless initialization +### +echo ">> copy apps into apps folder." +cp -R /owncloud-apps/* /var/www/owncloud/apps/ + +echo ">>Setting Permissions:" +ocpath='/var/www/owncloud' +htuser='www-data' + +chown -R root:${htuser} ${ocpath}/ +chown -R ${htuser}:${htuser} ${ocpath}/apps/ +chown -R ${htuser}:${htuser} ${ocpath}/config/ +chown -R ${htuser}:${htuser} ${ocpath}/data/ + +echo ">> initialization" +echo ">> starting nginx to configure owncloud" +sleep 1 +nginx > /tmp/nginx.log 2> /tmp/nginx.log & +sleep 1 + +## Create OwnCloud Installation +echo ">> init owncloud installation" +DATA_DIR=/var/www/owncloud/data + +/opt/mysql-check.sh + +if [ -z ${DB_USER+x} ] || [ -z ${DB_PASS+x} ] +then + echo "We need user and password for database" + exit 1 +else + echo ">> using mysql DB" + DB_TYPE="mysql" + POST=`echo "install=true&adminlogin=$EMAIL&adminpass=$ADMIN_PASSWORD&adminpass-clone=$ADMIN_PASSWORD&directory=$DATA_DIR&dbtype=$DB_TYPE&dbuser=$DB_USER&dbpass=$DB_PASS&dbpass-clone=$DB_PASS&dbname=$DB_NAME&dbhost=$DB_HOST:$DB_PORT"` +fi + +echo ">> using curl to post data to owncloud" +echo "POST = $POST" +curl -d "$POST" http://${URL}/index.php + +echo ">> killing nginx - done with configuration" +sleep 1 +killall nginx +echo ">> finished initialization" + diff --git a/scripts/provision.sh b/scripts/provision.sh index c97565c..9d7c216 100755 --- a/scripts/provision.sh +++ b/scripts/provision.sh @@ -77,7 +77,7 @@ function call_API () { } function scaffold () { - supported_applications=( "static" "wordpress" "known" ) + supported_applications=( "static" "wordpress" "known" "owncloud") if [ $(contains "${supported_applications[@]}" "${arg_a}") == "n" ]; then error "Application ${arg_a} is not yet supported." exit 1 @@ -107,6 +107,15 @@ function scaffold () { -v ${APP_FODLER}/.htaccess:/app/.htaccess \ --env-file ${APP_FODLER}/.env" >> ${FOLDER}/.env ;; + "owncloud" ) + echo APPLICATION=${arg_a} >> ${FOLDER}/.env + echo DOCKER_ARGUMENTS="--link mysql-${arg_u}:db \ + -v ${APP_FODLER}/apps:/app/apps \ + -v ${APP_FODLER}/config:/app/config \ + -v ${APP_FODLER}/data:/app/data \ + --env-file ${APP_FODLER}/.env" >> ${FOLDER}/.env + ;; + esac info "Scaffold created with success." -- GitLab