|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# This file is part of the Moodle Continuous Integration Project. |
| 4 | +# |
| 5 | +# Moodle is free software: you can redistribute it and/or modify |
| 6 | +# it under the terms of the GNU General Public License as published by |
| 7 | +# the Free Software Foundation, either version 3 of the License, or |
| 8 | +# (at your option) any later version. |
| 9 | +# |
| 10 | +# Moodle is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU General Public License |
| 16 | +# along with Moodle. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +# Moodle module functions for Composer-based Moodle installations. |
| 19 | + |
| 20 | +# This module defines the following env variables. |
| 21 | +function moodle-composer_env() { |
| 22 | + env=( |
| 23 | + ) |
| 24 | + echo "${env[@]}" |
| 25 | +} |
| 26 | + |
| 27 | +# Moodle composer module checks. |
| 28 | +function moodle-composer_check() { |
| 29 | + # These env variables must be set for the module to work. |
| 30 | + verify_env CODEDIR |
| 31 | + |
| 32 | + # We can't verify the WEBSERVER env variable here, as the _check method |
| 33 | + # is executed before the docker-php_setup method that defines it. |
| 34 | +} |
| 35 | + |
| 36 | +# Moodle composer module config. |
| 37 | +function moodle-composer_setup() { |
| 38 | + if [[ "${COMPOSERINSTALL}" != "1" ]]; then |
| 39 | + return |
| 40 | + fi |
| 41 | + |
| 42 | + # Install composer. |
| 43 | + docker cp "${BASEDIR}/modules/moodle-composer/install-composer.sh" "${WEBSERVER}":/tmp/install-composer.sh |
| 44 | + docker exec -u root "${WEBSERVER}" bash -c "chmod +x /tmp/install-composer.sh ; /tmp/install-composer.sh" |
| 45 | + |
| 46 | + # Create a composer.json. |
| 47 | + echo "Copying composer.json to the web server." |
| 48 | + docker cp "${BASEDIR}/modules/moodle-composer/composer.json" "${WEBSERVER}":${PHPWORKINGDIR}/composer.json |
| 49 | + docker exec -u root "${WEBSERVER}" bash -c "sed -i '/require.*setup.php/d' ${PHPWORKINGDIR}/config.php" |
| 50 | + |
| 51 | + # Configure composer. |
| 52 | + docker exec \ |
| 53 | + "${WEBSERVER}" \ |
| 54 | + git config --global --add safe.directory /var/www/html |
| 55 | + |
| 56 | + # Run composer install. |
| 57 | + echo "Running composer install. This may take a while..." |
| 58 | + docker exec \ |
| 59 | + -u www-data \ |
| 60 | + "${WEBSERVER}" \ |
| 61 | + bash -c "composer install --no-interaction --prefer-dist --optimize-autoloader" |
| 62 | + echo "Composer install finished" |
| 63 | +} |
0 commit comments