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

Add Docker / docker-compose option to deploy gibbon #1762

Open
wants to merge 26 commits into
base: v27.0.00
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
514edd2
Added Dockerfile
mrestivill Dec 4, 2023
b5dc46e
minor fix
mrestivill Dec 4, 2023
dcfc74e
added docker-gibbon-entrypoint
mrestivill Dec 20, 2023
a6b92ff
added docker gibbon entrypoint
mrestivill Dec 20, 2023
179e51f
version 8.2
mrestivill Dec 20, 2023
771526f
minor fixes
mrestivill Dec 20, 2023
ffe4759
removed unused php extensions
mrestivill Dec 20, 2023
96b0afd
added dockerignore
mrestivill Dec 20, 2023
f40f637
fixed dockerfile
mrestivill Dec 20, 2023
72df2e0
fixed core download
mrestivill Dec 20, 2023
fde68e2
docker-compose example
mrestivill Dec 21, 2023
f1e519b
Update docker-gibbon-entrypoint
mrestivill Dec 22, 2023
cd34124
added +x permissions
mrestivill Dec 22, 2023
ca0bc0a
Merge branch 'feature/docker' of github.com:mrestivill/gibbon-core in…
mrestivill Dec 22, 2023
7c0d303
fixed config.php generation
mrestivill Dec 22, 2023
d80b963
remove installer
mrestivill Dec 22, 2023
e652c30
fixed guid
mrestivill Dec 22, 2023
845ab99
recommended php production/development configuration
mrestivill Dec 22, 2023
bba2a23
initialize mysql with base gibbon.sql script
mrestivill Dec 22, 2023
6b461e9
reordered commands
mrestivill Dec 22, 2023
eaef138
added database initialization dependency on docker-compose
mrestivill Dec 22, 2023
20c8d06
reordered commands
mrestivill Dec 22, 2023
75e0dfc
minor fixes
mrestivill Dec 22, 2023
ae306fa
fix: added admin user
mrestivill Apr 9, 2024
199ae34
fix: add default email and username
mrestivill Apr 9, 2024
b0067d9
Update docker-gibbon-entrypoint
mrestivill Apr 9, 2024
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
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/Dockerfile
.github
86 changes: 86 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
FROM php:8.2-apache-buster



ENV VERSION=26.0.00
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid

#WORKDIR /var/www/html already set by base image

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
apt-transport-https


# Install apache, PHP, and supplimentary programs. openssh-server, curl, and lynx-cur are for debugging the container.
RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
git \
wget \
curl \
lynx \
ca-certificates \
libzip-dev \
zlib1g-dev \
libpng-dev \
libjpeg-dev \
libxml2-dev \
libcurl4-openssl-dev \
libonig-dev \
&& a2enmod rewrite && \
# sed -i 's/short_open_tag = Off/short_open_tag = On/' $PHP_INI_DIR/php.ini && \
# sed -i 's/magic_quotes_gpc = On/magic_quotes_gpc = Off/g' $PHP_INI_DIR/php.ini && \
# sed -i "s/^allow_url_fopen.*$/allow_url_fopen = On/" $PHP_INI_DIR/php.ini && \
# sed -i 's/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/' $PHP_INI_DIR/php.ini && \
apt-get clean autoclean && \
apt-get autoremove -y && \
rm -rfv /var/lib/{apt,dpkg,cache,log}/
RUN docker-php-ext-install bcmath \
&& docker-php-ext-configure gd --with-jpeg \
&& docker-php-ext-install gd \
&& docker-php-ext-install xml \
&& docker-php-ext-install curl \
&& docker-php-ext-install mbstring \
&& docker-php-ext-install mysqli \
&& docker-php-ext-install opcache \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install pdo \
&& docker-php-ext-install gettext \
&& docker-php-ext-install zip \
&& docker-php-ext-install intl

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN git clone --single-branch https://github.com/GibbonEdu/core.git -b v${VERSION} . && \
rm -f docker-gibbon-entrypoint Dockerfile docker-compose.yml && \
git clone --single-branch https://github.com/GibbonEdu/i18n.git ./i18n && \
chmod -R 755 . && chown -R www-data:www-data .
#Tool to generate config.php
RUN wget https://github.com/okdana/twigc/releases/download/v0.4.0/twigc.phar -O /tmp/twigc.phar && \
chmod +x /tmp/twigc.phar && mv /tmp/twigc.phar /usr/local/bin/twigc

ADD .htaccess .

# composer
RUN composer install && \
chown 33:33 -R . && \
chmod -Rv 755 .

# basic recommendations https://docs.gibbonedu.org/administrators/getting-started/installing-gibbon/#post-install-server-config
RUN echo "\nphp_flag register_globals off\n" >> .htaccess && \
sed "s/Options Indexes FollowSymLinks/Options FollowSymLinks/g" -i /etc/apache2/apache2.conf

COPY ./docker-gibbon-entrypoint /usr/local/bin

RUN chmod u+x /usr/local/bin/docker-gibbon-entrypoint

EXPOSE 80
VOLUME /var/www/html/uploads


ENTRYPOINT [ "docker-gibbon-entrypoint" ]

CMD ["apache2-foreground"]

42 changes: 42 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: '3.9'
services:
db:
image: mysql:8
restart: always
environment:
MYSQL_DATABASE: 'gibbondb'
MYSQL_USER: 'gibbon'
MYSQL_PASSWORD: 'gibbon-password'
MYSQL_ROOT_PASSWORD: 'SuperSecretPassword'
ports:
- '3306:3306'
expose:
- '3306'
volumes:
- gibbon-db:/var/lib/mysql
- ./gibbon.sql:/docker-entrypoint-initdb.d/gibbon.sql
healthcheck:
test: ["CMD", 'mysqladmin', 'ping', '--silent', '-h', 'localhost', '-u', 'root', '-p$$MYSQL_ROOT_PASSWORD' ]
interval: 30s
timeout: 20s
retries: 20
gibbon:
image: gibbon/gibbon
build: .
restart: always
environment:
MYSQL_HOST: 'db'
MYSQL_DATABASE: 'gibbondb'
MYSQL_USER: 'gibbon'
MYSQL_PASSWORD: 'gibbon-password'
ports:
- "8080:80"
volumes:
- gibbon-uploads:/var/www/html/uploads
depends_on:
db:
condition: service_healthy

volumes:
gibbon-db:
gibbon-uploads:
102 changes: 102 additions & 0 deletions docker-gibbon-entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/sh
set -e
environment='production'

# Check if the environment variable is set
if [ -z "$GIBBON_STUDENTS" ]; then
students="30"
else
students="$GIBBON_STUDENTS"
fi
# xdebug setup
if [ -n "$DEBUG" ]; then
environment='development'
echo "Debug mode enabled"
# Install xdebug PECL extension
pecl install xdebug
CONTAINER_IP=`/sbin/ip route|awk '/default/ { print $3 }'`
cat << EOF > $PHP_INI_DIR/conf.d/debug.ini
zend_extension=xdebug.so

xdebug.cli_color = 1
xdebug.client_host=${CONTAINER_IP}
xdebug.log_level=0
xdebug.mode=develop,debug
xdebug.show_error_trace = On
xdebug.start_with_request=yes
xdebug.var_display_max_children = 128
xdebug.var_display_max_data = 128
xdebug.var_display_max_depth = 8

max_execution_time=600
EOF

else
echo "Debug mode not enabled"
rm -f $PHP_INI_DIR/conf.d/debug.ini
cp $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini
fi
#generate php.ini based on development/production php recommendations
if [ ! -e "$PHP_INI_DIR/php.ini" ]; then
cp $PHP_INI_DIR/php.ini-$environment $PHP_INI_DIR/php.ini
echo "\nmax_input_vars=5000\n" >> $PHP_INI_DIR/php.ini
echo "max_file_uploads=$students\n" >> $PHP_INI_DIR/php.ini
fi

if [ -n "$MYSQL_HOST" ] && [ -n "$MYSQL_USER" ] && [ -n "$MYSQL_PASSWORD" ] && [ -n "$MYSQL_DATABASE" ]; then
if [ ! -e "config.php" ]; then
guid="$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
if [ -n "$GUID" ]; then
guid="$GUID"
fi
echo "File config.php does not exists, Configuring instance with environment variables"
twigc resources/templates/installer/config.twig.html -p "guid='$guid'" -p "databaseServer='$MYSQL_HOST'" -p "databaseUsername='$MYSQL_USER'" -p "databasePassword='$MYSQL_PASSWORD'" -p "databaseName='$MYSQL_DATABASE'" | grep -v '^Deprecated:'> config.php
rm -Rf installer
# Check if admin record exists
if [[ $(mysql -h "$MYSQL_HOST" -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" -N -B -e "SELECT COUNT(*) FROM gibbonPerson WHERE gibbonPersonID=1;") -eq 0 ]]; then
# Generate a random password
if [[ -z "${GIBBON_ADMIN_PASSWORD}" ]]; then
PASSWORD=$(openssl rand -base64 12)
else
PASSWORD=${GIBBON_ADMIN_PASSWORD}
fi

# Set environment variables
export EMAIL="${GIBBON_ADMIN_EMAIL:=admin@example.com}"
export USERNAME="${GIBBON_ADMIN_USERNAME:=admin}"
export PASSWORD_STRONG="$PASSWORD"
export PASSWORD_STRONG_SALT="$(openssl rand -base64 12)"
export STATUS="active"
export CAN_LOGIN=1
export PASSWORD_FORCE_RESET=0
export GIBBON_ROLE_ID_PRIMARY=1
export GIBBON_ROLE_ID_ALL=1

# Insert new record
mysql -h "$MYSQL_HOST" -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" <<EOF
INSERT INTO gibbonPerson (gibbonPersonID, title, surname, firstName, preferredName, officialName, username, passwordStrong, passwordStrongSalt, status, canLogin, passwordForceReset, gibbonRoleIDPrimary, gibbonRoleIDAll, email)
VALUES (1, '', '', '', '', '', '\$USERNAME', '\$PASSWORD_STRONG', '\$PASSWORD_STRONG_SALT', '\$STATUS', \$CAN_LOGIN, \$PASSWORD_FORCE_RESET, \$GIBBON_ROLE_ID_PRIMARY, \$GIBBON_ROLE_ID_ALL, '\$EMAIL');
EOF
if [[ -z "${GIBBON_ADMIN_PASSWORD}" ]]; then
echo "New user inserted. Generated password: $PASSWORD"
else
echo "New user inserted.
fi
else
echo "Record already exists."
fi

fi
unset MYSQL_HOST MYSQL_USER MYSQL_PASSWORD MYSQL_DATABASE
fi
# new volume could contain diferent permissions, asure permissions on uploads are ok
owner=$(stat -c "%U" "uploads")
if [ "$owner" != "33" ]; then
chown -R 33:33 uploads
chmod -R g+w uploads
chmod -R u+w uploads
chmod -R o-w uploads
fi


sh /usr/local/bin/docker-php-entrypoint "$@"