Skip to content

Commit

Permalink
nginx for the win (fixes #25) (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
empeje authored and dogi committed Dec 23, 2017
1 parent c63551c commit ac74d26
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 59 deletions.
35 changes: 25 additions & 10 deletions 3.4/arm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
FROM arm32v7/ubuntu
FROM arm32v7/debian:stretch-slim
LABEL MAINTAINER "Dashlorde <[email protected]>"
LABEL MAINTAINER "Abdurrachman Mappuji <[email protected]>"
LABEL MAINTAINER "dogi <[email protected]>"

ENV version '3.4.0'

EXPOSE 80

ADD ./start.sh /etc/apache2/start.sh
ADD ./start.sh /etc/nginx/
COPY ./moodle /etc/nginx/sites-available/moodle

RUN apt-get update && \
apt-get -y install wget unzip apache2 php libapache2-mod-php7.0 php-xml php-zip \
php7.0-pgsql php7.0-curl php7.0-xmlrpc php7.0-gd php7.0-intl php7.0-mysql
apt-get -y install \
nginx php-fpm php-common \
php-mbstring php-xmlrpc \
php-soap php-gd php-xml \
php-intl php-pgsql php-mysqlnd php-cli \
php-mcrypt php-ldap php-zip php-curl \
wget && \
apt-get -y autoclean && \
apt-get -y autoremove && \
rm -rf /var/lib/apt/lists/*

RUN wget -O /var/www/moodle-${version}.tar.gz https://github.com/moodle/moodle/archive/v${version}.tar.gz && \
RUN mkdir -p /var/www/html && \
wget -O /var/www/moodle-${version}.tar.gz \
https://github.com/moodle/moodle/archive/v${version}.tar.gz && \
rm -rf /var/www/html/ && \
cd /var/www && tar xvf moodle-${version}.tar.gz && \
rm moodle-${version}.tar.gz && \
mv /var/www/moodle-${version} /var/www/html && \
rm moodle-${version}.tar.gz && \
chown -R www-data:www-data /var/www/html && \
chmod +x /etc/apache2/start.sh &&\
chmod +x /etc/nginx/start.sh && \
mkdir -p /var/www/moodledata && chmod 777 /var/www/moodledata && \
chown -R www-data:www-data /var/www/moodledata
chown -R www-data:www-data /var/www/moodledata && \
ln -s /etc/nginx/sites-available/moodle /etc/nginx/sites-enabled/ && \
unlink /etc/nginx/sites-enabled/default

COPY ./config.php /var/www/html/
ADD ./config.php /var/www/html/

CMD ["/etc/apache2/start.sh"]
CMD ["/etc/nginx/start.sh"]
2 changes: 1 addition & 1 deletion 3.4/arm/build.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker build . -t treehouses/moodle:rpi-pgsql
docker build . -t treehouses/moodle:rpi-latest
6 changes: 2 additions & 4 deletions 3.4/arm/docker-compose-ready.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ services:
container_name: moodle_rpi
ports:
- "80:80"
volumes:
- /home/pi/apache2:/var/run/apache2
environment:
- MOODOLE_DB_URL=moodledb_rpi
- MOODOLE_DB_NAME=moodle
- MOODOLE_DB_USER=moodle
- MOODOLE_DB_PASS=moodle
- MOODOLE_DB_PORT=5432
- MOODOLE_POST_MAX_SIZE=200M
- MOODOLE_UPLOAD_MAX_FILESIZE=200M
- MOODOLE_MAX_BODY_SIZE=200M
- MOODOLE_BODY_TIMEOUT=300s
6 changes: 2 additions & 4 deletions 3.4/arm/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ services:
container_name: moodle_rpi
ports:
- "80:80"
volumes:
- /home/pi/apache2:/var/run/apache2
environment:
- MOODOLE_DB_URL=moodledb_rpi
- MOODOLE_DB_NAME=moodle
- MOODOLE_DB_USER=moodle
- MOODOLE_DB_PASS=moodle
- MOODOLE_DB_PORT=5432
- MOODOLE_POST_MAX_SIZE=200M
- MOODOLE_UPLOAD_MAX_FILESIZE=200M
- MOODOLE_MAX_BODY_SIZE=200M
- MOODOLE_BODY_TIMEOUT=300s
28 changes: 28 additions & 0 deletions 3.4/arm/moodle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
server {
listen 80;
listen [::]:80;
root /var/www/html;
index index.php index.html index.htm;
server_name _;
client_max_body_size 200M;
client_body_timeout 300s;

location / {
try_files $uri $uri/ =404;
}

location /dataroot/ {
internal;
alias /var/www/html/moodledata/;
}

location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

}
47 changes: 41 additions & 6 deletions 3.4/arm/start.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
#!bin/bash

source /etc/apache2/envvars
# populate environment first

if [ ! -z "${MOODOLE_POST_MAX_SIZE}" ]
# /etc/nginx/sites-available/moodle
NGINX_CONFIG="/etc/nginx/sites-available/moodle"

if [ ! -z "${MOODOLE_MAX_BODY_SIZE}" ]
then
sed -i '/client_max_body_size/c\\tclient_max_body_size '$MOODOLE_MAX_BODY_SIZE';' $NGINX_CONFIG
fi

if [ ! -z "${MOODOLE_BODY_TIMEOUT}" ]
then
sed -i '/client_body_timeout/c\\tclient_body_timeout '$MOODOLE_BODY_TIMEOUT';' $NGINX_CONFIG
fi

# /etc/php/7.0/fpm/php-fpm.conf
PHP_FM_CONFIG="/etc/php/7.0/fpm/php-fpm.conf"
echo "[www]" >> $PHP_FM_CONFIG

if [ ! -z "${MOODOLE_DB_URL}" ]
then
echo "env[MOODOLE_DB_URL] = '$MOODOLE_DB_URL'" >> $PHP_FM_CONFIG
fi

if [ ! -z "${MOODOLE_DB_NAME}" ]
then
echo "env[MOODOLE_DB_NAME] = '$MOODOLE_DB_NAME'" >> $PHP_FM_CONFIG
fi

if [ ! -z "${MOODOLE_DB_USER}" ]
then
sed -i '/post_max_size/c\post_max_size = '$MOODOLE_POST_MAX_SIZE /etc/php/7.0/apache2/php.ini
echo "env[MOODOLE_DB_USER] = '$MOODOLE_DB_USER'" >> $PHP_FM_CONFIG
fi

if [ ! -z "${MOODOLE_UPLOAD_MAX_FILESIZE}" ]
if [ ! -z "${MOODOLE_DB_PASS}" ]
then
sed -i '/upload_max_filesize/c\upload_max_filesize = '$MOODOLE_UPLOAD_MAX_FILESIZE /etc/php/7.0/apache2/php.ini
echo "env[MOODOLE_DB_PASS] = '$MOODOLE_DB_PASS'" >> $PHP_FM_CONFIG
fi

exec apache2 -D FOREGROUND
if [ ! -z "${MOODOLE_DB_PORT}" ]
then
echo "env[MOODOLE_DB_PORT] = '$MOODOLE_DB_PORT'" >> $PHP_FM_CONFIG
fi

service php7.0-fpm start
service nginx start

tail -f /var/log/nginx/access.log
33 changes: 24 additions & 9 deletions 3.4/x86/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
FROM i386/ubuntu:16.04
FROM debian:stretch-slim
LABEL MAINTAINER "Dashlorde <[email protected]>"
LABEL MAINTAINER "Abdurrachman Mappuji <[email protected]>"
LABEL MAINTAINER "dogi <[email protected]>"

ENV version '3.4.0'

EXPOSE 80

ADD ./start.sh /etc/apache2/start.sh
ADD ./start.sh /etc/nginx/
COPY ./moodle /etc/nginx/sites-available/moodle

RUN apt-get update && \
apt-get -y install wget unzip apache2 php libapache2-mod-php7.0 php-xml php-zip \
php7.0-mysql php7.0-curl php7.0-xmlrpc php7.0-gd php7.0-intl php7.0-pgsql
apt-get -y install \
nginx php-fpm php-common \
php-mbstring php-xmlrpc \
php-soap php-gd php-xml \
php-intl php-pgsql php-mysqlnd php-cli \
php-mcrypt php-ldap php-zip php-curl \
wget && \
apt-get -y autoclean && \
apt-get -y autoremove && \
rm -rf /var/lib/apt/lists/*

RUN wget -O /var/www/moodle-${version}.tar.gz https://github.com/moodle/moodle/archive/v${version}.tar.gz && \
RUN mkdir -p /var/www/html && \
wget -O /var/www/moodle-${version}.tar.gz \
https://github.com/moodle/moodle/archive/v${version}.tar.gz && \
rm -rf /var/www/html/ && \
cd /var/www && tar xvf moodle-${version}.tar.gz && \
mv /var/www/moodle-${version} /var/www/html && \
rm moodle-${version}.tar.gz && \
chown -R www-data:www-data /var/www/html && \
chmod +x /etc/apache2/start.sh && \
chmod +x /etc/nginx/start.sh && \
mkdir -p /var/www/moodledata && chmod 777 /var/www/moodledata && \
chown -R www-data:www-data /var/www/moodledata
chown -R www-data:www-data /var/www/moodledata && \
ln -s /etc/nginx/sites-available/moodle /etc/nginx/sites-enabled/ && \
unlink /etc/nginx/sites-enabled/default

COPY ./config.php /var/www/html/
ADD ./config.php /var/www/html/

CMD ["/etc/apache2/start.sh"]
CMD ["/etc/nginx/start.sh"]
2 changes: 1 addition & 1 deletion 3.4/x86/build.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker build . -t treehouses/moodle:x86-pgsql
docker build . -t treehouses/moodle:latest
6 changes: 2 additions & 4 deletions 3.4/x86/docker-compose-ready.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ services:
container_name: moodle
ports:
- "80:80"
volumes:
- /home/pi/apache2:/var/run/apache2
environment:
- MOODOLE_DB_URL=moodledb
- MOODOLE_DB_NAME=moodle
- MOODOLE_DB_USER=moodle
- MOODOLE_DB_PASS=moodle
- MOODOLE_DB_PORT=5432
- MOODOLE_POST_MAX_SIZE=200M
- MOODOLE_UPLOAD_MAX_FILESIZE=200M
- MOODOLE_MAX_BODY_SIZE=200M
- MOODOLE_BODY_TIMEOUT=300s
6 changes: 2 additions & 4 deletions 3.4/x86/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ services:
container_name: moodle
ports:
- "80:80"
volumes:
- /home/pi/apache2:/var/run/apache2
environment:
- MOODOLE_DB_URL=moodledb
- MOODOLE_DB_NAME=moodle
- MOODOLE_DB_USER=moodle
- MOODOLE_DB_PASS=moodle
- MOODOLE_DB_PORT=5432
- MOODOLE_POST_MAX_SIZE=200M
- MOODOLE_UPLOAD_MAX_FILESIZE=200M
- MOODOLE_MAX_BODY_SIZE=200M
- MOODOLE_BODY_TIMEOUT=300s
28 changes: 28 additions & 0 deletions 3.4/x86/moodle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
server {
listen 80;
listen [::]:80;
root /var/www/html;
index index.php index.html index.htm;
server_name _;
client_max_body_size 200M;
client_body_timeout 300s;

location / {
try_files $uri $uri/ =404;
}

location /dataroot/ {
internal;
alias /var/www/html/moodledata/;
}

location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

}
47 changes: 41 additions & 6 deletions 3.4/x86/start.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
#!bin/bash

source /etc/apache2/envvars
# populate environment first

if [ ! -z "${MOODOLE_POST_MAX_SIZE}" ]
# /etc/nginx/sites-available/moodle
NGINX_CONFIG="/etc/nginx/sites-available/moodle"

if [ ! -z "${MOODOLE_MAX_BODY_SIZE}" ]
then
sed -i '/client_max_body_size/c\\tclient_max_body_size '$MOODOLE_MAX_BODY_SIZE';' $NGINX_CONFIG
fi

if [ ! -z "${MOODOLE_BODY_TIMEOUT}" ]
then
sed -i '/client_body_timeout/c\\tclient_body_timeout '$MOODOLE_BODY_TIMEOUT';' $NGINX_CONFIG
fi

# /etc/php/7.0/fpm/php-fpm.conf
PHP_FM_CONFIG="/etc/php/7.0/fpm/php-fpm.conf"
echo "[www]" >> $PHP_FM_CONFIG

if [ ! -z "${MOODOLE_DB_URL}" ]
then
echo "env[MOODOLE_DB_URL] = '$MOODOLE_DB_URL'" >> $PHP_FM_CONFIG
fi

if [ ! -z "${MOODOLE_DB_NAME}" ]
then
echo "env[MOODOLE_DB_NAME] = '$MOODOLE_DB_NAME'" >> $PHP_FM_CONFIG
fi

if [ ! -z "${MOODOLE_DB_USER}" ]
then
sed -i '/post_max_size/c\post_max_size = '$MOODOLE_POST_MAX_SIZE /etc/php/7.0/apache2/php.ini
echo "env[MOODOLE_DB_USER] = '$MOODOLE_DB_USER'" >> $PHP_FM_CONFIG
fi

if [ ! -z "${MOODOLE_UPLOAD_MAX_FILESIZE}" ]
if [ ! -z "${MOODOLE_DB_PASS}" ]
then
sed -i '/upload_max_filesize/c\upload_max_filesize = '$MOODOLE_UPLOAD_MAX_FILESIZE /etc/php/7.0/apache2/php.ini
echo "env[MOODOLE_DB_PASS] = '$MOODOLE_DB_PASS'" >> $PHP_FM_CONFIG
fi

exec apache2 -D FOREGROUND
if [ ! -z "${MOODOLE_DB_PORT}" ]
then
echo "env[MOODOLE_DB_PORT] = '$MOODOLE_DB_PORT'" >> $PHP_FM_CONFIG
fi

service php7.0-fpm start
service nginx start

tail -f /var/log/nginx/access.log
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@ services:
- POSTGRES_USER=moodle
- POSTGRES_PASSWORD=moodle
moodle:
image: treehouses/moodle:latest
build: .
container_name: moodle
ports:
- "80:80"
volumes:
- /home/pi/apache2:/var/run/apache2
environment:
- MOODOLE_DB_URL=moodledb
- MOODOLE_DB_NAME=moodle
- MOODOLE_DB_USER=moodle
- MOODOLE_DB_PASS=moodle
- MOODOLE_DB_PORT=5432
- MOODOLE_POST_MAX_SIZE=200M
- MOODOLE_UPLOAD_MAX_FILESIZE=200M
- MOODOLE_MAX_BODY_SIZE=300M
- MOODOLE_BODY_TIMEOUT=700s
```

---
Expand All @@ -58,14 +56,13 @@ services:
container_name: moodle_rpi
ports:
- "80:80"
volumes:
- /home/pi/apache2:/var/run/apache2
environment:
- MOODOLE_DB_URL=moodledb_rpi
- MOODOLE_DB_NAME=moodle
- MOODOLE_DB_USER=moodle
- MOODOLE_DB_PASS=moodle
- MOODOLE_DB_PORT=5432
- MOODOLE_POST_MAX_SIZE=200M
- MOODOLE_UPLOAD_MAX_FILESIZE=200M
- MOODOLE_MAX_BODY_SIZE=200M
- MOODOLE_BODY_TIMEOUT=300s
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moodole",
"version": "0.0.1",
"version": "0.0.2",
"description": "Moodle Docker for x86 and Raspberry Pi",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down

0 comments on commit ac74d26

Please sign in to comment.