diff --git a/INSTALL/INSTALL.wsl.md b/INSTALL/INSTALL.wsl.md new file mode 100644 index 0000000..720bcec --- /dev/null +++ b/INSTALL/INSTALL.wsl.md @@ -0,0 +1,5 @@ +Installation with WSL (Windows Subsystem for Linux) +------------------------- + +It is possible to deploy the application in WSL environment. +See the instructions [here](../wsl/README.rst). diff --git a/wsl/README.md b/wsl/README.md new file mode 100644 index 0000000..61d4114 --- /dev/null +++ b/wsl/README.md @@ -0,0 +1,43 @@ +# Development environment for MONARC using WSL + +[WSL](https://docs.microsoft.com/en-us/windows/wsl/) +is convenient to use in order to setup your development environment on Windows OS. + +WSL data can be accessible using ```\\wsl$``` on Windows. + + +## Prerequisites + +* You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11. +* Hyper-V Feature turned on [[1]](https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v#enable-hyper-v-using-powershell) +* Virtual Machine Platform and Windows Subsystem for Linux are enabled [[2]](https://docs.microsoft.com/en-us/windows/wsl/troubleshooting#installation-issues) + +## Installation of WSL + +1. In PowerShell Launch install +```powershell +wsl --install -d Ubuntu +``` +2. Create WSL user (WSL shell) +3. Make sure that the Ubuntu distribution is set as default +```powershell +wsl -s Ubuntu +``` + +## Deployment of the front office +In WLS shell: + +```bash + $ cd ~ + $ git clone https://github.com/monarc-project/MonarcAppFO + $ cd MonarcAppFO/wsl + $ bash installFO.sh +``` + +Once the VM will be configured by WSL, go to the address in the browser +```http://localhost/``` + +The username is *admin@admin.localhost* and the password is *admin*. + +The StatsService service will be configured, launched and +accessible on```http://localhost:5005``` diff --git a/wsl/installFO.sh b/wsl/installFO.sh new file mode 100644 index 0000000..7c0c347 --- /dev/null +++ b/wsl/installFO.sh @@ -0,0 +1,338 @@ +#! /usr/bin/env bash + +PATH_TO_MONARC=$HOME/MonarcAppFO + +APPENV='local' +ENVIRONMENT='development' + +# MariaDB database +DBHOST='localhost' +DBNAME_COMMON='monarc_common' +DBNAME_CLI='monarc_cli' +DBUSER_ADMIN='root' +DBPASSWORD_ADMIN="root" +DBUSER_MONARC='sqlmonarcuser' +DBPASSWORD_MONARC="sqlmonarcuser" + +# PHP configuration +upload_max_filesize=200M +post_max_size=50M +max_execution_time=100 +max_input_time=223 +memory_limit=512M + +PHP_INI=/etc/php/7.4/apache2/php.ini +XDEBUG_CFG=/etc/php/7.4/apache2/conf.d/20-xdebug.ini +MARIA_DB_CFG=/etc/mysql/mariadb.conf.d/50-server.cnf + +# Stats service +STATS_PATH=$HOME/stats-service +STATS_HOST='0.0.0.0' +STATS_PORT='5005' +STATS_DB_NAME='statsservice' +STATS_DB_USER='sqlmonarcuser' +STATS_DB_PASSWORD="sqlmonarcuser" +STATS_SECRET_KEY="$(openssl rand -hex 32)" + +echo -e "\n--- Installing now… ---\n" + +echo -e "\n--- Updating packages list… ---\n" +sudo apt-get update > /dev/null 2>&1 +sudo apt-get upgrade -y > /dev/null 2>&1 + +echo -e "\n--- Install base packages… ---\n" +sudo apt-get -y install vim zip unzip git gettext curl gsfonts > /dev/null + + +echo -e "\n--- Install MariaDB specific packages and settings… ---\n" +sudo apt-get -y install mariadb-server mariadb-client > /dev/null +# Secure the MariaDB installation (especially by setting a strong root password) +sudo service mysql restart > /dev/null +sleep 5 +sudo mysql_secure_installation > /dev/null 2>&1 < /dev/null + +echo -e "\n--- Installing PHP-specific packages… ---\n" +sudo apt-get -y install php apache2 libapache2-mod-php php-curl php-gd php-mysql php-pear php-apcu php-xml php-mbstring php-intl php-imagick php-zip php-xdebug php-bcmath > /dev/null 2>&1 + +echo -e "\n--- Configuring PHP… ---\n" +for key in upload_max_filesize post_max_size max_execution_time max_input_time memory_limit +do + sudo sed -i "s/^\($key\).*/\1 = $(eval echo \${$key})/" $PHP_INI +done + +echo -e "\n--- Configuring Xdebug for development ---\n" +sudo bash -c "cat << EOF > $XDEBUG_CFG +zend_extension=xdebug.so +xdebug.remote_enable=1 +xdebug.remote_connect_back=1 +xdebug.idekey=IDEKEY +EOF" + +echo -e "\n--- Enabling mod-rewrite and ssl… ---\n" +sudo a2enmod rewrite > /dev/null 2>&1 +sudo a2enmod ssl > /dev/null 2>&1 +sudo a2enmod headers > /dev/null 2>&1 + +echo -e "\n--- Allowing Apache override to all ---\n" +sudo sed -i "s/AllowOverride None/AllowOverride All/g" /etc/apache2/apache2.conf + +echo -e "\n--- Installing composer… ---\n" +curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer > /dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "\nERROR: unable to install composer\n" + exit 1; +fi + + +echo -e "\n--- Installing MONARC… ---\n" +git clone --config core.fileMode=false https://github.com/monarc-project/MonarcAppFO.git $PATH_TO_MONARC > /dev/null 2>&1 +cd $PATH_TO_MONARC + +echo -e "\n--- Installing the dependencies… ---\n" +composer ins > /dev/null 2>&1 + + +# Make modules symlinks. +mkdir -p module/Monarc +cd module/Monarc +ln -sfn ./../../vendor/monarc/core Core +ln -sfn ./../../vendor/monarc/frontoffice FrontOffice +cd $PATH_TO_MONARC + + + +# Front-end +mkdir -p node_modules +cd node_modules +if [ ! -d "ng_client" ]; then + git clone --config core.fileMode=false https://github.com/monarc-project/ng-client.git ng_client > /dev/null 2>&1 +fi +if [ $? -ne 0 ]; then + echo "\nERROR: unable to clone the ng-client repository\n" + exit 1; +fi +if [ ! -d "ng_anr" ]; then + git clone --config core.fileMode=false https://github.com/monarc-project/ng-anr.git ng_anr > /dev/null 2>&1 +fi +if [ $? -ne 0 ]; then + echo "\nERROR: unable to clone the ng-anr repository\n" + exit 1; +fi +cd .. + + + +echo -e "\n--- Add a VirtualHost for MONARC ---\n" +sudo bash -c "cat << EOF > /etc/apache2/sites-enabled/000-default.conf + + ServerName localhost + DocumentRoot $PATH_TO_MONARC/public + + + DirectoryIndex index.php + AllowOverride All + Require all granted + + + + Header always set X-Content-Type-Options nosniff + Header always set X-XSS-Protection '1; mode=block' + Header always set X-Robots-Tag none + Header always set X-Frame-Options SAMEORIGIN + + + SetEnv APP_ENV $ENVIRONMENT + SetEnv APP_DIR $PATH_TO_MONARC + +EOF" +echo -e "\n--- Restarting Apache… ---\n" +sudo service apache2 restart > /dev/null + + +echo -e "\n--- Installation of Node, NPM and Grunt… ---\n" +curl -sL https://deb.nodesource.com/setup_15.x | sudo bash - > /dev/null 2>&1 +sudo apt-get install -y nodejs > /dev/null 2>&1 +sudo npm install -g grunt-cli > /dev/null 2>&1 + + +echo -e "\n--- Installing the stats service… ---\n" +sudo apt-get -y install postgresql python3-pip python3-venv > /dev/null 2>&1 +sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 10 > /dev/null 2>&1 +sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 20 > /dev/null 2>&1 +sudo service postgresql restart > /dev/null +sudo -u postgres psql -c "CREATE USER $STATS_DB_USER WITH PASSWORD '$STATS_DB_PASSWORD';" > /dev/null +sudo -u postgres psql -c "ALTER USER $STATS_DB_USER WITH SUPERUSER;" > /dev/null + +cd ~ +curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python > /dev/null +echo 'export PATH="$PATH:$HOME/.poetry/bin"' >> ~/.bashrc +echo 'export FLASK_APP=runserver.py' >> ~/.bashrc +echo 'export STATS_CONFIG=production.py' >> ~/.bashrc + +git clone https://github.com/monarc-project/stats-service $STATS_PATH > /dev/null 2>&1 +cd $STATS_PATH +export PATH="$PATH:$HOME/.poetry/bin" +export FLASK_APP=runserver.py +export STATS_CONFIG=production.py +npm ci > /dev/null 2>&1 +poetry install --no-dev > /dev/null + +bash -c "cat << EOF > $STATS_PATH/instance/production.py +HOST = '$STATS_HOST' +PORT = $STATS_PORT +DEBUG = False +TESTING = False +INSTANCE_URL = 'http://127.0.0.1:$STATS_PORT' + +ADMIN_EMAIL = 'info@cases.lu' +ADMIN_URL = 'https://www.cases.lu' + +REMOTE_STATS_SERVER = 'https://dashboard.monarc.lu' + +DB_CONFIG_DICT = { + 'user': '$STATS_DB_USER', + 'password': '$STATS_DB_PASSWORD', + 'host': 'localhost', + 'port': 5432, +} +DATABASE_NAME = '$STATS_DB_NAME' +SQLALCHEMY_DATABASE_URI = 'postgresql://{user}:{password}@{host}:{port}/{name}'.format( + name=DATABASE_NAME, **DB_CONFIG_DICT +) +SQLALCHEMY_TRACK_MODIFICATIONS = False + +SECRET_KEY = '$STATS_SECRET_KEY' + +LOG_PATH = './var/stats.log' + +MOSP_URL = 'https://objects.monarc.lu' +EOF" + +FLASK_APP=runserver.py poetry run flask db_create +FLASK_APP=runserver.py poetry run flask db_init +FLASK_APP=runserver.py poetry run flask client_create --name ADMIN --role admin +FLASK_APP=runserver.py poetry run nohup python runserver.py > /dev/null 2>&1 & + +# Create a new client and set the apiKey. +cd $STATS_PATH ; apiKey=$(poetry run flask client_create --name admin_localhost | sed -nr 's/Token: (.*)$/\1/p') +cd $PATH_TO_MONARC + + +echo -e "\n--- Configuration of MONARC database connection ---\n" +cat > config/autoload/local.php < [ + 'connection' => [ + 'orm_default' => [ + 'params' => [ + 'host' => '$DBHOST', + 'user' => '$DBUSER_MONARC', + 'password' => '$DBPASSWORD_MONARC', + 'dbname' => '$DBNAME_COMMON', + ], + ], + 'orm_cli' => [ + 'params' => [ + 'host' => '$DBHOST', + 'user' => '$DBUSER_MONARC', + 'password' => '$DBPASSWORD_MONARC', + 'dbname' => '$DBNAME_CLI', + ], + ], + ], + ], + + 'activeLanguages' => array('fr','en','de','nl','es','it','ja','pl','pt','ru','zh'), + + 'appVersion' => \$package_json['version'], + + 'checkVersion' => false, + 'appCheckingURL' => 'https://version.monarc.lu/check/MONARC', + + 'email' => [ + 'name' => 'MONARC', + 'from' => 'info@monarc.lu', + ], + + 'mospApiUrl' => 'https://objects.monarc.lu/api/', + + 'monarc' => [ + 'ttl' => 60, // timeout + 'salt' => '', // private salt for password encryption + ], + + 'statsApi' => [ + 'baseUrl' => 'http://127.0.0.1:$STATS_PORT', + 'apiKey' => '$apiKey', + ], +]; +EOF + + +echo -e "\n--- Creation of the data bases… ---\n" +mysql -u $DBUSER_MONARC -p$DBPASSWORD_MONARC -e "CREATE DATABASE monarc_cli DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;" > /dev/null +mysql -u $DBUSER_MONARC -p$DBPASSWORD_MONARC -e "CREATE DATABASE monarc_common DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;" > /dev/null +echo -e "\n--- Populating MONARC DB… ---\n" +mysql -u $DBUSER_MONARC -p$DBPASSWORD_MONARC monarc_common < db-bootstrap/monarc_structure.sql > /dev/null +mysql -u $DBUSER_MONARC -p$DBPASSWORD_MONARC monarc_common < db-bootstrap/monarc_data.sql > /dev/null + + +echo -e "\n--- Creating cache folders for backend… ---\n" +mkdir -p $PATH_TO_MONARC/data/cache +mkdir -p $PATH_TO_MONARC/data/LazyServices/Proxy +mkdir -p $PATH_TO_MONARC/data/DoctrineORMModule/Proxy +chmod -R g+w $PATH_TO_MONARC/data +sudo chown -R www-data:www-data data + + +echo -e "\n--- Update the project… ---\n" +./scripts/update-all.sh -d + + +echo -e "\n--- Create initial user and client ---\n" +php ./bin/phinx seed:run -c ./module/Monarc/FrontOffice/migrations/phinx.php + + +echo -e "\n--- Restarting Apache… ---\n" +sudo service apache2 restart > /dev/null + +echo -e "\n--- Adding autostart Services ---\n" +cat >> ~/.bashrc < /dev/null +wsl.exe -u root service apache2 start > /dev/null +wsl.exe -u root service postgresql start > /dev/null +cd ~/stats-service/ ; poetry run nohup python runserver.py > /dev/null 2>&1 & +cd ~ +EOF + +echo -e "MONARC FO is ready and available at http://localhost" +echo -e "Stats service is ready and available at http://localhost:$STATS_PORT" +echo -e "user: admin@admin.localhost / password: admin"