diff --git a/moodle/centos7/Dockerfile b/moodle/centos7/Dockerfile new file mode 100644 index 00000000..216ff8b0 --- /dev/null +++ b/moodle/centos7/Dockerfile @@ -0,0 +1,25 @@ +FROM registry.centos.org/centos/centos:7 + +MAINTAINER Mohammed Zeeshan Ahmed + +RUN yum -y update && yum clean all + +ENV MOODLE_VERSION="3.1" \ + MOODLE_NODOT_VERSION="stable31"\ + PHP_REMI_VERSION="php71" + +RUN mkdir -p /opt/scripts + +ADD install.sh fix-permissions.sh run.sh passwd.template /opt/scripts/ + +RUN . /opt/scripts/install.sh + +EXPOSE 8080 8443 + +WORKDIR /var/www/html + +USER apache + +ENTRYPOINT ["/opt/scripts/run.sh"] +CMD ["moodle"] + diff --git a/moodle/centos7/Dockerfile.3.5 b/moodle/centos7/Dockerfile.3.5 new file mode 100644 index 00000000..a06e9b26 --- /dev/null +++ b/moodle/centos7/Dockerfile.3.5 @@ -0,0 +1,25 @@ +FROM registry.centos.org/centos/centos:7 + +MAINTAINER Mohammed Zeeshan Ahmed + +RUN yum -y update && yum clean all + +ENV MOODLE_VERSION="3.5" \ + MOODLE_NODOT_VERSION="stable35"\ + PHP_REMI_VERSION="php73" + +RUN mkdir -p /opt/scripts + +ADD install.sh fix-permissions.sh run.sh passwd.template /opt/scripts/ + +RUN . /opt/scripts/install.sh + +EXPOSE 8080 8443 + +WORKDIR /var/www/html + +USER apache + +ENTRYPOINT ["/opt/scripts/run.sh"] +CMD ["moodle"] + diff --git a/moodle/centos7/README.md b/moodle/centos7/README.md new file mode 100644 index 00000000..8ebae091 --- /dev/null +++ b/moodle/centos7/README.md @@ -0,0 +1,42 @@ +# Openshift Ready Moodle Container + +## Building the container: + +To build this container yourself, please navigate this this directory after cloning and run: + + $ docker build -t moodle -f Dockerfile . + +## Running the container (with postgresql backend): + +First start postgresql container: + + $ docker run -e POSTGRESQL_USER=moodle -e POSTGRESQL_PASSWORD=moodle -e POSTGRESQL_DATABASE=moodle -d registry.centos.org/postgresql/postgresql:9.6 + +Now find the hostname or ip of postgresql container: + + $ docker run -e DB_TYPE=pgsql -e DB_HOST= -d moodle + +## Mount Points: + + 1. /var/moodledata - This is where the moodle will store its caching data. Please ensure you mount a volume with appropriate permissions here. + +## Environment Variables: + +You can customize parts of moodle by passing certain values as environment variables when you run it. + + 1. DB_TYPE - pgsql | mariadb | mysqli | mssql | sqlsrv | oci : The type of database to use. The terms are self explanatory, however oci for oracle is currently not supported due to licensing issues with their client software. + 2. DB_HOST - The hostname or ip of the database that moodle will use. + 3. DB_NAME - The name of the moodle database in the DB. This assumes the database has already been setup with appropriate users and permissions. + 4. DB_USER - The username of the user who has permissions on DB_NAME in DB_HOST. + 5. DB_PASSWD - The password of DB_USER. + 6. MOODLE_URL - The URL of moodle endpoint. This should include the protocol and port, if any (unless your URL is internally mapped to port 8080 of container as can be done with openshift routes). Default value will be http:\/\/containerip:8080. **Please ensure you escape any such slashes in your own hostname as it will be internally passed to a `sed` command to update the config.php. It is compulsory to either have http or https preceeding this URL.** + +### Tracking Updates: + + 1. **PHP** : PHP updates can be tracked in remicolt repository. + 2. **Moodle** : For moodle, we will have track releases on from download.moodle.org or even on release + monitoring (https://release-monitoring.org/project/6384/) + +### Notes: + + 1. For users of selinux based systems, if you try to volume mount, you might have permission issues even if you do `-v /somepath:/var/moodledata:rw`. You can get more information about that [here](http://www.projectatomic.io/blog/2015/06/using-volumes-with-docker-can-cause-problems-with-selinux/ "SELinux with docker volumes"). diff --git a/moodle/centos7/cccp.yml b/moodle/centos7/cccp.yml new file mode 100644 index 00000000..80551ae6 --- /dev/null +++ b/moodle/centos7/cccp.yml @@ -0,0 +1,2 @@ +job-id: moodle + diff --git a/moodle/centos7/fix-permissions.sh b/moodle/centos7/fix-permissions.sh new file mode 100755 index 00000000..7eaf8135 --- /dev/null +++ b/moodle/centos7/fix-permissions.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# Fix permissions on the given directory to allow group read/write of +# regular files and execute of directories. +set -eux +find "$1" -exec chown ${2} {} \; +find "$1" -exec chgrp 0 {} \; +find "$1" -exec chmod g+rw {} \; +find "$1" -type d -exec chmod g+x {} + + diff --git a/moodle/centos7/install.sh b/moodle/centos7/install.sh new file mode 100755 index 00000000..3f96c0c2 --- /dev/null +++ b/moodle/centos7/install.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +set -eux; + +# Initialize variables +HTTPD_CONF="/etc/httpd/conf/httpd.conf" +HTTPD_WELCOME="/etc/httpd/conf.d/welcome.conf" + +INSTALL_PKGS1="wget"; +INSTALL_PKGS2="httpd nss_wrapper gettext"; +REMI_REPO="https://rpms.remirepo.net/enterprise/remi-release-7.rpm" +PHP_REMI_VERSION="${PHP_REMI_VERSION:-"php71"}" + +PHP1="${PHP_REMI_VERSION} ${PHP_REMI_VERSION}-php ${PHP_REMI_VERSION}-php-pgsql ${PHP_REMI_VERSION}-php-mysqlnd" +PHP2="${PHP_REMI_VERSION}-php-pecl-mysql ${PHP_REMI_VERSION}-php-xml ${PHP_REMI_VERSION}-php-xmlrpc " +PHP3="${PHP_REMI_VERSION}-php-gd ${PHP_REMI_VERSION}-php-pecl-mongodb ${PHP_REMI_VERSION}-php-pecl-apcu" +PHP4="${PHP_REMI_VERSION}-php-pecl-apcu-bc ${PHP_REMI_VERSION}-php-pecl-redis ${PHP_REMI_VERSION}-php-phpiredis" +PHP5="${PHP_REMI_VERSION}-php-opcache ${PHP_REMI_VERSION}-php-pecl-memcache ${PHP_REMI_VERSION}-php-pecl-memcached" +PHP6="${PHP_REMI_VERSION}-php-intl ${PHP_REMI_VERSION}-php-mbstring ${PHP_REMI_VERSION}-php-pecl-solr2" +PHP7="${PHP_REMI_VERSION}-php-pecl-zip ${PHP_REMI_VERSION}-php-soap" + +PHP_MSSQL_PACKAGES="${PHP_REMI_VERSION}-php-sqlsrv" +PHP_ORACLE_PACKAGES="" + +PHP_PACKAGES="${PHP1} ${PHP2} ${PHP3} ${PHP4} ${PHP5} ${PHP6} ${PHP7} ${PHP_MSSQL_PACKAGES}"; +INSTALL_PKGS="${INSTALL_PKGS2} ${PHP_PACKAGES}"; + +MOODLE="moodle"; +MOODLE_DOWNLOAD_BASE="https://download.moodle.org"; +MOODLE_VERSION=${MOODLE_VERSION-"latest"}; +MOODLE_NODOT_VERSION=${MOODLE_NODOT_VERSION:-"moodle"}; +MOODLE_TAR="${MOODLE}-${MOODLE_VERSION}.tgz"; +MOODLE_DOWNLOAD_URL="${MOODLE_DOWNLOAD_BASE}/${MOODLE_NODOT_VERSION}/${MOODLE_TAR}"; +MSSQL_REPODATA="https://packages.microsoft.com/config/rhel/7/prod.repo"; + +export ACCEPT_EULA="Y"; +export MOODLE_DATA="/var/moodledata"; + +# INSTALL BEGINS + +# Setup repositories +yum -y install ${INSTALL_PKGS1} +pushd /etc/yum.repos.d && wget ${MSSQL_REPODATA} && popd + +# Setup necessary packages +yum -y install epel-release && yum -y install ${REMI_REPO} && yum -y install --skip-broken ${INSTALL_PKGS} + +# Install moodle +pushd /var/www; +wget ${MOODLE_DOWNLOAD_URL} && tar zxvf ${MOODLE_TAR} && mv /var/www/${MOODLE}/* /var/www/html; +mkdir -p /var/moodledata && rm -rf ${MOODLE_TAR}; +popd; + +# Fixup Configurations +rm -rf ${HTTPD_WELCOME}; +sed -i 's/^Listen 80/Listen 8080\\\nListen 8443/g' ${HTTPD_CONF}; +sed -i 's/^Listen 8080\\/Listen 8080/g' ${HTTPD_CONF}; +sed -i 's/^Group apache/Group root/g' ${HTTPD_CONF}; +sed -i 's/logs\/error_log/\/dev\/stderr/g' ${HTTPD_CONF}; +sed -i 's/logs\/access_log/\/dev\/stdout/g' ${HTTPD_CONF}; +mkdir -p /etc/httpd/logs && touch /etc/httpd/logs/error_log && touch /etc/httpd/logs/access_log; + +# Fix the permissions +for item in "/etc/httpd" "/var/www" "/var/moodledata"; do + . /opt/scripts/fix-permissions.sh ${item} apache; +done + +chmod -R 777 /etc/httpd/logs; + +# Cleanup +yum -y remove ${INSTALL_PKGS1} && yum clean all + diff --git a/moodle/centos7/passwd.template b/moodle/centos7/passwd.template new file mode 100644 index 00000000..64b8fd40 --- /dev/null +++ b/moodle/centos7/passwd.template @@ -0,0 +1,15 @@ +root:x:0:0:root:/root:/bin/bash +bin:x:1:1:bin:/bin:/sbin/nologin +daemon:x:2:2:daemon:/sbin:/sbin/nologin +adm:x:3:4:adm:/var/adm:/sbin/nologin +lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin +sync:x:5:0:sync:/sbin:/bin/sync +shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown +halt:x:7:0:halt:/sbin:/sbin/halt +mail:x:8:12:mail:/var/spool/mail:/sbin/nologin +operator:x:11:0:operator:/root:/sbin/nologin +games:x:12:100:games:/usr/games:/sbin/nologin +ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin +nobody:x:99:99:Nobody:/:/sbin/nologin +apache:x:${USER_ID}:${GROUP_ID}:Apache User:${HOME}:/bin/bash + diff --git a/moodle/centos7/run.sh b/moodle/centos7/run.sh new file mode 100755 index 00000000..9a713273 --- /dev/null +++ b/moodle/centos7/run.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +# Permissions +export USER_ID=$(id -u); +export GROUP_ID=$(id -g); +envsubst < /opt/scripts/passwd.template > /tmp/passwd; +export LD_PRELOAD=libnss_wrapper.so; +export NSS_WRAPPER_PASSWD=/tmp/passwd; +export NSS_WRAPPER_GROUP=/etc/group; + +# Initialize and validate variables +DB_TYPE=${DB_TYPE:-"pgsql"}; +DB_LIBRARY=${DB_LIBRARY:-"native"}; +DB_HOST=${DB_HOST:-"localhost"}; +DB_NAME=${DB_NAME:-"moodle"}; +DB_USER=${DB_USER:-"moodle"}; +DB_PASSWD=${DB_PASSWD:-"moodle"}; +MOODLE_URL=${MOODLE_URL:-"http:\/\/`hostname -i`:8080"} + +# Main Begins + +if [ $1 == "moodle" ]; then + + if [ ${DB_TYPE} == "oci" ]; then + echo "Oracle database is not currently supported due to licensing issues with their client"; + exit 1 + fi + + sed -e "s/pgsql/${DB_TYPE}/ + s/username/${DB_USER}/ + s/password/${DB_PASSWD}/ + s/http:\/\/example.com\/moodle/${MOODLE_URL}/ + s/localhost/${DB_HOST}/ + s/\/home\/example\/moodledata/\/var\/moodledata/" /var/www/html/config-dist.php > /var/www/html/config.php; + + exec /usr/sbin/httpd -DFOREGROUND; +else + exec $@ +fi +