diff --git a/.gitignore b/.gitignore index 763b166..54eebb9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,11 @@ # dotenv environment variables file -construye.sh .env* *.env +# dev tools +construye.sh +docker-compose-dev.yml + # Temporary folders tmp/ temp/ diff --git a/Dockerfile b/Dockerfile index af6b012..c743b02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,22 +9,25 @@ ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && apt-get -y dist-upgrade && apt-get -y install mysql-client pwgen python-setuptools curl git unzip apache2 php php-gd libapache2-mod-php postfix wget supervisor php-pgsql curl libcurl4 libcurl3-dev php-curl php-xmlrpc php-intl php-mysql git-core php-xml php-mbstring php-zip php-soap cron php-ldap vim locales # -RUN cd /tmp && git clone -b MOODLE_39_STABLE git://git.moodle.org/moodle.git --depth=1 && \ + +RUN cd /tmp && git clone -b MOODLE_37_STABLE git://git.moodle.org/moodle.git --depth=1 && \ mv /tmp/moodle/* /var/www/html/ && rm -rf /var/www/html/index.html && \ - chown -R www-data:www-data /var/www/html + chown -R root:www-data /var/www/html && \ + find /var/www/html -type d -exec chmod 750 {} \; && \ + find /var/www/html -type f -exec chmod 640 {} \; + # COPY files/foreground.sh /etc/foreground.sh # COPY files/moodle-php.ini /etc/php/7.2/apache2/conf.d/moodle-php.ini -COPY files/apache-moodle.conf /etc/apache2/conf-available/apache-moodle.conf +COPY files/apache-moodle.conf /etc/apache2/conf-enabled/apache-moodle.conf COPY files/moodlecron /etc/cron.d/moodlecron # RUN chmod 0644 /etc/cron.d/moodlecron ; \ - chmod +x /etc/foreground.sh ; \ + chmod +x /etc/foreground.sh ; \ cd /var/log/apache2/ ; for i in *log; do rm $i; ln -s /dev/stdout $i;done ; \ - a2enconf apache-moodle ; \ echo "TLS_REQCERT never" >> /etc/ldap/ldap.conf # Cleanup, this is ran to reduce the resulting size of the image. @@ -34,4 +37,6 @@ RUN apt-get clean autoclean && apt-get autoremove -y && rm -rf /var/lib/apt/list VOLUME ["/var/moodledata","/var/www/html/theme","/var/www/html/mod"] EXPOSE 80 443 +ENV MOODLE_VER=3.7 + ENTRYPOINT ["/etc/foreground.sh"] diff --git a/README.md b/README.md index 2ef5cb3..0796177 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,17 @@ Moodle is a very popular open source learning management solution (LMS) for the Site: https://moodle.org/ +## Version/TAG: +* 3.7 (3.7_STABLE 3.7.9 build 20220216) +* 3.8 (3.8_STABLE 3.8.9 build 20220216) +* 3.9 (3.9_STABLE 3.9.12 build 20220216) + ## Features -* All configurations can be added from environment variables -* Moodle security recommendations for apache and php -* Check/move admin directory -* Version: 3.7 (STABLE) / 3.8 (STABLE) / 3.9 (STABLE) +- [x] All configurations can be added from environment variables to config.php +- [x] Moodle security recommendations for apache and php +- [x] Check/move admin directory +- [x] Timezone and Language setting from enviroment +- [x] Proxy support and URL setting from enviroment ### Config values All environment variables starting MOODLE_ will be transformed to $CFG and added automatically to the config.php file. Double _ separates array. Example: @@ -25,6 +31,20 @@ All environment variables starting MOODLE_ will be transformed to $CFG and added ### Check/move admin directory If you define MOODLE_admin ($CFG->admin) rename admin directory to MOODLE_admin +In certain circumstances you will want to move the management directory (/admin) to another location (for security or compatibility reasons) +For this you only have to define the environment variable MOODLE_admin with the name with which you want it to be renaming the directory "admin" + +### URL +The VIRTUAL_HOST and VIRTUAL_PORT variables are used with double functionality. + +On the one hand they can be used for the docker with reverse proxy, but they are also used to generate the variable MOODLE_wwwroot ($CFG->wwwroot) together with the environment variable VIRTUAL_URL + +MOODLE_wwwroot = $proto://$VIRTUAL_HOST:$VIRTUAL_PORT$VIRTUAL_URL + +If the variable MOODLE_sslproxy is defined, $proto is https, else http +In this way, you can use VIRTUAL_URL to publish moodle in any URL, something very useful when you are behind a reverse proxy + + ## Deploy ### Docker Composer @@ -33,8 +53,8 @@ If you define MOODLE_admin ($CFG->admin) rename admin directory to MOODLE_admin $ git clone https://github.com/pvrmza/docker-moodle.git $ cd docker-moodle $ cp env_mysql_example .env_mysql - $ cp env_moodle_example .env_observium - $ docker-compose up + $ cp env_moodle_example .env_moodle + $ docker-compose up -d ``` # Volumen diff --git a/docker-compose.yml b/docker-compose.yml index fff3749..23a2a31 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,8 +17,7 @@ services: - db links: - db:db - #image: docker-moodle:200711-1840 - image: pvrmza/docker-moodle + image: pvrmza/docker-moodle:3.9 restart: always env_file: - .env_moodle diff --git a/env_moodle_example b/env_moodle_example index eda08f8..835b5c8 100644 --- a/env_moodle_example +++ b/env_moodle_example @@ -1,31 +1,44 @@ + +# date time & languages TZ=America/Argentina/Mendoza -VIRTUAL_HOST=moodle.local -VIRTUAL_PORT=80 +MOODLE_lang=es -MOODLE_wwwroot=http://localhost:8011 +#### nging proxy reverse and SSL +VIRTUAL_HOST=localhost +VIRTUAL_PORT=8011 +VIRTUAL_URL=/moodle -MOODLE_dbtype=mysqli -MOODLE_dblibrary=native +# If the docker is behind a reverse proxy +# MOODLE_reverseproxy=true +# If the reverse proxy is SSL +# MOODLE_sslproxy=true + +# This is generated when starting the container with the previous variables +# MOODLE_wwwroot=http://$VIRTUAL_HOST:$VIRTUAL_PORT$VIRTUAL_URL + + +# DB Connect +MOODLE_dbtype=mysqli MOODLE_dbhost=db MOODLE_dbname=moodle MOODLE_dbuser=moodle MOODLE_dbpass=moodlepwd@ -MOODLE_prefix=mdl_ +# DB Options +MOODLE_prefix=mdl_ +MOODLE_dblibrary=native MOODLE_dboptions__dbpersist=false MOODLE_dboptions__dbsocket=false MOODLE_dboptions__dbport=3306 MOODLE_dboptions__dbhandlesoptions=false MOODLE_dboptions__dbcollation=utf8mb4_unicode_ci - +# Directory and permission MOODLE_dataroot=/var/moodledata MOODLE_directorypermissions=02777 MOODLE_admin=admin -MOODLE_lang=es - -#MOODLE_reverseproxy=true -#MOODLE_sslproxy=true +# log username in access_log MOODLE_apacheloguser=2 + diff --git a/files/apache-moodle.conf b/files/apache-moodle.conf index 64d7196..a8bbdc3 100644 --- a/files/apache-moodle.conf +++ b/files/apache-moodle.conf @@ -1,5 +1,3 @@ -Alias /moodle /var/www/html - ServerSignature Off ServerTokens Prod TraceEnable off @@ -9,4 +7,4 @@ TraceEnable off Options -Indexes -FollowSymLinks AllowOverride None Require all granted - \ No newline at end of file + diff --git a/files/foreground.sh b/files/foreground.sh index 121965d..f3206bd 100644 --- a/files/foreground.sh +++ b/files/foreground.sh @@ -10,28 +10,58 @@ touch /etc/crontab /etc/cron.d/php /etc/cron.d/moodlecron ####### # timezone -echo $TZ > /etc/timezone && rm /etc/localtime && \ -ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \ -dpkg-reconfigure -f noninteractive tzdata +if test -v TZ && [ `readlink /etc/localtime` != "/usr/share/zoneinfo/$TZ" ]; then + if [ -f /usr/share/zoneinfo/$TZ ]; then + echo $TZ > /etc/timezone + rm /etc/localtime + ln -snf /usr/share/zoneinfo/$TZ /etc/localtime + dpkg-reconfigure -f noninteractive tzdata + echo "date.timezone=$TZ" > /etc/php/7.2/apache2/conf.d/99_datatime.ini + fi +fi ####### -# permission check -echo "placeholder" > /var/moodledata/placeholder -chown -R www-data:www-data /var/moodledata -find /var/moodledata -type d -exec chmod 700 {} \; -find /var/moodledata -type f -exec chmod 600 {} \; +# LANG +if test -v MOODLE_lang; then + if ! test -d /var/www/html/lang/$MOODLE_lang && ! test -d $MOODLE_dataroot/lang/$MOODLE_lang; then + mkdir -p $MOODLE_dataroot/lang && cd $MOODLE_dataroot/lang/ + wget https://download.moodle.org/download.php/direct/langpack/$MOODLE_VER/$MOODLE_lang.zip -q -O /tmp/temp.zip && unzip /tmp/temp.zip && rm -rf /tmp/temp.zip + fi + # check lang package + if [ `dpkg-query -l language-pack-$MOODLE_lang 2>/dev/null | egrep ^ii >/dev/null; echo $?` -eq 1 ]; then + apt-get update + apt-get -y install language-pack-$MOODLE_lang + dpkg-reconfigure locales + fi +fi + +####### +# Building URL +if test -v VIRTUAL_URL; then + # Apache conf + echo -e "\nAlias $VIRTUAL_URL /var/www/html \n" > /etc/apache2/conf-enabled/apache-moodle-url.conf +fi + +if test -v MOODLE_sslproxy; then + proto=https + export VIRTUAL_PORT=443 + export MOODLE_reverseproxy=true +else + proto=http +fi + +if ! test -v MOODLE_wwwroot; then + export MOODLE_wwwroot=$proto://$VIRTUAL_HOST:$VIRTUAL_PORT$VIRTUAL_URL +fi -chown -R root:www-data /var/www/html -find /var/www/html -type d -exec chmod 750 {} \; -find /var/www/html -type f -exec chmod 640 {} \; ####### # check/move admin dir if test -v MOODLE_admin; then - mv /var/www/html/admin /var/www/html/$MOODLE_admin + admin_dir=$(find /var/www/html/ -iname admin_settings_search_form.php | xargs dirname) + mv $admin_dir /var/www/html/$MOODLE_admin 2>/dev/null fi - ####### # ENVIRONMENT to CONFIG rm -rf /var/www/html/config.php @@ -42,7 +72,7 @@ global \$CFG; " > /var/www/html/config.php while IFS= read -r line -do +do key=`echo $line | cut -d = -f 1 |sed "s/MOODLE_//g"` if test $(echo $key | egrep __) ; then var=`echo $key | sed "s/__/['/g" | sed "s/$/']/g" ` @@ -50,7 +80,7 @@ do var=$key fi - value=`echo $line | cut -d = -f 2- ` + value=`echo $line | cut -d = -f 2- |sed 's/\"//g'` case $value in [0-9]*) echo "\$CFG->$var=$value;" ;; true|false) echo "\$CFG->$var=$value;" ;; @@ -58,11 +88,20 @@ do esac done < <(printenv | egrep ^MOODLE_ | sort -u) >> /var/www/html/config.php + echo " require_once(dirname(__FILE__) . '/lib/setup.php'); ?>" >> /var/www/html/config.php +####### +# permission check +echo "Check permissions in $MOODLE_dataroot... " +echo "placeholder" > $MOODLE_dataroot/placeholder +chown -R www-data:www-data $MOODLE_dataroot +find $MOODLE_dataroot -type d -exec chmod 700 {} \; +find $MOODLE_dataroot -type f -exec chmod 600 {} \; + # start up cron /usr/sbin/cron diff --git a/lang_support.md b/lang_support.md new file mode 100644 index 0000000..0bb08f1 --- /dev/null +++ b/lang_support.md @@ -0,0 +1,80 @@ +# List of supported languages +af - translation updates for language Afrikaans +am - translation updates for language Amharic +an - translation updates for language Aragonese +ar - translation updates for language Arabic +as - translation updates for language Assamese +az - translation updates for language Azerbaijani +be - translation updates for language Belarusian +bg - translation updates for language Bulgarian +bn - translation updates for language Bengali +br - translation updates for language Breton +bs - translation updates for language Bosnian +ca - translation updates for language Catalan; Valencian +cs - translation updates for language Czech +cy - translation updates for language Welsh +da - translation updates for language Danish +de - translation updates for language German +dz - translation updates for language Dzongkha +el - translation updates for language Greek, Modern (1453-) +en - translation updates for language English +eo - translation updates for language Esperanto +es - translation updates for language Spanish; Castilian +et - translation updates for language Estonian +eu - translation updates for language Basque +fa - translation updates for language Persian +fi - translation updates for language Finnish +fr - translation updates for language French +ga - translation updates for language Irish +gd - translation updates for language Gaelic; Scottish Gaelic +gl - translation updates for language Galician +gu - translation updates for language Gujarati +he - translation updates for language Hebrew +hi - translation updates for language Hindi +hr - translation updates for language Croatian +hu - translation updates for language Hungarian +ia - translation updates for language Interlingua (International Auxiliary Language Association) +id - translation updates for language Indonesian +is - translation updates for language Icelandic +it - translation updates for language Italian +ja - translation updates for language Japanese +ka - translation updates for language Georgian +kk - translation updates for language Kazakh +km - translation updates for language Central Khmer +kn - translation updates for language Kannada +ko - translation updates for language Korean +ku - translation updates for language Kurdish +lt - translation updates for language Lithuanian +lv - translation updates for language Latvian +mk - translation updates for language Macedonian +ml - translation updates for language Malayalam +mr - translation updates for language Marathi +ms - translation updates for language Malay +my - translation updates for language Burmese +nb - translation updates for language Bokm?l, Norwegian; Norwegian Bokm?l +ne - translation updates for language Nepali +nl - translation updates for language Dutch; Flemish +nn - translation updates for language Norwegian Nynorsk; Nynorsk, Norwegian +oc - translation updates for language Occitan (post 1500); Proven?al +or - translation updates for language Oriya +pa - translation updates for language Panjabi; Punjabi +pl - translation updates for language Polish +pt - translation updates for language Portuguese +ro - translation updates for language Romanian; Moldavian; Moldovan +ru - translation updates for language Russian +si - translation updates for language Sinhala; Sinhalese +sk - translation updates for language Slovak +sl - translation updates for language Slovenian +sq - translation updates for language Albanian +sr - translation updates for language Serbian +sv - translation updates for language Swedish +ta - translation updates for language Tamil +te - translation updates for language Telugu +tg - translation updates for language Tajik +th - translation updates for language Thai +tr - translation updates for language Turkish +ug - translation updates for language Uighur; Uyghur +uk - translation updates for language Ukrainian +vi - translation updates for language Vietnamese +xh - translation updates for language Xhosa +