Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dockerfiles to create container for moodle. #130

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
217deb8
Added dockerfiles to create container for moodle.
mohammedzee1000 Apr 4, 2017
4cb5480
Updated to alter install zend opcache and configuration.
mohammedzee1000 Apr 4, 2017
8d795c6
Added cccp.yml file to allow building on pipeline.
mohammedzee1000 Apr 4, 2017
70b1b73
Moodle container now functional on openshift.
mohammedzee1000 Apr 5, 2017
76a1896
Added few more packages to allow more options for datasources.
mohammedzee1000 Apr 5, 2017
1e3848c
Added redis, solr apcu packages.
mohammedzee1000 Apr 5, 2017
19b39cb
Updated to use remicolt repository for php 71.
mohammedzee1000 Apr 6, 2017
dc9f31d
Added basic readme. Will fill in once container is ready.
mohammedzee1000 Apr 6, 2017
21e94f0
Modified remicolt repo url and brought back mssql.
mohammedzee1000 Apr 6, 2017
221abf7
Added mssql php extensions for using mssql as backend.
mohammedzee1000 Apr 6, 2017
2308f04
Removed freetds and updated to fail if oracle backend is requested.
mohammedzee1000 Apr 6, 2017
0f4df78
Updated to single env for hostand fixed name.
mohammedzee1000 Apr 6, 2017
f5dd91f
Updated readme with some information.
mohammedzee1000 Apr 6, 2017
18227e1
Fixed package name and added end of file newlines.
mohammedzee1000 Apr 7, 2017
0d54f07
Removed mssql-tools setup as it interferes with php-sqlserv.
mohammedzee1000 Apr 7, 2017
2698835
Fixed default pattern for MOODLE_URL and added readme notice.
mohammedzee1000 Apr 7, 2017
90e007a
Updated README to indicate that protocol is compulsory.
mohammedzee1000 Apr 7, 2017
dea50f2
Updated readme with information on how to track updates.
mohammedzee1000 Apr 8, 2017
dbd5091
Uncommented the yum update.
mohammedzee1000 Apr 11, 2017
45036e9
Fixed typos in moodle readme.
mohammedzee1000 Apr 12, 2017
a719455
Updated to tail log files.
mohammedzee1000 Apr 21, 2017
2a8a29f
Updated config to dump logs on stdout and stderr.
mohammedzee1000 Apr 21, 2017
18e2972
Adding 3.5 Dockerfile for moodle container.
mohammedzee1000 Jul 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions moodle/centos7/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM registry.centos.org/centos/centos:7

MAINTAINER Mohammed Zeeshan Ahmed <[email protected]>

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"]

25 changes: 25 additions & 0 deletions moodle/centos7/Dockerfile.3.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM registry.centos.org/centos/centos:7

MAINTAINER Mohammed Zeeshan Ahmed <[email protected]>

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"]

42 changes: 42 additions & 0 deletions moodle/centos7/README.md
Original file line number Diff line number Diff line change
@@ -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=<POSTGRES_IP> -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").
2 changes: 2 additions & 0 deletions moodle/centos7/cccp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
job-id: moodle

9 changes: 9 additions & 0 deletions moodle/centos7/fix-permissions.sh
Original file line number Diff line number Diff line change
@@ -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 {} +

72 changes: 72 additions & 0 deletions moodle/centos7/install.sh
Original file line number Diff line number Diff line change
@@ -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

15 changes: 15 additions & 0 deletions moodle/centos7/passwd.template
Original file line number Diff line number Diff line change
@@ -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

40 changes: 40 additions & 0 deletions moodle/centos7/run.sh
Original file line number Diff line number Diff line change
@@ -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