Commit e4b8276b authored by Artem Baranovskyi's avatar Artem Baranovskyi
Browse files

Few PHPUnit infrastructural fixes.

parent 866f9a08
...@@ -9,6 +9,7 @@ MOODLE_DATABASE_USER=moodleuser ...@@ -9,6 +9,7 @@ MOODLE_DATABASE_USER=moodleuser
MOODLE_DATABASE_PASSWORD=moodlepassword MOODLE_DATABASE_PASSWORD=moodlepassword
MOODLE_BASE_DIR=/var/www/html/moodle MOODLE_BASE_DIR=/var/www/html/moodle
MOODLE_BASE_DIR_DATA=/var/www/html/moodledata MOODLE_BASE_DIR_DATA=/var/www/html/moodledata
MOODLE_PHPUNIT_DATAROOT=/var/www/html/phpunitdata
MOODLE_WWWROOT=https://www.moodle.loc MOODLE_WWWROOT=https://www.moodle.loc
MOODLE_FULLNAME="Moodle LMS Site" MOODLE_FULLNAME="Moodle LMS Site"
......
...@@ -33,6 +33,7 @@ services: ...@@ -33,6 +33,7 @@ services:
- MOODLE_DATABASE_NAME=${MOODLE_DATABASE_NAME} - MOODLE_DATABASE_NAME=${MOODLE_DATABASE_NAME}
- MOODLE_DATABASE_USER=${MOODLE_DATABASE_USER} - MOODLE_DATABASE_USER=${MOODLE_DATABASE_USER}
- MOODLE_DATABASE_PASSWORD=${MOODLE_DATABASE_PASSWORD} - MOODLE_DATABASE_PASSWORD=${MOODLE_DATABASE_PASSWORD}
- MOODLE_PHPUNIT_DATAROOT=${MOODLE_PHPUNIT_DATAROOT}
ports: ports:
- 80:80 - 80:80
- 443:443 - 443:443
...@@ -46,6 +47,7 @@ services: ...@@ -46,6 +47,7 @@ services:
- ${PWD}/asystgrade:${MOODLE_BASE_DIR}/local/asystgrade # Sync the plugin folder with the container - ${PWD}/asystgrade:${MOODLE_BASE_DIR}/local/asystgrade # Sync the plugin folder with the container
- moodle_data:${MOODLE_BASE_DIR} # Volume for Moodle - moodle_data:${MOODLE_BASE_DIR} # Volume for Moodle
- moodledata:${MOODLE_BASE_DIR_DATA} # Volume for Moodle data - moodledata:${MOODLE_BASE_DIR_DATA} # Volume for Moodle data
- moodle_phpunit_data:${MOODLE_PHPUNIT_DATAROOT}
networks: networks:
- network # Adding the network communication between containers - network # Adding the network communication between containers
...@@ -76,6 +78,8 @@ volumes: # Defining local volumes ...@@ -76,6 +78,8 @@ volumes: # Defining local volumes
driver: local driver: local
flask: flask:
driver: local driver: local
moodle_phpunit_data:
driver: local
networks: networks:
network: # Creating a network network: # Creating a network
\ No newline at end of file
...@@ -15,7 +15,7 @@ COPY . /app ...@@ -15,7 +15,7 @@ COPY . /app
COPY ./asyst /app/asyst COPY ./asyst /app/asyst
# Installing dependencies # Installing dependencies
RUN /opt/myenv/bin/pip install --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple -r /app/requirements.txt RUN /opt/myenv/bin/pip install -r /app/requirements.txt
RUN /opt/myenv/bin/python3 -m pip install --upgrade setuptools wheel RUN /opt/myenv/bin/python3 -m pip install --upgrade setuptools wheel
......
...@@ -17,12 +17,17 @@ docker-compose exec moodle mkdir -p ${MOODLE_BASE_DIR_DATA}/temp ...@@ -17,12 +17,17 @@ docker-compose exec moodle mkdir -p ${MOODLE_BASE_DIR_DATA}/temp
docker-compose exec moodle mkdir -p ${MOODLE_BASE_DIR_DATA}/trashdir docker-compose exec moodle mkdir -p ${MOODLE_BASE_DIR_DATA}/trashdir
docker-compose exec moodle chown -R www-data:www-data ${MOODLE_BASE_DIR_DATA} docker-compose exec moodle chown -R www-data:www-data ${MOODLE_BASE_DIR_DATA}
docker-compose exec moodle chmod -R 775 ${MOODLE_BASE_DIR_DATA} docker-compose exec moodle chmod -R 775 ${MOODLE_BASE_DIR_DATA}
# Ensure correct ownership and permissions after installation
docker-compose exec moodle chown -R www-data:www-data ${MOODLE_BASE_DIR}
docker-compose exec moodle chmod -R 755 ${MOODLE_BASE_DIR}
docker-compose exec moodle mkdir -p ${MOODLE_PHPUNIT_DATAROOT}
docker-compose exec moodle chown -R www-data:www-data ${MOODLE_PHPUNIT_DATAROOT}
docker-compose exec moodle chmod -R 755 ${MOODLE_PHPUNIT_DATAROOT}
# Install Moodle # Install Moodle
sleep 5 sleep 5
docker-compose exec moodle php ${MOODLE_BASE_DIR}/admin/cli/install.php \ docker-compose exec moodle php ${MOODLE_BASE_DIR}/admin/cli/install.php \
--wwwroot="${MOODLE_WWWROOT}" \ --wwwroot="${MOODLE_WWWROOT}" \
--phpunit_dataroot="${MOODLE_WWWROOT}" \
--dataroot="${MOODLE_BASE_DIR_DATA}" \ --dataroot="${MOODLE_BASE_DIR_DATA}" \
--dbtype="mariadb" \ --dbtype="mariadb" \
--dbname="${MOODLE_DATABASE_NAME}" \ --dbname="${MOODLE_DATABASE_NAME}" \
...@@ -35,6 +40,10 @@ docker-compose exec moodle php ${MOODLE_BASE_DIR}/admin/cli/install.php \ ...@@ -35,6 +40,10 @@ docker-compose exec moodle php ${MOODLE_BASE_DIR}/admin/cli/install.php \
--agree-license \ --agree-license \
--non-interactive --non-interactive
# Add phpunit_dataroot & phpunit_prefix to config.php
docker-compose exec moodle bash -c "echo '\$CFG->phpunit_dataroot = \"${MOODLE_PHPUNIT_DATAROOT}\";' >> ${MOODLE_BASE_DIR}/config.php"
docker-compose exec moodle bash -c "echo '\$CFG->phpunit_prefix = \"phpu_\";' >> ${MOODLE_BASE_DIR}/config.php"
# Check if database backup exists and restore it if it does # Check if database backup exists and restore it if it does
BACKUP_FILE="moodle/moodle_backup.sql" BACKUP_FILE="moodle/moodle_backup.sql"
if [ -f "$BACKUP_FILE" ]; then if [ -f "$BACKUP_FILE" ]; then
...@@ -57,21 +66,26 @@ docker-compose exec moodle bash -c " ...@@ -57,21 +66,26 @@ docker-compose exec moodle bash -c "
php -r \"copy('https://getcomposer.org/installer', 'composer-setup.php');\" && php -r \"copy('https://getcomposer.org/installer', 'composer-setup.php');\" &&
php composer-setup.php --install-dir=/usr/local/bin --filename=composer && php composer-setup.php --install-dir=/usr/local/bin --filename=composer &&
php -r \"unlink('composer-setup.php');\" && php -r \"unlink('composer-setup.php');\" &&
cd /app && cd app &&
/usr/local/bin/composer install --no-interaction --no-plugins --no-scripts --no-dev --prefer-dist && /usr/local/bin/composer install --no-interaction --no-plugins --no-scripts --no-dev --prefer-dist &&
/usr/local/bin/composer dump-autoload /usr/local/bin/composer dump-autoload
" "
# Next, configure PHPUnit for Moodle: # Next, configure PHPUnit for Moodle:
docker-compose exec moodle php admin/tool/phpunit/cli/init.php docker-compose exec moodle php admin/tool/phpunit/cli/init.php
# Define the path to the phpunit.xml file # Define the path to the phpunit.xml file
PHPUNIT_XML_PATH="/var/www/html/moodle/phpunit.xml" PHPUNIT_XML_PATH="/var/www/html/moodle/phpunit.xml"
# Define the content to insert for your plugin's test suite # Define the content to insert for your plugin's test suite
TEST_SUITE_ENTRY='<testsuite name="Unit Tests"> TEST_SUITE_ENTRY='<testsuite name="Unit Tests">\n <directory>local/asystgrade/tests</directory>\n</testsuite>'
<directory>local/asystgrade/tests</directory>
</testsuite>' # Check if phpunit.xml exists
if [ -f "$PHPUNIT_XML_PATH" ]; then
echo "$PHPUNIT_XML_PATH exists."
else
echo "$PHPUNIT_XML_PATH does not exist."
fi
# Check if the plugin suite is already defined in phpunit.xml # Check if the plugin suite is already defined in phpunit.xml
if grep -q "local/asystgrade/tests" "$PHPUNIT_XML_PATH"; then if grep -q "local/asystgrade/tests" "$PHPUNIT_XML_PATH"; then
...@@ -82,10 +96,6 @@ else ...@@ -82,10 +96,6 @@ else
echo "Test suite for asystgrade plugin added to phpunit.xml." echo "Test suite for asystgrade plugin added to phpunit.xml."
fi fi
# Ensure correct ownership and permissions after installation
docker-compose exec moodle chown -R www-data:www-data ${MOODLE_BASE_DIR}
docker-compose exec moodle chmod -R 755 ${MOODLE_BASE_DIR}
# Set correct access rules for the plugin # Set correct access rules for the plugin
docker-compose exec moodle chown -R www-data:www-data ${MOODLE_BASE_DIR}/local/asystgrade docker-compose exec moodle chown -R www-data:www-data ${MOODLE_BASE_DIR}/local/asystgrade
docker-compose exec moodle chmod -R 775 ${MOODLE_BASE_DIR}/local/asystgrade docker-compose exec moodle chmod -R 775 ${MOODLE_BASE_DIR}/local/asystgrade
...@@ -105,4 +115,9 @@ docker-compose exec flask chmod +x /usr/local/bin/run_sag ...@@ -105,4 +115,9 @@ docker-compose exec flask chmod +x /usr/local/bin/run_sag
docker-compose exec flask /usr/local/bin/run_sag docker-compose exec flask /usr/local/bin/run_sag
# Adding cron-record at the Moodle container # Adding cron-record at the Moodle container
docker-compose exec -u root moodle bash -c "echo '* * * * * /usr/bin/php ${MOODLE_BASE_DIR}/admin/cli/cron.php >/dev/null 2>&1' >> /etc/crontabs/root && crontab /etc/crontabs/root" docker-compose exec -u root moodle bash -c "
mkdir -p /etc/crontabs &&
touch /etc/crontabs/root &&
echo '* * * * * /usr/bin/php ${MOODLE_BASE_DIR}/admin/cli/cron.php >/dev/null 2>&1' >> /etc/crontabs/root &&
crontab /etc/crontabs/root
"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment