Skip to content

Commit

Permalink
fix docker (#1530)
Browse files Browse the repository at this point in the history
* fix docker

use buildkit

wip docker volumes

wip

should be done now

done

add mysql to volumes

fix upgrades

fix version comparison

fix backup restoration and Claroline upgrade

fix invalid composer script

add public folder to volumes in order to keep generated files between runs

* fix docker

use buildkit

wip docker volumes

wip

should be done now

done

add mysql to volumes

fix upgrades

fix version comparison

fix backup restoration and Claroline upgrade

fix invalid composer script

add public folder to volumes in order to keep generated files between runs

fix initial install

fix upgrade

fix dist

fix upgrade logic

fix first upgrade

* docker improvement wip

* fix cache delete in composer.json

Co-authored-by: Gruber Laurent <laurent.gruber@claroline.com>
  • Loading branch information
maieutiquer and LaurentGruber committed Mar 23, 2021
1 parent 6ceeef4 commit c3c7a21
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 72 deletions.
1 change: 1 addition & 0 deletions .docker/mysql/my.cnf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[mysqld]

sql_mode = ""
default_authentication_plugin = "mysql_native_password"
52 changes: 22 additions & 30 deletions .docker/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,68 +1,60 @@
FROM php:7.0.7-apache
FROM php:7.4-apache

MAINTAINER Donovan Tengblad
LABEL maintainer="Donovan Tengblad"

RUN a2enmod rewrite expires ssl headers

RUN curl -sL https://deb.nodesource.com/setup_14.x | bash
RUN apt-get update && apt-get install -y \
git \
mysql-client \
mariadb-client \
wget \
unzip \
zip \
libxml2-dev \
libmcrypt-dev \
libcurl4-gnutls-dev \
wkhtmltopdf \
xz-utils \
xfonts-75dpi \
libav-tools \
libldap2-dev \
libpng12-dev \
libpng-dev \
libjpeg-dev \
zlib1g-dev \
libicu-dev \
libzip-dev \
libonig-dev \
g++ \
ssl-cert \
curl \
npm \
nodejs\
&& rm -rf /var/lib/apt/lists/*

RUN docker-php-ext-install -j$(nproc) xml mcrypt mysqli curl zip mbstring gettext pdo_mysql gd exif mbstring
RUN docker-php-ext-install -j$(nproc) xml mysqli curl zip mbstring gettext pdo_mysql gd exif mbstring
RUN docker-php-ext-configure intl
RUN docker-php-ext-install intl
RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && docker-php-ext-install ldap

RUN npm cache clean -f \
&& npm install -g n \
&& n 5.11.1

RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer

RUN wget http://download.gna.org/wkhtmltopdf/0.12/0.12.3/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz
RUN tar -xf wkhtmltox-0.12.3_linux-generic-amd64.tar.xz

RUN mv wkhtmltox/bin/wkhtmltopdf /usr/bin/wkhtmltopdf.sh
RUN mv wkhtmltox/bin/wkhtmltoimage /usr/bin/wkhtmltoimage.sh
RUN rm -r wkhtmltox
RUN rm wkhtmltox-0.12.3_linux-generic-amd64.tar.xz

RUN pecl install apcu-beta \
&& echo extension=apcu.so > /usr/local/etc/php/conf.d/apcu.ini
&& echo extension=apcu.so > /usr/local/etc/php/conf.d/apcu.ini

COPY config/php.ini /usr/local/etc/php/
COPY ./.docker/web/config/php.ini /usr/local/etc/php/
COPY ./.docker/web/files/apache2/claroline.conf /etc/apache2/sites-available/
COPY ./.docker/web/files/apache2/claroline-ssl.conf /etc/apache2/sites-available/
RUN a2dissite 000-default && a2dissite default-ssl && a2ensite claroline.conf

COPY ./files/apache2/claroline.conf /etc/apache2/sites-available/
COPY ./files/apache2/claroline-ssl.conf /etc/apache2/sites-available/
COPY . /var/www/html/claroline
WORKDIR /var/www/html/claroline

RUN a2dissite 000-default && a2dissite default-ssl && a2ensite claroline.conf
RUN php bin/configure
RUN php bin/check
RUN composer install --no-dev --optimize-autoloader

COPY entrypoint.sh /entrypoint.sh
RUN npm install
RUN npm run webpack

COPY ./.docker/web/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

WORKDIR /var/www/html/claroline
ENTRYPOINT ["/entrypoint.sh"]

CMD ["apache2-foreground"]
60 changes: 41 additions & 19 deletions .docker/web/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,51 @@
set -e

# Wait for MySQL to respond, depends on mysql-client
while ! mysqladmin ping -h"$DB_HOST" --silent; do
echo "MySQL is down"
sleep 1
echo "Waiting for $DB_HOST..."
while ! mysqladmin ping -h "$DB_HOST" --silent; do
echo "MySQL is down"
sleep 1
done

echo "MySQL is up"

if [ -f installed ]; then
echo "ClarolineConnect is allready installed"
else
echo "Executing configuration script"
php scripts/configure.php
if [ -f files/installed ]; then
echo "Claroline is already installed"

echo "Composer install"
if [[ "$ENV" == "dev" ]]; then
composer sync-dev
else
composer sync
if [ -f files/versionLastUsed.txt ]; then
versionLastUsed=$(head -n 1 files/versionLastUsed.txt)
currentVersion=$(head -n 1 VERSION.txt)

if [[ "$versionLastUsed" != "$currentVersion" ]]; then
echo "New version detected, updating..."
php bin/configure # we run it again to regenerate parameters.yml inside the volume
php bin/check
composer enable-maintenance
composer delete-cache
php bin/console claroline:update -vvv
composer disable-maintenance
chmod -R 750 var files config
chown -R www-data:www-data var files config
composer delete-cache # fixes SAML errors
else
echo "Claroline version is up to date"
fi
fi
else
echo "Installing Claroline..."
php bin/configure # we run it again to generate parameters.yml inside the volume
php bin/check
composer bundles # we run it again to generate bundles.ini inside the volume
php bin/console claroline:install -vvv

if [[ -v PLATFORM_NAME ]]; then
echo "Changing platform name to $PLATFORM_NAME";
sed -i "/name: claroline/c\name: $PLATFORM_NAME" files/config/platform_options.yml
sed -i "/name: claroline/c\name: $PLATFORM_NAME" files/config/platform_options.json
fi

if [[ -v PLATFORM_SUPPORT_EMAIL ]]; then
echo "Changing platform support email to $PLATFORM_SUPPORT_EMAIL";
sed -i "/support_email: null/c\support_email: $PLATFORM_SUPPORT_EMAIL" files/config/platform_options.yml
sed -i "/support_email: null/c\support_email: $PLATFORM_SUPPORT_EMAIL" files/config/platform_options.json
fi

USERS=$(mysql $DB_NAME -u $DB_USER -p$DB_PASSWORD -h $DB_HOST -se "select count(*) from claro_user")
Expand All @@ -42,13 +59,18 @@ else

php bin/console claroline:user:create -a $ADMIN_FIRSTNAME $ADMIN_LASTNAME $ADMIN_USERNAME $ADMIN_PASSWORD $ADMIN_EMAIL
else
echo 'ClarolineConnect installed without an admin account'
echo 'Users already exist or no admin vars detected, Claroline installed without an admin account'
fi

touch installed
echo "Setting correct file permissions"
chmod -R 750 var files config
chown -R www-data:www-data var files config

echo "Clean cache after setting correct permissions, fixes SAML issues"
rm -rf var/cache/prod
touch files/installed
fi

echo "Setting correct file permissions"
chmod -R 777 var/cache files/config var/log var/sessions files public/uploads
cp VERSION.txt files/versionLastUsed.txt

exec "$@"
2 changes: 1 addition & 1 deletion .docker/web/files/apache2/claroline-ssl.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Listen 443
SSLEngine on
DocumentRoot /var/www/html/claroline/web
DocumentRoot /var/www/html/claroline/public

#entrypoint.sh appended configuration
6 changes: 3 additions & 3 deletions .docker/web/files/apache2/claroline.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<VirtualHost *:80>
DocumentRoot /var/www/html/claroline/web
<Directory /var/www/html/claroline/web>
DocumentRoot /var/www/html/claroline/public
<Directory /var/www/html/claroline/public>
AllowOverride None
Order Allow,Deny
Allow from All
Expand All @@ -9,7 +9,7 @@
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
</Directory>
</VirtualHost>
18 changes: 18 additions & 0 deletions .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Docker Compose Actions Workflow

jobs:
build:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- name: Build the stack
# run: docker-compose up # remove -d in order to see the build output in gh actions for debugging - you'll need to cancel the run manually once it's done
run: docker-compose up -d
env:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
- name: Test 127.0.0.1
run: docker run --network container:claroline-web curlimages/curl -s --connect-timeout 500 --max-time 1000 --retry 5000 --retry-delay 10 --retry-max-time 4000 --retry-all-errors http://127.0.0.1/
- name: Test 172.22.9.6
run: docker run --network container:claroline-web curlimages/curl -s --connect-timeout 50 --max-time 100 --retry 50 --retry-delay 10 --retry-max-time 40 --retry-all-errors http://172.22.9.6/
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ For user documentation, see [here](https://support.claroline.com/#/desktop/works

[distribution]: https://github.com/claroline/Distribution
[gd]: http://www.php.net/manual/en/book.image.php
[ffmpeg]: http://ffmpeg-php.sourceforge.net
[composer]: https://getcomposer.org
[node]: https://nodejs.org
[npm]: https://docs.npmjs.com
Expand Down
4 changes: 2 additions & 2 deletions bin/check
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ if (!file_exists(__DIR__ . '/../config/parameters.yml')) {
);
}

ensureVersion('node', 'node -v', '6.12');
ensureVersion('npm', 'npm -v', '3.7');
ensureVersion('node', 'node -v', '10.0');
ensureVersion('npm', 'npm -v', '6.0');

function abort($msg)
{
Expand Down
40 changes: 28 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
{
"name": "claroline/claroline",
"description": "Claroline Learning Management System",
"keywords": ["Claroline", "LMS"],
"keywords": [
"Claroline",
"LMS"
],
"homepage": "http://www.claroline.net",
"license": "GPL-3.0-or-later",
"authors": [{
"name": "Claroline development team",
"email": "dev@claroline.net",
"homepage": "http://github.com/claroline"
}],
"authors": [
{
"name": "Claroline development team",
"email": "dev@claroline.net",
"homepage": "http://github.com/claroline"
}
],
"require": {
"php": ">=7.2",
"ext-curl": "*",
Expand Down Expand Up @@ -37,7 +42,7 @@
"lightsaml/sp-bundle": "1.2.1",
"lightsaml/lightsaml-logout": "1.0.0",
"php-http/httplug-bundle": "*",
"php-http/guzzle6-adapter":"*",
"php-http/guzzle6-adapter": "*",
"postal/postal": "1.0",
"psr/log": "1.0.2",
"ramsey/uuid": "3.7.3",
Expand Down Expand Up @@ -145,9 +150,15 @@
}
},
"scripts": {
"enable-maintenance": [
"Claroline\\CoreBundle\\Library\\Maintenance\\MaintenanceHandler::enableMaintenance"
],
"disable-maintenance": [
"Claroline\\CoreBundle\\Library\\Maintenance\\MaintenanceHandler::disableMaintenance"
],
"delete-cache": [
"rm -rf ./var/cache/*"
],
"bundles": [
"Claroline\\BundleRecorder\\ScriptHandler::buildBundleFile"
],
Expand All @@ -161,22 +172,27 @@
"pre-update-cmd": [
"php bin/configure",
"php bin/check",
"Claroline\\CoreBundle\\Library\\Maintenance\\MaintenanceHandler::enableMaintenance",
"Claroline\\CoreBundle\\Library\\Installation\\Refresher::deleteCache"
"composer enable-maintenance",
"composer delete-cache"
],
"post-update-cmd": [
"composer bundles",
"composer disable-maintenance"
"composer disable-maintenance",
"composer delete-cache"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"github-protocols": ["https", "git", "ssh"],
"github-protocols": [
"https",
"git",
"ssh"
],
"process-timeout": 3600
},
"extra": {
"symfony-var-dir": "var",
"symfony-assets-install": "symlink"
}
}
}
2 changes: 1 addition & 1 deletion config/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ parameters:

# database

database_version: 5.6
database_version: 8.0
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: ~
Expand Down

0 comments on commit c3c7a21

Please sign in to comment.