From 6e0d799a591eba4cfc41f7b76e38df88b94784b0 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Wed, 18 Dec 2024 09:22:32 +0800 Subject: [PATCH] trying to set the wwwroot --- exports | 36 +--------- .../main/jobtypes/performance/performance.sh | 70 ++++++++++++++++--- .../modules/docker-php/config.template.php | 5 +- runner/main/modules/docker-php/docker-php.sh | 3 + .../moodle-core-copy/moodle-core-copy.sh | 18 +++++ 5 files changed, 87 insertions(+), 45 deletions(-) diff --git a/exports b/exports index 6531a7b..d3bb146 100755 --- a/exports +++ b/exports @@ -3,45 +3,13 @@ export WORKSPACE=/home/simey/moodlehq/moodle-ci-runner/workspace export CODEDIR=/home/simey/www/docker_integration_main # The test to run -#export TESTTORUN=phpunit -#export TESTTORUN=install export JOBTYPE=performance -# The browser to use for Behat tests -#export BROWSER=firefox -#export BROWSER=chrome -#export BROWSER_HEADLESS=0 -#export BEHAT_TOTAL_RUNS=3 - # The build id - this is used to generated the chash export BUILD_ID="1" # The Database to use -#export DBTYPE=mysqli -#export DBTYPE=mariadb -#export DBTYPE=oci export DBTYPE=pgsql -#export DBTYPE=sqlsrv - -# Database slaces -export DBREPLICAS=0 -#export DBTAG=latest - -# Any Behat Tags to run -#export TAGS='@javascript&&@mod_workshop&&@arn' -#export TAGS=core_notes -#export TAGS=arn -#export TAGS=filter -#export TAGS="@install" -#export BEHAT_NAME="We can use calculated grade totals" - +export DBTAG=14 # PHP Version -export PHP_VERSION=8.1 - -# Install the moodle mobile app plugin. -#export PLUGINSTOINSTALL="https://github.com/moodlehq/moodle-local_moodlemobileapp.git|local/moodlemobileapp|" -#export MOBILE_VERSION="latest" - - -#export GOOD_COMMIT="7f450dcea36d752e62ab169cbeaf830ecb54c70f" -#export BAD_COMMIT="29ab56c4d28ccdc82722595fac1a1d739e6f2a0d" +export PHP_VERSION=8.3 diff --git a/runner/main/jobtypes/performance/performance.sh b/runner/main/jobtypes/performance/performance.sh index a3c9991..31dc01a 100644 --- a/runner/main/jobtypes/performance/performance.sh +++ b/runner/main/jobtypes/performance/performance.sh @@ -107,23 +107,18 @@ function performance_setup_normal() { # Create an empty timing file. touch "${SHAREDDIR}"/timing.json - # Clone the moodle-performance-comparison repository. - git clone https://github.com/moodlehq/moodle-performance-comparison.git - - # Set up the environment. - cd moodle-performance-comparison - composer install - # Init the Performance site. echo echo ">>> startsection Initialising Performance environment at $(date)<<<" echo "============================================================================" local initcmd performance_initcmd initcmd # By nameref. - echo "Running: ${initcmd[*]}" - docker exec -t -u www-data "${WEBSERVER}" "${initcmd[@]}" + + echo "Creating test data" + performance_generate_test_data + echo "============================================================================" echo ">>> stopsection <<<" } @@ -141,6 +136,63 @@ function performance_initcmd() { ) } +function performance_generate_test_data() { + local phpcmd="php" + + # Generate courses. + docker exec -t -u www-data "${WEBSERVER}" ${phpcmd} admin/tool/generator/cli/maketestsite.php \ + --size="XS" \ + --fixeddataset \ + --bypasscheck \ + --filesizelimit="1000" + echo "NETWORK: ${NETWORK}" + + # Variables +# WEBSERVER="your_webserver_container" +# phpcmd="php" +# SHAREDDIR="/path/to/shared/dir" # Replace with actual shared directory + SIZE="XS" + SHORTNAME="testcourse_3" + +# Generate the test plan files and capture the output +testplanfiles=$(docker exec -t -u www-data "${WEBSERVER}" ${phpcmd} admin/tool/generator/cli/maketestplan.php \ + --size='XS' \ + --shortname='testcourse_3' \ + --bypasscheck) + +# Display the captured output +echo "Captured Output:" +echo "${testplanfiles}" + +# Extract URLs and download files to ${SHAREDDIR} +urls=$(echo "${testplanfiles}" | grep -oP 'http://[^ ]+') +for url in ${urls}; do + # Extract the filename from the URL + filename=$(basename "${url}") + echo "Downloading: ${url} to ${SHAREDDIR}/${filename}" + curl -o "${SHAREDDIR}/${filename}" "${url}" +done + +echo "All files downloaded to ${SHAREDDIR}." + # Uncomment and handle the test plan files if needed. + # local testplanfiles="$(${testplancommand})" + # if [[ "$testplanfiles" == *"testplan"* ]]; then + # local files=( $testplanfiles ) + # if [ "${#files[*]}" -ne 2 ]; then + # echo "Error: There was a problem generating the test plan." >&2 + # exit 1 + # fi + # ${curlcmd} \ + # -o $FILE_NAME_TEST_PLAN ${files[0]} \ + # -o $FILE_NAME_USERS ${files[1]} \ + # --silent || \ + # throw_error "There was a problem getting the test plan files. Check your wwwroot setting." + # else + # echo "Error: There was a problem generating the test plan." >&2 + # exit 1 + # fi +} + #function performance_datacmd() { # #} diff --git a/runner/main/modules/docker-php/config.template.php b/runner/main/modules/docker-php/config.template.php index 0bd7fd0..5935946 100644 --- a/runner/main/modules/docker-php/config.template.php +++ b/runner/main/modules/docker-php/config.template.php @@ -57,7 +57,7 @@ if (empty($CFG->skiplangupgrade)) { define('TOOL_LANGIMPORT_REMOTE_TESTS', true); } - +echo "WWWROOT: " . getenv('MOODLE_WWWROOT') . "\n"; $CFG->wwwroot = getenv('MOODLE_WWWROOT') ?: 'http://host.name'; $CFG->dataroot = '/var/www/moodledata'; $CFG->admin = 'admin'; @@ -74,7 +74,8 @@ $CFG->phpunit_dataroot = '/var/www/phpunitdata'; $CFG->phpunit_prefix = 't_'; - +// Set the generated users password to avoid the default non-loggeable one. +$CFG->tool_generator_users_password = '%%toolgeneratorpassword%%'; // Configure behat. \moodlehq_ci_runner::set_behat_configuration( getenv('WEBSERVER'), diff --git a/runner/main/modules/docker-php/docker-php.sh b/runner/main/modules/docker-php/docker-php.sh index d438b79..8953052 100644 --- a/runner/main/modules/docker-php/docker-php.sh +++ b/runner/main/modules/docker-php/docker-php.sh @@ -52,6 +52,7 @@ function docker-php_setup() { docker run \ --network "${NETWORK}" \ --name "${WEBSERVER}" \ + -e MOODLE_WWWROOT="http://$ip_address" --detach \ --env-file "${ENVIROPATH}" \ -v "${COMPOSERCACHE}:/var/www/.composer:rw" \ @@ -61,6 +62,8 @@ function docker-php_setup() { # Ensure that the whole .composer directory is writable to all (www-data needs to write there). docker exec "${WEBSERVER}" chmod -R go+rw /var/www/.composer + + echo echo "Webserver logs:" docker logs "${WEBSERVER}" diff --git a/runner/main/modules/moodle-core-copy/moodle-core-copy.sh b/runner/main/modules/moodle-core-copy/moodle-core-copy.sh index 439ccd4..8aef9c3 100644 --- a/runner/main/modules/moodle-core-copy/moodle-core-copy.sh +++ b/runner/main/modules/moodle-core-copy/moodle-core-copy.sh @@ -90,6 +90,24 @@ function moodle-core-copy_setup() { # Copy the config.php in place echo "== Copying configuration in place." + ip_address=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "${WEBSERVER}") + echo "IP Address: ${ip_address}" + # Set the MOODLE_WWWROOT environment variable +# export MOODLE_WWWROOT="http://$ip_address" + # Verify that the environment variable is set +# echo "MOODLE_WWWROOT is set to $MOODLE_WWWROOT" +# Set the MOODLE_WWWROOT environment variable in the running container + +# Set the MOODLE_WWWROOT environment variable +export MOODLE_WWWROOT="http://$ip_address" + +# Verify that the environment variable is set +echo "MOODLE_WWWROOT is set to $MOODLE_WWWROOT" + +# Set the MOODLE_WWWROOT environment variable in the running container +docker exec "${WEBSERVER}" /bin/bash -c "export MOODLE_WWWROOT='http://$ip_address' && echo 'MOODLE_WWWROOT is set to $MOODLE_WWWROOT'" + + docker cp "${BASEDIR}/modules/docker-php/config.template.php" "${WEBSERVER}":/var/www/html/config.php docker exec "${WEBSERVER}" chown -R www-data:www-data /var/www/html/config.php