From ca8b1a11e43a638b204ede276134c1cbb95c3cc1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 12 Jan 2026 16:17:39 +0000 Subject: [PATCH 1/7] Initial plan From 4a7f2f3edf0e347e390c417a631227f12830001b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 12 Jan 2026 16:23:11 +0000 Subject: [PATCH 2/7] Add Docker development environment setup files Co-authored-by: ruslanbaidan <3246171+ruslanbaidan@users.noreply.github.com> --- .dockerignore | 46 +++++ .env.dev | 18 ++ .gitignore | 2 + Dockerfile | 114 ++++++++++++ Dockerfile.stats | 38 ++++ README.docker.md | 344 +++++++++++++++++++++++++++++++++++++ docker-compose.dev.yml | 124 +++++++++++++ docker-entrypoint.sh | 156 +++++++++++++++++ docker-stats-entrypoint.sh | 97 +++++++++++ 9 files changed, 939 insertions(+) create mode 100644 .dockerignore create mode 100644 .env.dev create mode 100644 Dockerfile create mode 100644 Dockerfile.stats create mode 100644 README.docker.md create mode 100644 docker-compose.dev.yml create mode 100644 docker-entrypoint.sh create mode 100644 docker-stats-entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f568e03 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,46 @@ +# Git files +.git +.gitignore +.github + +# Documentation +README.md +CHANGELOG.md +AUTHORS +LICENSE +SECURITY.md +*.md + +# Development files +vagrant/ +wsl/ +INSTALL/ +.idea +.vscode +.DS_Store + +# Dependencies (will be installed in container) +vendor/ +node_modules/ + +# Data directories (will be mounted as volumes) +data/ + +# Build artifacts +public/css/ +public/js/ +public/img/ +public/flags/ +public/views/ + +# Logs +*.log +npm-debug.log + +# Cache +*.cache +.docker-initialized + +# Environment files (should be configured separately) +.env +.env.dev diff --git a/.env.dev b/.env.dev new file mode 100644 index 0000000..1cf1339 --- /dev/null +++ b/.env.dev @@ -0,0 +1,18 @@ +# MariaDB Configuration +DBPASSWORD_ADMIN=root +DBNAME_COMMON=monarc_common +DBNAME_CLI=monarc_cli +DBUSER_MONARC=sqlmonarcuser +DBPASSWORD_MONARC=sqlmonarcuser + +# Stats Service Configuration +STATS_HOST=0.0.0.0 +STATS_PORT=5005 +STATS_DB_NAME=statsservice +STATS_DB_USER=sqlmonarcuser +STATS_DB_PASSWORD=sqlmonarcuser +# Generate a random secret key for production use: +# openssl rand -hex 32 +STATS_SECRET_KEY=changeme_generate_random_secret_key_for_production +# This will be generated by stats service on first run +STATS_API_KEY=will_be_generated_on_first_run diff --git a/.gitignore b/.gitignore index 9fb0019..c2db730 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ bin/ data/* !data/fonts .docker/mariaDb/data/* +.env +.docker-initialized diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eab8cd8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,114 @@ +FROM ubuntu:22.04 + +# Prevent interactive prompts during package installation +ENV DEBIAN_FRONTEND=noninteractive +ENV LANGUAGE=en_US.UTF-8 +ENV LANG=en_US.UTF-8 +ENV LC_ALL=en_US.UTF-8 + +# Install system dependencies +RUN apt-get update && apt-get upgrade -y && \ + apt-get install -y \ + vim \ + zip \ + unzip \ + git \ + gettext \ + curl \ + gsfonts \ + apache2 \ + php8.1 \ + php8.1-cli \ + php8.1-common \ + php8.1-mysql \ + php8.1-zip \ + php8.1-gd \ + php8.1-mbstring \ + php8.1-curl \ + php8.1-xml \ + php8.1-bcmath \ + php8.1-intl \ + php8.1-imagick \ + php8.1-xdebug \ + locales \ + wget \ + ca-certificates \ + gnupg && \ + locale-gen en_US.UTF-8 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Configure PHP +RUN sed -i 's/upload_max_filesize = .*/upload_max_filesize = 200M/' /etc/php/8.1/apache2/php.ini && \ + sed -i 's/post_max_size = .*/post_max_size = 50M/' /etc/php/8.1/apache2/php.ini && \ + sed -i 's/max_execution_time = .*/max_execution_time = 100/' /etc/php/8.1/apache2/php.ini && \ + sed -i 's/max_input_time = .*/max_input_time = 223/' /etc/php/8.1/apache2/php.ini && \ + sed -i 's/memory_limit = .*/memory_limit = 512M/' /etc/php/8.1/apache2/php.ini && \ + sed -i 's/session\.gc_maxlifetime = .*/session.gc_maxlifetime = 604800/' /etc/php/8.1/apache2/php.ini && \ + sed -i 's/session\.gc_probability = .*/session.gc_probability = 1/' /etc/php/8.1/apache2/php.ini && \ + sed -i 's/session\.gc_divisor = .*/session.gc_divisor = 1000/' /etc/php/8.1/apache2/php.ini + +# Configure Xdebug for development +RUN echo "zend_extension=xdebug.so" > /etc/php/8.1/apache2/conf.d/20-xdebug.ini && \ + echo "xdebug.mode=debug" >> /etc/php/8.1/apache2/conf.d/20-xdebug.ini && \ + echo "xdebug.discover_client_host=1" >> /etc/php/8.1/apache2/conf.d/20-xdebug.ini && \ + echo "xdebug.idekey=IDEKEY" >> /etc/php/8.1/apache2/conf.d/20-xdebug.ini + +# Enable Apache modules +RUN a2enmod rewrite ssl headers + +# Install Composer +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + +# Install Node.js and npm +RUN mkdir -p /etc/apt/keyrings && \ + curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ + echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_15.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \ + apt-get update && \ + apt-get install -y nodejs npm && \ + npm install -g grunt-cli && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Set working directory +WORKDIR /var/www/html/monarc + +# Configure Apache +RUN echo '\n\ + ServerName localhost\n\ + DocumentRoot /var/www/html/monarc/public\n\ +\n\ + \n\ + DirectoryIndex index.php\n\ + AllowOverride All\n\ + Require all granted\n\ + \n\ +\n\ + \n\ + Header always set X-Content-Type-Options nosniff\n\ + Header always set X-XSS-Protection "1; mode=block"\n\ + Header always set X-Robots-Tag none\n\ + Header always set X-Frame-Options SAMEORIGIN\n\ + \n\ +\n\ + SetEnv APP_ENV development\n\ + SetEnv APP_DIR /var/www/html/monarc\n\ +' > /etc/apache2/sites-available/000-default.conf + +# Allow Apache override to all +RUN sed -i 's/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf + +# Create necessary directories +RUN mkdir -p /var/www/html/monarc/data/cache \ + /var/www/html/monarc/data/LazyServices/Proxy \ + /var/www/html/monarc/data/DoctrineORMModule/Proxy \ + /var/www/html/monarc/data/import/files + +# Copy entrypoint script +COPY docker-entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/docker-entrypoint.sh + +EXPOSE 80 + +ENTRYPOINT ["docker-entrypoint.sh"] +CMD ["apache2-foreground"] diff --git a/Dockerfile.stats b/Dockerfile.stats new file mode 100644 index 0000000..a2b9bee --- /dev/null +++ b/Dockerfile.stats @@ -0,0 +1,38 @@ +FROM ubuntu:22.04 + +ENV DEBIAN_FRONTEND=noninteractive +ENV LANGUAGE=en_US.UTF-8 +ENV LANG=en_US.UTF-8 +ENV LC_ALL=en_US.UTF-8 +ENV FLASK_APP=runserver.py +ENV STATS_CONFIG=production.py + +# Install dependencies +RUN apt-get update && \ + apt-get install -y \ + git \ + curl \ + python3 \ + python3-pip \ + python3-venv \ + nodejs \ + npm \ + postgresql-client \ + locales && \ + locale-gen en_US.UTF-8 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Install Poetry +RUN curl -sSL https://install.python-poetry.org | python3 - && \ + ln -s /root/.local/bin/poetry /usr/local/bin/poetry + +WORKDIR /var/www/stats-service + +# Copy entrypoint script +COPY docker-stats-entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/docker-stats-entrypoint.sh + +EXPOSE 5005 + +ENTRYPOINT ["docker-stats-entrypoint.sh"] diff --git a/README.docker.md b/README.docker.md new file mode 100644 index 0000000..1f26cb2 --- /dev/null +++ b/README.docker.md @@ -0,0 +1,344 @@ +# Docker Development Environment for MONARC FrontOffice + +This guide explains how to set up a local development environment for MONARC FrontOffice using Docker. + +## Prerequisites + +- Docker Engine 20.10 or later +- Docker Compose V2 (comes with Docker Desktop) +- At least 8GB of RAM available for Docker +- At least 20GB of free disk space + +## Quick Start + +1. **Clone the repository** (if you haven't already): + ```bash + git clone https://github.com/monarc-project/MonarcAppFO + cd MonarcAppFO + ``` + +2. **Copy the environment file**: + ```bash + cp .env.dev .env + ``` + +3. **Customize environment variables** (optional): + Edit `.env` file to change default passwords and configuration: + ```bash + # Generate a secure secret key for stats service + openssl rand -hex 32 + # Update STATS_SECRET_KEY in .env with the generated value + ``` + +4. **Start the development environment**: + ```bash + docker-compose -f docker-compose.dev.yml up --build + ``` + + The first run will take several minutes as it: + - Builds the Docker images + - Installs all dependencies (PHP, Node.js, Python) + - Clones frontend repositories + - Initializes databases + - Sets up the stats service + - Creates the initial admin user + +5. **Access the application**: + - MONARC FrontOffice: http://localhost:5001 + - Stats Service: http://localhost:5005 + - MailCatcher (email testing): http://localhost:1080 + +6. **Login credentials**: + - Username: `admin@admin.localhost` + - Password: `admin` + +## Services + +The development environment includes the following services: + +| Service | Description | Port | Container Name | +|---------|-------------|------|----------------| +| monarc | Main FrontOffice application (PHP/Apache) | 5001 | monarc-fo-app | +| db | MariaDB database | 3306 | monarc-fo-db | +| postgres | PostgreSQL database (for stats) | 5432 | monarc-fo-postgres | +| stats-service | MONARC Statistics Service | 5005 | monarc-fo-stats | +| mailcatcher | Email testing tool | 1080 (web), 1025 (SMTP) | monarc-fo-mailcatcher | + +## Development Workflow + +### Live Code Editing + +The application source code is mounted as a volume, so changes you make on your host machine will be immediately reflected in the container. After making changes: + +1. **PHP/Backend changes**: Apache automatically reloads modified files +2. **Frontend changes**: You may need to rebuild the frontend: + ```bash + docker exec -it monarc-fo-app bash + cd /var/www/html/monarc + ./scripts/update-all.sh -d + ``` + +### Accessing the Container + +To access the MONARC application container: +```bash +docker exec -it monarc-fo-app bash +``` + +To access the stats service container: +```bash +docker exec -it monarc-fo-stats bash +``` + +### Database Access + +Connect to MariaDB: +```bash +docker exec -it monarc-fo-db mysql -usqlmonarcuser -psqlmonarcuser monarc_common +``` + +Connect to PostgreSQL: +```bash +docker exec -it monarc-fo-postgres psql -U sqlmonarcuser -d statsservice +``` + +### Viewing Logs + +View logs for all services: +```bash +docker-compose -f docker-compose.dev.yml logs -f +``` + +View logs for a specific service: +```bash +docker-compose -f docker-compose.dev.yml logs -f monarc +docker-compose -f docker-compose.dev.yml logs -f stats-service +``` + +### Restarting Services + +Restart all services: +```bash +docker-compose -f docker-compose.dev.yml restart +``` + +Restart a specific service: +```bash +docker-compose -f docker-compose.dev.yml restart monarc +``` + +### Stopping the Environment + +Stop all services (keeps data): +```bash +docker-compose -f docker-compose.dev.yml stop +``` + +Stop and remove containers (keeps volumes/data): +```bash +docker-compose -f docker-compose.dev.yml down +``` + +Stop and remove everything including data: +```bash +docker-compose -f docker-compose.dev.yml down -v +``` + +## Common Tasks + +### Resetting the Database + +To completely reset the databases: +```bash +docker-compose -f docker-compose.dev.yml down -v +docker-compose -f docker-compose.dev.yml up --build +``` + +### Installing New PHP Dependencies + +```bash +docker exec -it monarc-fo-app bash +composer require package/name +``` + +### Installing New Node Dependencies + +```bash +docker exec -it monarc-fo-app bash +cd node_modules/ng_client # or ng_anr +npm install package-name +``` + +### Running Database Migrations + +```bash +docker exec -it monarc-fo-app bash +php ./vendor/robmorgan/phinx/bin/phinx migrate -c ./module/Monarc/FrontOffice/migrations/phinx.php +``` + +### Creating Database Seeds + +```bash +docker exec -it monarc-fo-app bash +php ./bin/phinx seed:run -c ./module/Monarc/FrontOffice/migrations/phinx.php +``` + +### Rebuilding Frontend + +```bash +docker exec -it monarc-fo-app bash +cd /var/www/html/monarc +./scripts/update-all.sh -d +``` + +## Debugging + +### Xdebug Configuration + +Xdebug is pre-configured in the development environment. To use it: + +1. Configure your IDE to listen on port 9003 +2. Set the IDE key to `IDEKEY` +3. Start debugging in your IDE +4. Trigger a request to the application + +For PhpStorm: +- Go to Settings → PHP → Debug +- Set Xdebug port to 9003 +- Enable "Can accept external connections" +- Set the path mappings: `/var/www/html/monarc` → your local project path + +### Checking Service Health + +```bash +# Check if all services are running +docker-compose -f docker-compose.dev.yml ps + +# Check specific service health +docker-compose -f docker-compose.dev.yml ps monarc +``` + +## Troubleshooting + +### Port Conflicts + +If you get port conflicts, you can change the ports in the `docker-compose.dev.yml` file: +```yaml +ports: + - "5001:80" # Change 5001 to another available port +``` + +### Permission Issues + +If you encounter permission issues with mounted volumes: +```bash +docker exec -it monarc-fo-app bash +chown -R www-data:www-data /var/www/html/monarc/data +chmod -R 775 /var/www/html/monarc/data +``` + +### Database Connection Issues + +Check if the database is healthy: +```bash +docker-compose -f docker-compose.dev.yml ps db +``` + +If needed, restart the database: +```bash +docker-compose -f docker-compose.dev.yml restart db +``` + +### Stats Service Issues + +Check stats service logs: +```bash +docker-compose -f docker-compose.dev.yml logs stats-service +``` + +Restart the stats service: +```bash +docker-compose -f docker-compose.dev.yml restart stats-service +``` + +### Rebuilding from Scratch + +If something goes wrong and you want to start fresh: +```bash +# Stop everything +docker-compose -f docker-compose.dev.yml down -v + +# Remove all related containers, images, and volumes +docker system prune -a + +# Rebuild and start +docker-compose -f docker-compose.dev.yml up --build +``` + +## Performance Optimization + +For better performance on macOS and Windows: + +1. **Use Docker volume mounts for dependencies**: The compose file already uses named volumes for `vendor` and `node_modules` to improve performance. + +2. **Allocate more resources**: In Docker Desktop settings, increase: + - CPUs: 4 or more + - Memory: 8GB or more + - Swap: 2GB or more + +3. **Enable caching**: The Dockerfile uses apt cache and composer optimizations. + +## Comparison with Vagrant + +| Feature | Docker | Vagrant | +|---------|--------|---------| +| Startup time | Fast (~2-3 min) | Slow (~10-15 min) | +| Resource usage | Lower | Higher | +| Isolation | Container-level | VM-level | +| Portability | Excellent | Good | +| Live code reload | Yes | Yes | +| Learning curve | Moderate | Low | + +## Environment Variables Reference + +All environment variables are defined in the `.env` file: + +| Variable | Description | Default | +|----------|-------------|---------| +| `DBPASSWORD_ADMIN` | MariaDB root password | `root` | +| `DBNAME_COMMON` | Common database name | `monarc_common` | +| `DBNAME_CLI` | CLI database name | `monarc_cli` | +| `DBUSER_MONARC` | Database user | `sqlmonarcuser` | +| `DBPASSWORD_MONARC` | Database password | `sqlmonarcuser` | +| `STATS_HOST` | Stats service host | `0.0.0.0` | +| `STATS_PORT` | Stats service port | `5005` | +| `STATS_DB_NAME` | Stats database name | `statsservice` | +| `STATS_DB_USER` | Stats database user | `sqlmonarcuser` | +| `STATS_DB_PASSWORD` | Stats database password | `sqlmonarcuser` | +| `STATS_SECRET_KEY` | Stats service secret key | `changeme_generate_random_secret_key_for_production` | + +## Security Notes + +⚠️ **Important**: The default credentials provided are for development only. Never use these in production! + +For production deployments: +1. Change all default passwords +2. Generate a secure `STATS_SECRET_KEY` using `openssl rand -hex 32` +3. Use proper SSL/TLS certificates +4. Follow security best practices + +## Additional Resources + +- [MONARC Website](https://www.monarc.lu) +- [MONARC Documentation](https://www.monarc.lu/documentation) +- [GitHub Repository](https://github.com/monarc-project/MonarcAppFO) +- [MonarcAppBO (BackOffice)](https://github.com/monarc-project/MonarcAppBO) + +## Getting Help + +If you encounter issues: + +1. Check the [troubleshooting section](#troubleshooting) +2. Review the logs: `docker-compose -f docker-compose.dev.yml logs` +3. Open an issue on [GitHub](https://github.com/monarc-project/MonarcAppFO/issues) +4. Join the MONARC community discussions diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..6803d71 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,124 @@ +version: '3.8' + +services: + # MariaDB database for MONARC + db: + image: mariadb:10.11 + container_name: monarc-fo-db + environment: + MYSQL_ROOT_PASSWORD: ${DBPASSWORD_ADMIN} + MYSQL_DATABASE: ${DBNAME_COMMON} + MYSQL_USER: ${DBUSER_MONARC} + MYSQL_PASSWORD: ${DBPASSWORD_MONARC} + command: + - --character-set-server=utf8mb4 + - --collation-server=utf8mb4_general_ci + - --bind-address=0.0.0.0 + ports: + - "3306:3306" + volumes: + - db_data:/var/lib/mysql + networks: + - monarc-network + healthcheck: + test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${DBPASSWORD_ADMIN}"] + interval: 10s + timeout: 5s + retries: 5 + + # PostgreSQL database for stats service + postgres: + image: postgres:15 + container_name: monarc-fo-postgres + environment: + POSTGRES_USER: ${STATS_DB_USER} + POSTGRES_PASSWORD: ${STATS_DB_PASSWORD} + POSTGRES_DB: ${STATS_DB_NAME} + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + networks: + - monarc-network + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${STATS_DB_USER}"] + interval: 10s + timeout: 5s + retries: 5 + + # Stats service + stats-service: + build: + context: . + dockerfile: Dockerfile.stats + container_name: monarc-fo-stats + environment: + STATS_HOST: ${STATS_HOST} + STATS_PORT: ${STATS_PORT} + STATS_DB_HOST: postgres + STATS_DB_NAME: ${STATS_DB_NAME} + STATS_DB_USER: ${STATS_DB_USER} + STATS_DB_PASSWORD: ${STATS_DB_PASSWORD} + STATS_SECRET_KEY: ${STATS_SECRET_KEY} + ports: + - "5005:5005" + depends_on: + postgres: + condition: service_healthy + networks: + - monarc-network + volumes: + - stats_data:/var/www/stats-service + + # MailCatcher for email testing + mailcatcher: + image: sj26/mailcatcher:latest + container_name: monarc-fo-mailcatcher + ports: + - "1080:1080" # Web interface + - "1025:1025" # SMTP + networks: + - monarc-network + + # Main MONARC FrontOffice application + monarc: + build: + context: . + dockerfile: Dockerfile + container_name: monarc-fo-app + environment: + DBHOST: db + DBNAME_COMMON: ${DBNAME_COMMON} + DBNAME_CLI: ${DBNAME_CLI} + DBUSER_MONARC: ${DBUSER_MONARC} + DBPASSWORD_MONARC: ${DBPASSWORD_MONARC} + STATS_API_KEY: ${STATS_API_KEY} + APP_ENV: development + APP_DIR: /var/www/html/monarc + ports: + - "5001:80" + depends_on: + db: + condition: service_healthy + stats-service: + condition: service_started + networks: + - monarc-network + volumes: + # Mount the application code for live development + - ./:/var/www/html/monarc + # Preserve vendor directory in named volume for better performance + - vendor_data:/var/www/html/monarc/vendor + - node_modules_data:/var/www/html/monarc/node_modules + working_dir: /var/www/html/monarc + +networks: + monarc-network: + driver: bridge + +volumes: + db_data: + postgres_data: + stats_data: + vendor_data: + node_modules_data: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..b022597 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,156 @@ +#!/bin/bash +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +echo -e "${GREEN}Starting MONARC FrontOffice setup...${NC}" + +# Wait for database to be ready +echo -e "${YELLOW}Waiting for MariaDB to be ready...${NC}" +while ! mysqladmin ping -h"${DBHOST}" -u"${DBUSER_MONARC}" -p"${DBPASSWORD_MONARC}" --silent 2>/dev/null; do + echo "Waiting for MariaDB..." + sleep 2 +done +echo -e "${GREEN}MariaDB is ready!${NC}" + +# Check if this is the first run +if [ ! -f "/var/www/html/monarc/.docker-initialized" ]; then + echo -e "${GREEN}First run detected, initializing application...${NC}" + + cd /var/www/html/monarc + + # Install composer dependencies + if [ ! -d "vendor" ]; then + echo -e "${YELLOW}Installing Composer dependencies...${NC}" + composer install --ignore-platform-req=php + fi + + # Create module symlinks + echo -e "${YELLOW}Creating module symlinks...${NC}" + mkdir -p module/Monarc + cd module/Monarc + ln -sfn ./../../vendor/monarc/core Core + ln -sfn ./../../vendor/monarc/frontoffice FrontOffice + cd /var/www/html/monarc + + # Clone frontend repositories + echo -e "${YELLOW}Setting up frontend repositories...${NC}" + 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 + fi + + if [ ! -d "ng_anr" ]; then + git clone --config core.fileMode=false https://github.com/monarc-project/ng-anr.git ng_anr + fi + + cd /var/www/html/monarc + + # Check if database exists and create if needed + echo -e "${YELLOW}Setting up databases...${NC}" + DB_EXISTS=$(mysql -h"${DBHOST}" -u"${DBUSER_MONARC}" -p"${DBPASSWORD_MONARC}" -e "SHOW DATABASES LIKE '${DBNAME_CLI}';" | grep -c "${DBNAME_CLI}" || true) + + if [ "$DB_EXISTS" -eq 0 ]; then + echo -e "${YELLOW}Creating databases...${NC}" + mysql -h"${DBHOST}" -u"${DBUSER_MONARC}" -p"${DBPASSWORD_MONARC}" -e "CREATE DATABASE ${DBNAME_CLI} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;" + mysql -h"${DBHOST}" -u"${DBUSER_MONARC}" -p"${DBPASSWORD_MONARC}" -e "CREATE DATABASE ${DBNAME_COMMON} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;" + + echo -e "${YELLOW}Populating databases...${NC}" + mysql -h"${DBHOST}" -u"${DBUSER_MONARC}" -p"${DBPASSWORD_MONARC}" ${DBNAME_COMMON} < db-bootstrap/monarc_structure.sql + mysql -h"${DBHOST}" -u"${DBUSER_MONARC}" -p"${DBPASSWORD_MONARC}" ${DBNAME_COMMON} < db-bootstrap/monarc_data.sql + fi + + # Generate local config if it doesn't exist + if [ ! -f "config/autoload/local.php" ]; then + echo -e "${YELLOW}Creating local configuration...${NC}" + 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','ro','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://stats-service:5005', + 'apiKey' => '${STATS_API_KEY}', + ], + + 'import' => [ + 'uploadFolder' => '\$appdir/data/import/files', + 'isBackgroundProcessActive' => false, + ], +]; +EOF + fi + + # Update and build frontend + echo -e "${YELLOW}Building frontend...${NC}" + ./scripts/update-all.sh -d + + # Seed database with initial user + echo -e "${YELLOW}Creating initial user and client...${NC}" + php ./bin/phinx seed:run -c ./module/Monarc/FrontOffice/migrations/phinx.php + + # Set permissions + echo -e "${YELLOW}Setting permissions...${NC}" + chown -R www-data:www-data /var/www/html/monarc/data + chmod -R 775 /var/www/html/monarc/data + + # Mark initialization as complete + touch /var/www/html/monarc/.docker-initialized + echo -e "${GREEN}Initialization complete!${NC}" +else + echo -e "${GREEN}Application already initialized, starting services...${NC}" +fi + +# Execute the main command +exec apache2-foreground diff --git a/docker-stats-entrypoint.sh b/docker-stats-entrypoint.sh new file mode 100644 index 0000000..cd6cb12 --- /dev/null +++ b/docker-stats-entrypoint.sh @@ -0,0 +1,97 @@ +#!/bin/bash +set -e + +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' + +echo -e "${GREEN}Starting MONARC Stats Service setup...${NC}" + +# Wait for PostgreSQL to be ready +echo -e "${YELLOW}Waiting for PostgreSQL to be ready...${NC}" +until PGPASSWORD=$STATS_DB_PASSWORD psql -h "$STATS_DB_HOST" -U "$STATS_DB_USER" -d postgres -c '\q' 2>/dev/null; do + echo "Waiting for PostgreSQL..." + sleep 2 +done +echo -e "${GREEN}PostgreSQL is ready!${NC}" + +# Check if this is the first run +if [ ! -f "/var/www/stats-service/.docker-initialized" ]; then + echo -e "${GREEN}First run detected, initializing stats service...${NC}" + + # Clone the stats service repository + if [ ! -d "/var/www/stats-service/.git" ]; then + echo -e "${YELLOW}Cloning stats-service repository...${NC}" + cd /var/www + git clone https://github.com/monarc-project/stats-service stats-service-tmp + cp -r stats-service-tmp/* stats-service/ + cp -r stats-service-tmp/.git stats-service/ + rm -rf stats-service-tmp + cd /var/www/stats-service + fi + + # Install npm dependencies + echo -e "${YELLOW}Installing npm dependencies...${NC}" + npm ci + + # Install Python dependencies with Poetry + echo -e "${YELLOW}Installing Python dependencies with Poetry...${NC}" + poetry install --no-dev + + # Create instance directory and configuration + echo -e "${YELLOW}Creating configuration...${NC}" + mkdir -p instance + cat > instance/production.py < Date: Mon, 12 Jan 2026 16:25:26 +0000 Subject: [PATCH 3/7] Fix Docker configuration and improve setup Co-authored-by: ruslanbaidan <3246171+ruslanbaidan@users.noreply.github.com> --- .env.dev | 5 +++-- Dockerfile | 3 ++- README.docker.md | 15 ++++++++++++++- docker-compose.dev.yml | 2 -- docker-entrypoint.sh | 4 ++-- docker-stats-entrypoint.sh | 0 6 files changed, 21 insertions(+), 8 deletions(-) mode change 100644 => 100755 docker-entrypoint.sh mode change 100644 => 100755 docker-stats-entrypoint.sh diff --git a/.env.dev b/.env.dev index 1cf1339..049c9ba 100644 --- a/.env.dev +++ b/.env.dev @@ -14,5 +14,6 @@ STATS_DB_PASSWORD=sqlmonarcuser # Generate a random secret key for production use: # openssl rand -hex 32 STATS_SECRET_KEY=changeme_generate_random_secret_key_for_production -# This will be generated by stats service on first run -STATS_API_KEY=will_be_generated_on_first_run +# Stats API Key - Leave empty on first run, it will be generated by the stats service +# After first run, get it from the stats service logs or container +STATS_API_KEY= diff --git a/Dockerfile b/Dockerfile index eab8cd8..ad70470 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,7 @@ RUN apt-get update && apt-get upgrade -y && \ gettext \ curl \ gsfonts \ + mariadb-client \ apache2 \ php8.1 \ php8.1-cli \ @@ -111,4 +112,4 @@ RUN chmod +x /usr/local/bin/docker-entrypoint.sh EXPOSE 80 ENTRYPOINT ["docker-entrypoint.sh"] -CMD ["apache2-foreground"] +CMD ["apachectl", "-D", "FOREGROUND"] diff --git a/README.docker.md b/README.docker.md index 1f26cb2..efc4a76 100644 --- a/README.docker.md +++ b/README.docker.md @@ -48,7 +48,20 @@ This guide explains how to set up a local development environment for MONARC Fro - Stats Service: http://localhost:5005 - MailCatcher (email testing): http://localhost:1080 -6. **Login credentials**: +6. **(Optional) Configure Stats API Key**: + The stats service generates an API key on first run. To retrieve it: + ```bash + # Check the stats service logs for the API key + docker-compose -f docker-compose.dev.yml logs stats-service | grep "Token:" + + # Or create a new client and get the key + docker exec -it monarc-fo-stats poetry run flask client_create --name monarc + + # Update the .env file with the API key and restart the monarc service + docker-compose -f docker-compose.dev.yml restart monarc + ``` + +7. **Login credentials**: - Username: `admin@admin.localhost` - Password: `admin` diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 6803d71..0941b81 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -1,5 +1,3 @@ -version: '3.8' - services: # MariaDB database for MONARC db: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh old mode 100644 new mode 100755 index b022597..2c836c2 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -121,7 +121,7 @@ return [ 'statsApi' => [ 'baseUrl' => 'http://stats-service:5005', - 'apiKey' => '${STATS_API_KEY}', + 'apiKey' => '${STATS_API_KEY:-}', ], 'import' => [ @@ -153,4 +153,4 @@ else fi # Execute the main command -exec apache2-foreground +exec apachectl -D FOREGROUND diff --git a/docker-stats-entrypoint.sh b/docker-stats-entrypoint.sh old mode 100644 new mode 100755 From fa3ef0d0e294e2b1bdcb2548205c5d9375882f33 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 12 Jan 2026 16:28:00 +0000 Subject: [PATCH 4/7] Add helper script and improve documentation Co-authored-by: ruslanbaidan <3246171+ruslanbaidan@users.noreply.github.com> --- README.docker.md | 126 ++++++++++++++++++++++++++++++++++++----------- docker-dev.sh | 122 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 220 insertions(+), 28 deletions(-) create mode 100755 docker-dev.sh diff --git a/README.docker.md b/README.docker.md index efc4a76..95cab6d 100644 --- a/README.docker.md +++ b/README.docker.md @@ -11,6 +11,43 @@ This guide explains how to set up a local development environment for MONARC Fro ## Quick Start +### Option 1: Using the Helper Script (Recommended) + +1. **Clone the repository** (if you haven't already): + ```bash + git clone https://github.com/monarc-project/MonarcAppFO + cd MonarcAppFO + ``` + +2. **Start the development environment**: + ```bash + ./docker-dev.sh start + ``` + + This will automatically: + - Create `.env` file from `.env.dev` if it doesn't exist + - Build and start all services + - Display access URLs + + The first run will take several minutes as it: + - Builds the Docker images + - Installs all dependencies (PHP, Node.js, Python) + - Clones frontend repositories + - Initializes databases + - Sets up the stats service + - Creates the initial admin user + +3. **Access the application**: + - MONARC FrontOffice: http://localhost:5001 + - Stats Service: http://localhost:5005 + - MailCatcher (email testing): http://localhost:1080 + +4. **Login credentials**: + - Username: `admin@admin.localhost` + - Password: `admin` + +### Option 2: Using Docker Compose Directly + 1. **Clone the repository** (if you haven't already): ```bash git clone https://github.com/monarc-project/MonarcAppFO @@ -35,14 +72,6 @@ This guide explains how to set up a local development environment for MONARC Fro docker-compose -f docker-compose.dev.yml up --build ``` - The first run will take several minutes as it: - - Builds the Docker images - - Installs all dependencies (PHP, Node.js, Python) - - Clones frontend repositories - - Initializes databases - - Sets up the stats service - - Creates the initial admin user - 5. **Access the application**: - MONARC FrontOffice: http://localhost:5001 - Stats Service: http://localhost:5005 @@ -51,7 +80,10 @@ This guide explains how to set up a local development environment for MONARC Fro 6. **(Optional) Configure Stats API Key**: The stats service generates an API key on first run. To retrieve it: ```bash - # Check the stats service logs for the API key + # Using helper script + ./docker-dev.sh stats-key + + # Or manually check logs docker-compose -f docker-compose.dev.yml logs stats-service | grep "Token:" # Or create a new client and get the key @@ -79,6 +111,25 @@ The development environment includes the following services: ## Development Workflow +### Helper Script Commands + +The `docker-dev.sh` script provides convenient commands for managing the development environment: + +```bash +./docker-dev.sh start # Start all services +./docker-dev.sh stop # Stop all services +./docker-dev.sh restart # Restart all services +./docker-dev.sh logs # View logs from all services +./docker-dev.sh logs-app # View logs from MONARC application +./docker-dev.sh logs-stats # View logs from stats service +./docker-dev.sh shell # Open a shell in the MONARC container +./docker-dev.sh shell-stats # Open a shell in the stats service container +./docker-dev.sh db # Open MySQL client +./docker-dev.sh status # Show status of all services +./docker-dev.sh stats-key # Show the stats API key +./docker-dev.sh reset # Reset everything (removes all data) +``` + ### Live Code Editing The application source code is mounted as a volume, so changes you make on your host machine will be immediately reflected in the container. After making changes: @@ -93,67 +144,86 @@ The application source code is mounted as a volume, so changes you make on your ### Accessing the Container -To access the MONARC application container: +Using helper script: ```bash -docker exec -it monarc-fo-app bash +./docker-dev.sh shell # MONARC application +./docker-dev.sh shell-stats # Stats service ``` -To access the stats service container: +Or directly with docker: ```bash -docker exec -it monarc-fo-stats bash +docker exec -it monarc-fo-app bash # MONARC application +docker exec -it monarc-fo-stats bash # Stats service ``` ### Database Access -Connect to MariaDB: +Using helper script: ```bash -docker exec -it monarc-fo-db mysql -usqlmonarcuser -psqlmonarcuser monarc_common +./docker-dev.sh db # Connect to MariaDB ``` -Connect to PostgreSQL: +Or directly with docker: ```bash +# Connect to MariaDB +docker exec -it monarc-fo-db mysql -usqlmonarcuser -psqlmonarcuser monarc_common + +# Connect to PostgreSQL docker exec -it monarc-fo-postgres psql -U sqlmonarcuser -d statsservice ``` ### Viewing Logs -View logs for all services: +Using helper script: ```bash -docker-compose -f docker-compose.dev.yml logs -f +./docker-dev.sh logs # All services +./docker-dev.sh logs-app # MONARC application only +./docker-dev.sh logs-stats # Stats service only ``` -View logs for a specific service: +Or directly with docker compose: ```bash +# View logs for all services +docker-compose -f docker-compose.dev.yml logs -f + +# View logs for a specific service docker-compose -f docker-compose.dev.yml logs -f monarc docker-compose -f docker-compose.dev.yml logs -f stats-service ``` ### Restarting Services -Restart all services: +Using helper script: ```bash -docker-compose -f docker-compose.dev.yml restart +./docker-dev.sh restart # Restart all services ``` -Restart a specific service: +Or directly with docker compose: ```bash +# Restart all services +docker-compose -f docker-compose.dev.yml restart + +# Restart a specific service docker-compose -f docker-compose.dev.yml restart monarc ``` ### Stopping the Environment -Stop all services (keeps data): +Using helper script: ```bash -docker-compose -f docker-compose.dev.yml stop +./docker-dev.sh stop # Stop all services (keeps data) +./docker-dev.sh reset # Stop and remove everything including data ``` -Stop and remove containers (keeps volumes/data): +Or directly with docker compose: ```bash +# Stop all services (keeps data) +docker-compose -f docker-compose.dev.yml stop + +# Stop and remove containers (keeps volumes/data) docker-compose -f docker-compose.dev.yml down -``` -Stop and remove everything including data: -```bash +# Stop and remove everything including data docker-compose -f docker-compose.dev.yml down -v ``` diff --git a/docker-dev.sh b/docker-dev.sh new file mode 100755 index 0000000..42f21f5 --- /dev/null +++ b/docker-dev.sh @@ -0,0 +1,122 @@ +#!/bin/bash +# Helper script for managing MONARC Docker development environment + +set -e + +COMPOSE_FILE="docker-compose.dev.yml" + +# Colors for output +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +RED='\033[0;31m' +NC='\033[0m' # No Color + +usage() { + echo -e "${GREEN}MONARC Docker Development Environment Manager${NC}" + echo "" + echo "Usage: $0 [command]" + echo "" + echo "Commands:" + echo " start Start all services (builds on first run)" + echo " stop Stop all services" + echo " restart Restart all services" + echo " logs View logs from all services" + echo " logs-app View logs from MONARC application" + echo " logs-stats View logs from stats service" + echo " shell Open a shell in the MONARC container" + echo " shell-stats Open a shell in the stats service container" + echo " db Open MySQL client in the database" + echo " reset Reset everything (removes all data)" + echo " status Show status of all services" + echo " stats-key Show the stats API key" + echo "" +} + +check_env() { + if [ ! -f .env ]; then + echo -e "${YELLOW}No .env file found. Creating from .env.dev...${NC}" + cp .env.dev .env + echo -e "${GREEN}.env file created. You can edit it to customize configuration.${NC}" + fi +} + +case "$1" in + start) + check_env + echo -e "${GREEN}Starting MONARC development environment...${NC}" + docker compose -f $COMPOSE_FILE up -d --build + echo -e "${GREEN}Services started!${NC}" + echo -e "MONARC FrontOffice: http://localhost:5001" + echo -e "Stats Service: http://localhost:5005" + echo -e "MailCatcher: http://localhost:1080" + echo -e "\n${YELLOW}To view logs: $0 logs${NC}" + ;; + + stop) + echo -e "${YELLOW}Stopping all services...${NC}" + docker compose -f $COMPOSE_FILE stop + echo -e "${GREEN}Services stopped.${NC}" + ;; + + restart) + echo -e "${YELLOW}Restarting all services...${NC}" + docker compose -f $COMPOSE_FILE restart + echo -e "${GREEN}Services restarted.${NC}" + ;; + + logs) + docker compose -f $COMPOSE_FILE logs -f + ;; + + logs-app) + docker compose -f $COMPOSE_FILE logs -f monarc + ;; + + logs-stats) + docker compose -f $COMPOSE_FILE logs -f stats-service + ;; + + shell) + echo -e "${GREEN}Opening shell in MONARC container...${NC}" + docker exec -it monarc-fo-app bash + ;; + + shell-stats) + echo -e "${GREEN}Opening shell in stats service container...${NC}" + docker exec -it monarc-fo-stats bash + ;; + + db) + echo -e "${GREEN}Opening MySQL client...${NC}" + docker exec -it monarc-fo-db mysql -usqlmonarcuser -psqlmonarcuser monarc_common + ;; + + reset) + echo -e "${RED}WARNING: This will remove all data!${NC}" + read -p "Are you sure? (yes/no): " confirm + if [ "$confirm" = "yes" ]; then + echo -e "${YELLOW}Stopping and removing all containers, volumes, and data...${NC}" + docker compose -f $COMPOSE_FILE down -v + echo -e "${GREEN}Reset complete. Run '$0 start' to start fresh.${NC}" + else + echo -e "${GREEN}Reset cancelled.${NC}" + fi + ;; + + status) + docker compose -f $COMPOSE_FILE ps + ;; + + stats-key) + echo -e "${GREEN}Retrieving stats API key...${NC}" + docker compose -f $COMPOSE_FILE logs stats-service | grep "Token:" | tail -1 + echo -e "\n${YELLOW}Note: Update this key in your .env file and restart MONARC service:${NC}" + echo -e " 1. Edit .env and set STATS_API_KEY=" + echo -e " 2. Run: docker compose -f $COMPOSE_FILE restart monarc" + ;; + + *) + usage + exit 1 + ;; +esac From e6bd605f6b7467349bee2a50c35bba414a561485 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 12 Jan 2026 16:29:13 +0000 Subject: [PATCH 5/7] Update main README and add Docker installation guide Co-authored-by: ruslanbaidan <3246171+ruslanbaidan@users.noreply.github.com> --- INSTALL/INSTALL.docker.md | 186 ++++++++++++++++++++++++++++++++++++++ README.md | 16 ++++ 2 files changed, 202 insertions(+) create mode 100644 INSTALL/INSTALL.docker.md diff --git a/INSTALL/INSTALL.docker.md b/INSTALL/INSTALL.docker.md new file mode 100644 index 0000000..7c9bddc --- /dev/null +++ b/INSTALL/INSTALL.docker.md @@ -0,0 +1,186 @@ +# Docker Installation Guide for MONARC FrontOffice + +This document provides installation instructions for setting up MONARC FrontOffice using Docker for development purposes. + +## Quick Installation + +```bash +# Clone the repository +git clone https://github.com/monarc-project/MonarcAppFO +cd MonarcAppFO + +# Start with the helper script (recommended) +./docker-dev.sh start + +# Or use docker-compose directly +cp .env.dev .env +docker compose -f docker-compose.dev.yml up -d --build +``` + +## What Gets Installed + +The Docker setup includes: + +1. **MONARC FrontOffice Application** + - Ubuntu 22.04 base + - PHP 8.1 with all required extensions + - Apache web server + - Composer for PHP dependencies + - Node.js for frontend + - All MONARC modules and dependencies + +2. **MariaDB 10.11** + - Database for MONARC application data + - Pre-configured with proper character sets + +3. **PostgreSQL 15** + - Database for the statistics service + +4. **Stats Service** + - Python/Flask application + - Poetry for dependency management + - Integrated with MONARC FrontOffice + +5. **MailCatcher** + - Email testing interface + - SMTP server for development + +## First Time Setup + +When you start the environment for the first time: + +1. Docker images will be built (5-10 minutes) +2. Dependencies will be installed automatically +3. Databases will be created and initialized +4. Frontend repositories will be cloned and built +5. Initial admin user will be created + +## Access URLs + +After startup, access the application at: + +- **MONARC FrontOffice**: http://localhost:5001 +- **Stats Service**: http://localhost:5005 +- **MailCatcher**: http://localhost:1080 + +## Default Credentials + +- **Username**: admin@admin.localhost +- **Password**: admin + +⚠️ **Security Warning**: Change these credentials before deploying to production! + +## System Requirements + +- Docker Engine 20.10 or later +- Docker Compose V2 +- At least 8GB RAM available for Docker +- At least 20GB free disk space +- Linux, macOS, or Windows with WSL2 + +## Configuration + +Environment variables are defined in the `.env` file (copied from `.env.dev`): + +- Database credentials +- Service ports +- Secret keys + +You can customize these before starting the environment. + +## Troubleshooting + +### Port Conflicts + +If ports 5001, 5005, 3306, 5432, or 1080 are already in use: + +1. Edit `docker-compose.dev.yml` +2. Change the host port (left side of the port mapping) +3. Example: Change `"5001:80"` to `"8001:80"` + +### Permission Issues + +If you encounter permission errors: + +```bash +docker exec -it monarc-fo-app bash +chown -R www-data:www-data /var/www/html/monarc/data +chmod -R 775 /var/www/html/monarc/data +``` + +### Service Not Starting + +Check the logs: + +```bash +./docker-dev.sh logs +# or +docker compose -f docker-compose.dev.yml logs +``` + +### Reset Everything + +To start completely fresh: + +```bash +./docker-dev.sh reset +# or +docker compose -f docker-compose.dev.yml down -v +``` + +## Common Tasks + +### View Logs +```bash +./docker-dev.sh logs +``` + +### Access Container Shell +```bash +./docker-dev.sh shell +``` + +### Access Database +```bash +./docker-dev.sh db +``` + +### Stop Services +```bash +./docker-dev.sh stop +``` + +### Restart Services +```bash +./docker-dev.sh restart +``` + +## Comparison with Other Installation Methods + +| Method | Complexity | Time | Best For | +|--------|-----------|------|----------| +| Docker | Low | Fast (2-5 min startup) | Development | +| Vagrant | Medium | Slow (10-15 min startup) | Development | +| Manual | High | Slow (30+ min) | Production | +| VM | Low | Medium | Testing | + +## Next Steps + +After installation: + +1. Read the [full Docker documentation](README.docker.md) +2. Review the [MONARC documentation](https://www.monarc.lu/documentation) +3. Configure the stats API key (optional) +4. Start developing! + +## Getting Help + +- **Documentation**: [README.docker.md](README.docker.md) +- **MONARC Website**: https://www.monarc.lu +- **GitHub Issues**: https://github.com/monarc-project/MonarcAppFO/issues +- **Community**: https://www.monarc.lu/community + +## License + +This project is licensed under the GNU Affero General Public License version 3. +See [LICENSE](LICENSE) for details. diff --git a/README.md b/README.md index 21a8a85..ffdbdf6 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,22 @@ For installation instructions see You can also use the provided [Virtual Machine](https://vm.monarc.lu). +Development Environment +----------------------- + +For local development, you can use either: + +- **Docker** (recommended): See [README.docker.md](README.docker.md) for instructions + ```bash + ./docker-dev.sh start + ``` + +- **Vagrant**: See [vagrant/README.rst](vagrant/README.rst) for instructions + ```bash + cd vagrant && vagrant up + ``` + + Contributing ------------ From 27b38321d190139644cfb963083b0b27466b4bff Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 12 Jan 2026 16:31:29 +0000 Subject: [PATCH 6/7] Address code review feedback - fix Poetry flag, quoting, and unused file Co-authored-by: ruslanbaidan <3246171+ruslanbaidan@users.noreply.github.com> --- docker-dev.sh | 20 ++++++++++---------- docker-entrypoint.sh | 2 +- docker-stats-entrypoint.sh | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docker-dev.sh b/docker-dev.sh index 42f21f5..c55b340 100755 --- a/docker-dev.sh +++ b/docker-dev.sh @@ -44,7 +44,7 @@ case "$1" in start) check_env echo -e "${GREEN}Starting MONARC development environment...${NC}" - docker compose -f $COMPOSE_FILE up -d --build + docker compose -f "$COMPOSE_FILE" up -d --build echo -e "${GREEN}Services started!${NC}" echo -e "MONARC FrontOffice: http://localhost:5001" echo -e "Stats Service: http://localhost:5005" @@ -54,26 +54,26 @@ case "$1" in stop) echo -e "${YELLOW}Stopping all services...${NC}" - docker compose -f $COMPOSE_FILE stop + docker compose -f "$COMPOSE_FILE" stop echo -e "${GREEN}Services stopped.${NC}" ;; restart) echo -e "${YELLOW}Restarting all services...${NC}" - docker compose -f $COMPOSE_FILE restart + docker compose -f "$COMPOSE_FILE" restart echo -e "${GREEN}Services restarted.${NC}" ;; logs) - docker compose -f $COMPOSE_FILE logs -f + docker compose -f "$COMPOSE_FILE" logs -f ;; logs-app) - docker compose -f $COMPOSE_FILE logs -f monarc + docker compose -f "$COMPOSE_FILE" logs -f monarc ;; logs-stats) - docker compose -f $COMPOSE_FILE logs -f stats-service + docker compose -f "$COMPOSE_FILE" logs -f stats-service ;; shell) @@ -96,7 +96,7 @@ case "$1" in read -p "Are you sure? (yes/no): " confirm if [ "$confirm" = "yes" ]; then echo -e "${YELLOW}Stopping and removing all containers, volumes, and data...${NC}" - docker compose -f $COMPOSE_FILE down -v + docker compose -f "$COMPOSE_FILE" down -v echo -e "${GREEN}Reset complete. Run '$0 start' to start fresh.${NC}" else echo -e "${GREEN}Reset cancelled.${NC}" @@ -104,15 +104,15 @@ case "$1" in ;; status) - docker compose -f $COMPOSE_FILE ps + docker compose -f "$COMPOSE_FILE" ps ;; stats-key) echo -e "${GREEN}Retrieving stats API key...${NC}" - docker compose -f $COMPOSE_FILE logs stats-service | grep "Token:" | tail -1 + docker compose -f "$COMPOSE_FILE" logs stats-service | grep "Token:" | tail -1 echo -e "\n${YELLOW}Note: Update this key in your .env file and restart MONARC service:${NC}" echo -e " 1. Edit .env and set STATS_API_KEY=" - echo -e " 2. Run: docker compose -f $COMPOSE_FILE restart monarc" + echo -e " 2. Run: docker compose -f \"\$COMPOSE_FILE\" restart monarc" ;; *) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 2c836c2..b914616 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -125,7 +125,7 @@ return [ ], 'import' => [ - 'uploadFolder' => '\$appdir/data/import/files', + 'uploadFolder' => '$appdir/data/import/files', 'isBackgroundProcessActive' => false, ], ]; diff --git a/docker-stats-entrypoint.sh b/docker-stats-entrypoint.sh index cd6cb12..7127751 100755 --- a/docker-stats-entrypoint.sh +++ b/docker-stats-entrypoint.sh @@ -36,7 +36,7 @@ if [ ! -f "/var/www/stats-service/.docker-initialized" ]; then # Install Python dependencies with Poetry echo -e "${YELLOW}Installing Python dependencies with Poetry...${NC}" - poetry install --no-dev + poetry install --only=main # Create instance directory and configuration echo -e "${YELLOW}Creating configuration...${NC}" @@ -83,7 +83,7 @@ EOF # Create client for MONARC and capture the API key echo -e "${YELLOW}Creating MONARC client...${NC}" - poetry run flask client_create --name admin_localhost | tee /tmp/client_output.txt + poetry run flask client_create --name admin_localhost # Mark initialization as complete touch /var/www/stats-service/.docker-initialized From 1126e90c84af153ac6a873b74c5fe0b5dbfdf76b Mon Sep 17 00:00:00 2001 From: Ruslan Baidan Date: Fri, 16 Jan 2026 19:48:43 +0100 Subject: [PATCH 7/7] Fixed the docker run and made it possible to use the BackOffice common DB. --- .env.dev | 20 +++++ .gitignore | 2 + Dockerfile | 66 +++++++------- INSTALL/INSTALL.docker.md | 24 ++--- Makefile | 104 ++++++++++++++++++++++ README.docker.md | 151 ++++++++++++++++++++------------ README.md | 2 +- docker-compose.dev.yml | 118 ++++++++++++++----------- docker-dev.sh | 122 -------------------------- docker-entrypoint.sh | 103 ++++++++++++++-------- docker/db-init/10-dev-grants.sh | 12 +++ 11 files changed, 413 insertions(+), 311 deletions(-) create mode 100644 Makefile delete mode 100755 docker-dev.sh create mode 100644 docker/db-init/10-dev-grants.sh diff --git a/.env.dev b/.env.dev index 049c9ba..1981b09 100644 --- a/.env.dev +++ b/.env.dev @@ -1,9 +1,29 @@ # MariaDB Configuration +DBHOST=fodb +DBPORT_HOST=3307 DBPASSWORD_ADMIN=root DBNAME_COMMON=monarc_common DBNAME_CLI=monarc_cli DBUSER_MONARC=sqlmonarcuser DBPASSWORD_MONARC=sqlmonarcuser +# Set USE_BO_COMMON=1 and DBHOST to the BackOffice DB host to reuse monarc_common. +USE_BO_COMMON=1 + +# Shared Docker network name (must exist when using external network) +MONARC_NETWORK_NAME=monarc-network + +# Node.js major version for frontend build tooling +NODE_MAJOR=16 + +# Optional: set to 0/false/no to disable Xdebug in the image build +XDEBUG_ENABLED=1 +XDEBUG_MODE=debug +XDEBUG_START_WITH_REQUEST=trigger +# On Linux, set XDEBUG_CLIENT_HOST to your Docker bridge (often 172.17.0.1). +XDEBUG_CLIENT_HOST=host.docker.internal +XDEBUG_CLIENT_PORT=9003 +XDEBUG_IDEKEY=IDEKEY +XDEBUG_DISCOVER_CLIENT_HOST=0 # Stats Service Configuration STATS_HOST=0.0.0.0 diff --git a/.gitignore b/.gitignore index c2db730..606ef8d 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,5 @@ data/* .docker/mariaDb/data/* .env .docker-initialized +docker/db_data +.vscode diff --git a/Dockerfile b/Dockerfile index ad70470..27e423b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,14 @@ FROM ubuntu:22.04 +ARG XDEBUG_ENABLED=1 +ARG XDEBUG_MODE=debug +ARG XDEBUG_START_WITH_REQUEST=trigger +ARG XDEBUG_CLIENT_HOST=host.docker.internal +ARG XDEBUG_CLIENT_PORT=9003 +ARG XDEBUG_IDEKEY=IDEKEY +ARG XDEBUG_DISCOVER_CLIENT_HOST=0 +ARG NODE_MAJOR=16 + # Prevent interactive prompts during package installation ENV DEBIAN_FRONTEND=noninteractive ENV LANGUAGE=en_US.UTF-8 @@ -8,33 +17,15 @@ ENV LC_ALL=en_US.UTF-8 # Install system dependencies RUN apt-get update && apt-get upgrade -y && \ - apt-get install -y \ - vim \ - zip \ - unzip \ - git \ - gettext \ - curl \ - gsfonts \ - mariadb-client \ - apache2 \ - php8.1 \ - php8.1-cli \ - php8.1-common \ - php8.1-mysql \ - php8.1-zip \ - php8.1-gd \ - php8.1-mbstring \ - php8.1-curl \ - php8.1-xml \ - php8.1-bcmath \ - php8.1-intl \ - php8.1-imagick \ - php8.1-xdebug \ - locales \ - wget \ - ca-certificates \ - gnupg && \ + packages="vim zip unzip git gettext curl gsfonts mariadb-client apache2 php8.1 php8.1-cli \ + php8.1-common php8.1-mysql php8.1-zip php8.1-gd php8.1-mbstring php8.1-curl php8.1-xml \ + php8.1-bcmath php8.1-intl php8.1-imagick locales wget ca-certificates gnupg \ + build-essential python3 pkg-config libcairo2-dev libpango1.0-dev libjpeg-dev \ + libgif-dev librsvg2-dev libpixman-1-dev"; \ + if [ "$XDEBUG_ENABLED" = "1" ] || [ "$XDEBUG_ENABLED" = "true" ] || [ "$XDEBUG_ENABLED" = "yes" ]; then \ + packages="$packages php8.1-xdebug"; \ + fi; \ + apt-get install -y $packages && \ locale-gen en_US.UTF-8 && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* @@ -50,23 +41,32 @@ RUN sed -i 's/upload_max_filesize = .*/upload_max_filesize = 200M/' /etc/php/8.1 sed -i 's/session\.gc_divisor = .*/session.gc_divisor = 1000/' /etc/php/8.1/apache2/php.ini # Configure Xdebug for development -RUN echo "zend_extension=xdebug.so" > /etc/php/8.1/apache2/conf.d/20-xdebug.ini && \ - echo "xdebug.mode=debug" >> /etc/php/8.1/apache2/conf.d/20-xdebug.ini && \ - echo "xdebug.discover_client_host=1" >> /etc/php/8.1/apache2/conf.d/20-xdebug.ini && \ - echo "xdebug.idekey=IDEKEY" >> /etc/php/8.1/apache2/conf.d/20-xdebug.ini +RUN if [ "$XDEBUG_ENABLED" = "1" ] || [ "$XDEBUG_ENABLED" = "true" ] || [ "$XDEBUG_ENABLED" = "yes" ]; then \ + echo "zend_extension=xdebug.so" > /etc/php/8.1/apache2/conf.d/20-xdebug.ini && \ + echo "xdebug.mode=${XDEBUG_MODE}" >> /etc/php/8.1/apache2/conf.d/20-xdebug.ini && \ + echo "xdebug.start_with_request=${XDEBUG_START_WITH_REQUEST}" >> /etc/php/8.1/apache2/conf.d/20-xdebug.ini && \ + echo "xdebug.client_host=${XDEBUG_CLIENT_HOST}" >> /etc/php/8.1/apache2/conf.d/20-xdebug.ini && \ + echo "xdebug.client_port=${XDEBUG_CLIENT_PORT}" >> /etc/php/8.1/apache2/conf.d/20-xdebug.ini && \ + echo "xdebug.discover_client_host=${XDEBUG_DISCOVER_CLIENT_HOST}" >> /etc/php/8.1/apache2/conf.d/20-xdebug.ini && \ + echo "xdebug.idekey=${XDEBUG_IDEKEY}" >> /etc/php/8.1/apache2/conf.d/20-xdebug.ini; \ + fi # Enable Apache modules RUN a2enmod rewrite ssl headers +# Set global ServerName to avoid AH00558 warning +RUN echo "ServerName localhost" > /etc/apache2/conf-available/servername.conf \ + && a2enconf servername + # Install Composer RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer # Install Node.js and npm RUN mkdir -p /etc/apt/keyrings && \ curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ - echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_15.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \ + echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \ apt-get update && \ - apt-get install -y nodejs npm && \ + apt-get install -y nodejs && \ npm install -g grunt-cli && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* diff --git a/INSTALL/INSTALL.docker.md b/INSTALL/INSTALL.docker.md index 7c9bddc..365bcd1 100644 --- a/INSTALL/INSTALL.docker.md +++ b/INSTALL/INSTALL.docker.md @@ -9,10 +9,10 @@ This document provides installation instructions for setting up MONARC FrontOffi git clone https://github.com/monarc-project/MonarcAppFO cd MonarcAppFO -# Start with the helper script (recommended) -./docker-dev.sh start +# Start with the Makefile (recommended) +make start -# Or use docker-compose directly +# Or use docker compose directly cp .env.dev .env docker compose -f docker-compose.dev.yml up -d --build ``` @@ -92,12 +92,14 @@ You can customize these before starting the environment. ### Port Conflicts -If ports 5001, 5005, 3306, 5432, or 1080 are already in use: +If ports 5001, 5005, 3307, 5432, or 1080 are already in use: 1. Edit `docker-compose.dev.yml` 2. Change the host port (left side of the port mapping) 3. Example: Change `"5001:80"` to `"8001:80"` +You can also change the MariaDB host port by setting `DBPORT_HOST` in `.env`. + ### Permission Issues If you encounter permission errors: @@ -113,7 +115,7 @@ chmod -R 775 /var/www/html/monarc/data Check the logs: ```bash -./docker-dev.sh logs +make logs # or docker compose -f docker-compose.dev.yml logs ``` @@ -123,7 +125,7 @@ docker compose -f docker-compose.dev.yml logs To start completely fresh: ```bash -./docker-dev.sh reset +make reset # or docker compose -f docker-compose.dev.yml down -v ``` @@ -132,27 +134,27 @@ docker compose -f docker-compose.dev.yml down -v ### View Logs ```bash -./docker-dev.sh logs +make logs ``` ### Access Container Shell ```bash -./docker-dev.sh shell +make shell ``` ### Access Database ```bash -./docker-dev.sh db +make db ``` ### Stop Services ```bash -./docker-dev.sh stop +make stop ``` ### Restart Services ```bash -./docker-dev.sh restart +make restart ``` ## Comparison with Other Installation Methods diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..551882a --- /dev/null +++ b/Makefile @@ -0,0 +1,104 @@ +.DEFAULT_GOAL := help + +SHELL := /bin/bash + +ENV ?= dev +COMPOSE_FILE ?= docker-compose.$(ENV).yml +COMPOSE := docker compose -f $(COMPOSE_FILE) + +GREEN := \033[0;32m +YELLOW := \033[1;33m +RED := \033[0;31m +NC := \033[0m + +.PHONY: help check-env start stop restart logs logs-app logs-stats shell shell-stats db reset status stats-key + +help: + @printf "%b\n" "$(GREEN)MONARC FrontOffice Docker Development Environment Manager$(NC)" + @printf "\n%b\n" "Usage: make " + @printf "%b\n" "Environment: ENV= (default: dev, uses docker-compose..yml)" + @printf "\n%b\n" "Commands:" + @printf " %-12s %s\n" "start" "Start all services (builds on first run)" + @printf " %-12s %s\n" "stop" "Stop all services" + @printf " %-12s %s\n" "restart" "Restart all services" + @printf " %-12s %s\n" "logs" "View logs from all services" + @printf " %-12s %s\n" "logs-app" "View logs from MONARC application" + @printf " %-12s %s\n" "logs-stats" "View logs from stats service" + @printf " %-12s %s\n" "shell" "Open a shell in the MONARC container" + @printf " %-12s %s\n" "shell-stats" "Open a shell in the stats service container" + @printf " %-12s %s\n" "db" "Open MySQL client in the database" + @printf " %-12s %s\n" "stats-key" "Show the stats API key" + @printf " %-12s %s\n" "reset" "Reset everything (removes all data)" + @printf " %-12s %s\n" "status" "Show status of all services" + +check-env: + @if [ ! -f .env ]; then \ + printf "%b\n" "$(YELLOW)No .env file found. Creating from .env.dev...$(NC)"; \ + cp .env.dev .env; \ + printf "%b\n" "$(GREEN).env file created. You can edit it to customize configuration.$(NC)"; \ + fi + +start: check-env + @printf "%b\n" "$(GREEN)Starting MONARC FrontOffice development environment...$(NC)" + @$(COMPOSE) up -d --build + @printf "%b\n" "$(GREEN)Services started!$(NC)" + @printf "%b\n" "MONARC FrontOffice: http://localhost:5001" + @printf "%b\n" "Stats Service: http://localhost:5005" + @printf "%b\n" "MailCatcher: http://localhost:1080" + @printf "\n%b\n" "$(YELLOW)To view logs: make logs ENV=$(ENV)$(NC)" + +stop: + @printf "%b\n" "$(YELLOW)Stopping all services...$(NC)" + @$(COMPOSE) stop + @printf "%b\n" "$(GREEN)Services stopped.$(NC)" + +restart: + @printf "%b\n" "$(YELLOW)Restarting all services...$(NC)" + @$(COMPOSE) restart + @printf "%b\n" "$(GREEN)Services restarted.$(NC)" + +logs: + @$(COMPOSE) logs -f + +logs-app: + @$(COMPOSE) logs -f monarc + +logs-stats: + @$(COMPOSE) logs -f stats-service + +shell: + @printf "%b\n" "$(GREEN)Opening shell in MONARC container...$(NC)" + @docker exec -it monarc-fo-app bash + +shell-stats: + @printf "%b\n" "$(GREEN)Opening shell in stats service container...$(NC)" + @docker exec -it monarc-fo-stats bash + +db: + @printf "%b\n" "$(GREEN)Opening MySQL client...$(NC)" + @if [ -f .env ]; then \ + export $$(grep -v '^#' .env | xargs); \ + fi; \ + export MYSQL_PWD="$${DBPASSWORD_MONARC:-sqlmonarcuser}"; \ + docker exec -it monarc-fo-db mysql -u"$${DBUSER_MONARC:-sqlmonarcuser}" "$${DBNAME_COMMON:-monarc_common}" + +stats-key: + @printf "%b\n" "$(GREEN)Retrieving stats API key...$(NC)" + @$(COMPOSE) logs stats-service | grep "Token:" | tail -1 + @printf "\n%b\n" "$(YELLOW)Note: Update this key in your .env file and restart MONARC service:$(NC)" + @printf "%b\n" " 1. Edit .env and set STATS_API_KEY=" + @printf "%b\n" " 2. Run: docker compose -f \"$(COMPOSE_FILE)\" restart monarc" + +reset: + @printf "%b\n" "$(RED)WARNING: This will remove all data!$(NC)"; \ + read -p "Are you sure? (yes/no): " confirm; \ + if [ "$$confirm" = "yes" ]; then \ + printf "%b\n" "$(YELLOW)Stopping and removing all containers, volumes, and data...$(NC)"; \ + $(COMPOSE) down -v; \ + printf "%b\n" "$(GREEN)Reset complete. Run 'make start' to start fresh.$(NC)"; \ + else \ + printf "%b\n" "$(GREEN)Reset cancelled.$(NC)"; \ + fi + +status: + @$(COMPOSE) ps diff --git a/README.docker.md b/README.docker.md index 95cab6d..1c5ceac 100644 --- a/README.docker.md +++ b/README.docker.md @@ -11,7 +11,7 @@ This guide explains how to set up a local development environment for MONARC Fro ## Quick Start -### Option 1: Using the Helper Script (Recommended) +### Option 1: Using the Makefile (Recommended) 1. **Clone the repository** (if you haven't already): ```bash @@ -21,7 +21,7 @@ This guide explains how to set up a local development environment for MONARC Fro 2. **Start the development environment**: ```bash - ./docker-dev.sh start + make start ``` This will automatically: @@ -69,7 +69,7 @@ This guide explains how to set up a local development environment for MONARC Fro 4. **Start the development environment**: ```bash - docker-compose -f docker-compose.dev.yml up --build + docker compose -f docker-compose.dev.yml up --build ``` 5. **Access the application**: @@ -80,17 +80,17 @@ This guide explains how to set up a local development environment for MONARC Fro 6. **(Optional) Configure Stats API Key**: The stats service generates an API key on first run. To retrieve it: ```bash - # Using helper script - ./docker-dev.sh stats-key + # Using Makefile + make stats-key # Or manually check logs - docker-compose -f docker-compose.dev.yml logs stats-service | grep "Token:" + docker compose -f docker-compose.dev.yml logs stats-service | grep "Token:" # Or create a new client and get the key docker exec -it monarc-fo-stats poetry run flask client_create --name monarc # Update the .env file with the API key and restart the monarc service - docker-compose -f docker-compose.dev.yml restart monarc + docker compose -f docker-compose.dev.yml restart monarc ``` 7. **Login credentials**: @@ -104,30 +104,31 @@ The development environment includes the following services: | Service | Description | Port | Container Name | |---------|-------------|------|----------------| | monarc | Main FrontOffice application (PHP/Apache) | 5001 | monarc-fo-app | -| db | MariaDB database | 3306 | monarc-fo-db | +| db | MariaDB database | 3307 | monarc-fo-db | | postgres | PostgreSQL database (for stats) | 5432 | monarc-fo-postgres | | stats-service | MONARC Statistics Service | 5005 | monarc-fo-stats | | mailcatcher | Email testing tool | 1080 (web), 1025 (SMTP) | monarc-fo-mailcatcher | ## Development Workflow -### Helper Script Commands +### Makefile Commands -The `docker-dev.sh` script provides convenient commands for managing the development environment: +The Makefile provides convenient commands for managing the development environment. +Use `ENV=` to select `docker compose..yml` (default: `dev`). ```bash -./docker-dev.sh start # Start all services -./docker-dev.sh stop # Stop all services -./docker-dev.sh restart # Restart all services -./docker-dev.sh logs # View logs from all services -./docker-dev.sh logs-app # View logs from MONARC application -./docker-dev.sh logs-stats # View logs from stats service -./docker-dev.sh shell # Open a shell in the MONARC container -./docker-dev.sh shell-stats # Open a shell in the stats service container -./docker-dev.sh db # Open MySQL client -./docker-dev.sh status # Show status of all services -./docker-dev.sh stats-key # Show the stats API key -./docker-dev.sh reset # Reset everything (removes all data) +make start # Start all services +make stop # Stop all services +make restart # Restart all services +make logs # View logs from all services +make logs-app # View logs from MONARC application +make logs-stats # View logs from stats service +make shell # Open a shell in the MONARC container +make shell-stats # Open a shell in the stats service container +make db # Open MySQL client +make status # Show status of all services +make stats-key # Show the stats API key +make reset # Reset everything (removes all data) ``` ### Live Code Editing @@ -144,10 +145,10 @@ The application source code is mounted as a volume, so changes you make on your ### Accessing the Container -Using helper script: +Using Makefile: ```bash -./docker-dev.sh shell # MONARC application -./docker-dev.sh shell-stats # Stats service +make shell # MONARC application +make shell-stats # Stats service ``` Or directly with docker: @@ -158,9 +159,9 @@ docker exec -it monarc-fo-stats bash # Stats service ### Database Access -Using helper script: +Using Makefile: ```bash -./docker-dev.sh db # Connect to MariaDB +make db # Connect to MariaDB ``` Or directly with docker: @@ -174,67 +175,83 @@ docker exec -it monarc-fo-postgres psql -U sqlmonarcuser -d statsservice ### Viewing Logs -Using helper script: +Using Makefile: ```bash -./docker-dev.sh logs # All services -./docker-dev.sh logs-app # MONARC application only -./docker-dev.sh logs-stats # Stats service only +make logs # All services +make logs-app # MONARC application only +make logs-stats # Stats service only ``` Or directly with docker compose: ```bash # View logs for all services -docker-compose -f docker-compose.dev.yml logs -f +docker compose -f docker-compose.dev.yml logs -f # View logs for a specific service -docker-compose -f docker-compose.dev.yml logs -f monarc -docker-compose -f docker-compose.dev.yml logs -f stats-service +docker compose -f docker-compose.dev.yml logs -f monarc +docker compose -f docker-compose.dev.yml logs -f stats-service ``` ### Restarting Services -Using helper script: +Using Makefile: ```bash -./docker-dev.sh restart # Restart all services +make restart # Restart all services ``` Or directly with docker compose: ```bash # Restart all services -docker-compose -f docker-compose.dev.yml restart +docker compose -f docker-compose.dev.yml restart # Restart a specific service -docker-compose -f docker-compose.dev.yml restart monarc +docker compose -f docker-compose.dev.yml restart monarc ``` ### Stopping the Environment -Using helper script: +Using Makefile: ```bash -./docker-dev.sh stop # Stop all services (keeps data) -./docker-dev.sh reset # Stop and remove everything including data +make stop # Stop all services (keeps data) +make reset # Stop and remove everything including data ``` Or directly with docker compose: ```bash # Stop all services (keeps data) -docker-compose -f docker-compose.dev.yml stop +docker compose -f docker-compose.dev.yml stop # Stop and remove containers (keeps volumes/data) -docker-compose -f docker-compose.dev.yml down +docker compose -f docker-compose.dev.yml down # Stop and remove everything including data -docker-compose -f docker-compose.dev.yml down -v +docker compose -f docker-compose.dev.yml down -v ``` ## Common Tasks +### Using BackOffice monarc_common + +To reuse the BackOffice `monarc_common` database: + +1. Set `USE_BO_COMMON=1` in `.env`. +2. Point `DBHOST` to the BackOffice MariaDB host (for example, `monarc-bo-db` on a shared Docker network). +3. Ensure the BackOffice database already has `monarc_common` and grants for `DBUSER_MONARC`. + +### Shared Docker Network + +To connect FrontOffice and BackOffice containers, use a shared external network: + +1. Create the network once: `docker network create monarc-network` +2. Set `MONARC_NETWORK_NAME=monarc-network` in both projects' `.env` files. +3. Ensure the BackOffice compose file also uses the same external network name. + ### Resetting the Database To completely reset the databases: ```bash -docker-compose -f docker-compose.dev.yml down -v -docker-compose -f docker-compose.dev.yml up --build +docker compose -f docker-compose.dev.yml down -v +docker compose -f docker-compose.dev.yml up --build ``` ### Installing New PHP Dependencies @@ -263,7 +280,7 @@ php ./vendor/robmorgan/phinx/bin/phinx migrate -c ./module/Monarc/FrontOffice/mi ```bash docker exec -it monarc-fo-app bash -php ./bin/phinx seed:run -c ./module/Monarc/FrontOffice/migrations/phinx.php +php ./vendor/robmorgan/phinx/bin/phinx seed:run -c ./module/Monarc/FrontOffice/migrations/phinx.php ``` ### Rebuilding Frontend @@ -278,7 +295,12 @@ cd /var/www/html/monarc ### Xdebug Configuration -Xdebug is pre-configured in the development environment. To use it: +Xdebug is enabled by default in the development image. To disable it, set +`XDEBUG_ENABLED=0` in `.env` and rebuild the image (for example, `make start`). +You can also tune the connection behavior via `.env`: +`XDEBUG_START_WITH_REQUEST`, `XDEBUG_CLIENT_HOST`, and `XDEBUG_CLIENT_PORT`. + +When enabled, Xdebug is pre-configured. To use it: 1. Configure your IDE to listen on port 9003 2. Set the IDE key to `IDEKEY` @@ -295,10 +317,10 @@ For PhpStorm: ```bash # Check if all services are running -docker-compose -f docker-compose.dev.yml ps +docker compose -f docker-compose.dev.yml ps # Check specific service health -docker-compose -f docker-compose.dev.yml ps monarc +docker compose -f docker-compose.dev.yml ps monarc ``` ## Troubleshooting @@ -311,6 +333,9 @@ ports: - "5001:80" # Change 5001 to another available port ``` +To change the MariaDB host port without editing the compose file, set +`DBPORT_HOST` in `.env` (default: `3307`). + ### Permission Issues If you encounter permission issues with mounted volumes: @@ -324,24 +349,24 @@ chmod -R 775 /var/www/html/monarc/data Check if the database is healthy: ```bash -docker-compose -f docker-compose.dev.yml ps db +docker compose -f docker-compose.dev.yml ps db ``` If needed, restart the database: ```bash -docker-compose -f docker-compose.dev.yml restart db +docker compose -f docker-compose.dev.yml restart db ``` ### Stats Service Issues Check stats service logs: ```bash -docker-compose -f docker-compose.dev.yml logs stats-service +docker compose -f docker-compose.dev.yml logs stats-service ``` Restart the stats service: ```bash -docker-compose -f docker-compose.dev.yml restart stats-service +docker compose -f docker-compose.dev.yml restart stats-service ``` ### Rebuilding from Scratch @@ -349,13 +374,13 @@ docker-compose -f docker-compose.dev.yml restart stats-service If something goes wrong and you want to start fresh: ```bash # Stop everything -docker-compose -f docker-compose.dev.yml down -v +docker compose -f docker-compose.dev.yml down -v # Remove all related containers, images, and volumes docker system prune -a # Rebuild and start -docker-compose -f docker-compose.dev.yml up --build +docker compose -f docker-compose.dev.yml up --build ``` ## Performance Optimization @@ -388,17 +413,29 @@ All environment variables are defined in the `.env` file: | Variable | Description | Default | |----------|-------------|---------| +| `DBHOST` | MariaDB host for MONARC | `db` | +| `DBPORT_HOST` | MariaDB host port (published) | `3307` | | `DBPASSWORD_ADMIN` | MariaDB root password | `root` | | `DBNAME_COMMON` | Common database name | `monarc_common` | | `DBNAME_CLI` | CLI database name | `monarc_cli` | | `DBUSER_MONARC` | Database user | `sqlmonarcuser` | | `DBPASSWORD_MONARC` | Database password | `sqlmonarcuser` | +| `USE_BO_COMMON` | Use BackOffice `monarc_common` (`1/0`, `true/false`, `yes/no`) | `0` | +| `MONARC_NETWORK_NAME` | Shared Docker network name | `monarc-network` | +| `NODE_MAJOR` | Node.js major version for frontend tools | `16` | | `STATS_HOST` | Stats service host | `0.0.0.0` | | `STATS_PORT` | Stats service port | `5005` | | `STATS_DB_NAME` | Stats database name | `statsservice` | | `STATS_DB_USER` | Stats database user | `sqlmonarcuser` | | `STATS_DB_PASSWORD` | Stats database password | `sqlmonarcuser` | | `STATS_SECRET_KEY` | Stats service secret key | `changeme_generate_random_secret_key_for_production` | +| `XDEBUG_ENABLED` | Enable Xdebug in the build (`1/0`, `true/false`, `yes/no`) | `1` | +| `XDEBUG_MODE` | Xdebug modes (`debug`, `develop`, etc.) | `debug` | +| `XDEBUG_START_WITH_REQUEST` | Start mode (`trigger` or `yes`) | `trigger` | +| `XDEBUG_CLIENT_HOST` | Host IDE address | `host.docker.internal` | +| `XDEBUG_CLIENT_PORT` | IDE port | `9003` | +| `XDEBUG_IDEKEY` | IDE key | `IDEKEY` | +| `XDEBUG_DISCOVER_CLIENT_HOST` | Auto-detect client host (`1/0`) | `0` | ## Security Notes @@ -422,6 +459,6 @@ For production deployments: If you encounter issues: 1. Check the [troubleshooting section](#troubleshooting) -2. Review the logs: `docker-compose -f docker-compose.dev.yml logs` +2. Review the logs: `docker compose -f docker-compose.dev.yml logs` 3. Open an issue on [GitHub](https://github.com/monarc-project/MonarcAppFO/issues) 4. Join the MONARC community discussions diff --git a/README.md b/README.md index ffdbdf6..4e35f9e 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ For local development, you can use either: - **Docker** (recommended): See [README.docker.md](README.docker.md) for instructions ```bash - ./docker-dev.sh start + make start ``` - **Vagrant**: See [vagrant/README.rst](vagrant/README.rst) for instructions diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 0941b81..26c562a 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -1,6 +1,6 @@ services: # MariaDB database for MONARC - db: + fodb: image: mariadb:10.11 container_name: monarc-fo-db environment: @@ -8,14 +8,15 @@ services: MYSQL_DATABASE: ${DBNAME_COMMON} MYSQL_USER: ${DBUSER_MONARC} MYSQL_PASSWORD: ${DBPASSWORD_MONARC} - command: + command: - --character-set-server=utf8mb4 - --collation-server=utf8mb4_general_ci - --bind-address=0.0.0.0 ports: - - "3306:3306" + - "${DBPORT_HOST:-3307}:3306" volumes: - db_data:/var/lib/mysql + - ./docker/db-init:/docker-entrypoint-initdb.d:ro networks: - monarc-network healthcheck: @@ -25,48 +26,48 @@ services: retries: 5 # PostgreSQL database for stats service - postgres: - image: postgres:15 - container_name: monarc-fo-postgres - environment: - POSTGRES_USER: ${STATS_DB_USER} - POSTGRES_PASSWORD: ${STATS_DB_PASSWORD} - POSTGRES_DB: ${STATS_DB_NAME} - ports: - - "5432:5432" - volumes: - - postgres_data:/var/lib/postgresql/data - networks: - - monarc-network - healthcheck: - test: ["CMD-SHELL", "pg_isready -U ${STATS_DB_USER}"] - interval: 10s - timeout: 5s - retries: 5 + # postgres: + # image: postgres:15 + # container_name: monarc-fo-postgres + # environment: + # POSTGRES_USER: ${STATS_DB_USER} + # POSTGRES_PASSWORD: ${STATS_DB_PASSWORD} + # POSTGRES_DB: ${STATS_DB_NAME} + # ports: + # - "5432:5432" + # volumes: + # - postgres_data:/var/lib/postgresql/data + # networks: + # - monarc-network + # healthcheck: + # test: ["CMD-SHELL", "pg_isready -U ${STATS_DB_USER}"] + # interval: 10s + # timeout: 5s + # retries: 5 - # Stats service - stats-service: - build: - context: . - dockerfile: Dockerfile.stats - container_name: monarc-fo-stats - environment: - STATS_HOST: ${STATS_HOST} - STATS_PORT: ${STATS_PORT} - STATS_DB_HOST: postgres - STATS_DB_NAME: ${STATS_DB_NAME} - STATS_DB_USER: ${STATS_DB_USER} - STATS_DB_PASSWORD: ${STATS_DB_PASSWORD} - STATS_SECRET_KEY: ${STATS_SECRET_KEY} - ports: - - "5005:5005" - depends_on: - postgres: - condition: service_healthy - networks: - - monarc-network - volumes: - - stats_data:/var/www/stats-service + # # Stats service + # stats-service: + # build: + # context: . + # dockerfile: Dockerfile.stats + # container_name: monarc-fo-stats + # environment: + # STATS_HOST: ${STATS_HOST} + # STATS_PORT: ${STATS_PORT} + # STATS_DB_HOST: postgres + # STATS_DB_NAME: ${STATS_DB_NAME} + # STATS_DB_USER: ${STATS_DB_USER} + # STATS_DB_PASSWORD: ${STATS_DB_PASSWORD} + # STATS_SECRET_KEY: ${STATS_SECRET_KEY} + # ports: + # - "5005:5005" + # depends_on: + # postgres: + # condition: service_healthy + # networks: + # - monarc-network + # volumes: + # - stats_data:/var/www/stats-service # MailCatcher for email testing mailcatcher: @@ -79,27 +80,38 @@ services: - monarc-network # Main MONARC FrontOffice application - monarc: + monarcfoapp: build: context: . dockerfile: Dockerfile + args: + NODE_MAJOR: ${NODE_MAJOR:-16} + XDEBUG_ENABLED: ${XDEBUG_ENABLED:-1} + XDEBUG_MODE: ${XDEBUG_MODE:-debug} + XDEBUG_START_WITH_REQUEST: ${XDEBUG_START_WITH_REQUEST:-trigger} + XDEBUG_CLIENT_HOST: ${XDEBUG_CLIENT_HOST:-host.docker.internal} + XDEBUG_CLIENT_PORT: ${XDEBUG_CLIENT_PORT:-9003} + XDEBUG_IDEKEY: ${XDEBUG_IDEKEY:-IDEKEY} + XDEBUG_DISCOVER_CLIENT_HOST: ${XDEBUG_DISCOVER_CLIENT_HOST:-0} container_name: monarc-fo-app environment: - DBHOST: db + DBHOST: ${DBHOST:-fodb} DBNAME_COMMON: ${DBNAME_COMMON} DBNAME_CLI: ${DBNAME_CLI} DBUSER_MONARC: ${DBUSER_MONARC} DBPASSWORD_MONARC: ${DBPASSWORD_MONARC} + DBPASSWORD_ADMIN: ${DBPASSWORD_ADMIN} + USE_BO_COMMON: ${USE_BO_COMMON:-0} STATS_API_KEY: ${STATS_API_KEY} APP_ENV: development APP_DIR: /var/www/html/monarc ports: - "5001:80" depends_on: - db: + fodb: condition: service_healthy - stats-service: - condition: service_started + # stats-service: + # condition: service_started networks: - monarc-network volumes: @@ -112,10 +124,16 @@ services: networks: monarc-network: - driver: bridge + name: ${MONARC_NETWORK_NAME:-monarc-network} + external: true volumes: db_data: + driver: local + driver_opts: + type: none + device: ./docker/db_data + o: bind postgres_data: stats_data: vendor_data: diff --git a/docker-dev.sh b/docker-dev.sh deleted file mode 100755 index c55b340..0000000 --- a/docker-dev.sh +++ /dev/null @@ -1,122 +0,0 @@ -#!/bin/bash -# Helper script for managing MONARC Docker development environment - -set -e - -COMPOSE_FILE="docker-compose.dev.yml" - -# Colors for output -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -RED='\033[0;31m' -NC='\033[0m' # No Color - -usage() { - echo -e "${GREEN}MONARC Docker Development Environment Manager${NC}" - echo "" - echo "Usage: $0 [command]" - echo "" - echo "Commands:" - echo " start Start all services (builds on first run)" - echo " stop Stop all services" - echo " restart Restart all services" - echo " logs View logs from all services" - echo " logs-app View logs from MONARC application" - echo " logs-stats View logs from stats service" - echo " shell Open a shell in the MONARC container" - echo " shell-stats Open a shell in the stats service container" - echo " db Open MySQL client in the database" - echo " reset Reset everything (removes all data)" - echo " status Show status of all services" - echo " stats-key Show the stats API key" - echo "" -} - -check_env() { - if [ ! -f .env ]; then - echo -e "${YELLOW}No .env file found. Creating from .env.dev...${NC}" - cp .env.dev .env - echo -e "${GREEN}.env file created. You can edit it to customize configuration.${NC}" - fi -} - -case "$1" in - start) - check_env - echo -e "${GREEN}Starting MONARC development environment...${NC}" - docker compose -f "$COMPOSE_FILE" up -d --build - echo -e "${GREEN}Services started!${NC}" - echo -e "MONARC FrontOffice: http://localhost:5001" - echo -e "Stats Service: http://localhost:5005" - echo -e "MailCatcher: http://localhost:1080" - echo -e "\n${YELLOW}To view logs: $0 logs${NC}" - ;; - - stop) - echo -e "${YELLOW}Stopping all services...${NC}" - docker compose -f "$COMPOSE_FILE" stop - echo -e "${GREEN}Services stopped.${NC}" - ;; - - restart) - echo -e "${YELLOW}Restarting all services...${NC}" - docker compose -f "$COMPOSE_FILE" restart - echo -e "${GREEN}Services restarted.${NC}" - ;; - - logs) - docker compose -f "$COMPOSE_FILE" logs -f - ;; - - logs-app) - docker compose -f "$COMPOSE_FILE" logs -f monarc - ;; - - logs-stats) - docker compose -f "$COMPOSE_FILE" logs -f stats-service - ;; - - shell) - echo -e "${GREEN}Opening shell in MONARC container...${NC}" - docker exec -it monarc-fo-app bash - ;; - - shell-stats) - echo -e "${GREEN}Opening shell in stats service container...${NC}" - docker exec -it monarc-fo-stats bash - ;; - - db) - echo -e "${GREEN}Opening MySQL client...${NC}" - docker exec -it monarc-fo-db mysql -usqlmonarcuser -psqlmonarcuser monarc_common - ;; - - reset) - echo -e "${RED}WARNING: This will remove all data!${NC}" - read -p "Are you sure? (yes/no): " confirm - if [ "$confirm" = "yes" ]; then - echo -e "${YELLOW}Stopping and removing all containers, volumes, and data...${NC}" - docker compose -f "$COMPOSE_FILE" down -v - echo -e "${GREEN}Reset complete. Run '$0 start' to start fresh.${NC}" - else - echo -e "${GREEN}Reset cancelled.${NC}" - fi - ;; - - status) - docker compose -f "$COMPOSE_FILE" ps - ;; - - stats-key) - echo -e "${GREEN}Retrieving stats API key...${NC}" - docker compose -f "$COMPOSE_FILE" logs stats-service | grep "Token:" | tail -1 - echo -e "\n${YELLOW}Note: Update this key in your .env file and restart MONARC service:${NC}" - echo -e " 1. Edit .env and set STATS_API_KEY=" - echo -e " 2. Run: docker compose -f \"\$COMPOSE_FILE\" restart monarc" - ;; - - *) - usage - exit 1 - ;; -esac diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index b914616..99acc57 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -11,24 +11,29 @@ echo -e "${GREEN}Starting MONARC FrontOffice setup...${NC}" # Wait for database to be ready echo -e "${YELLOW}Waiting for MariaDB to be ready...${NC}" -while ! mysqladmin ping -h"${DBHOST}" -u"${DBUSER_MONARC}" -p"${DBPASSWORD_MONARC}" --silent 2>/dev/null; do +while ! mysqladmin ping -h"${DBHOST}" -u"root" -p"${DBPASSWORD_ADMIN}" --silent 2>/dev/null; do echo "Waiting for MariaDB..." sleep 2 done echo -e "${GREEN}MariaDB is ready!${NC}" +is_true() { + case "$1" in + 1|true|yes|on) return 0 ;; + *) return 1 ;; + esac +} + # Check if this is the first run if [ ! -f "/var/www/html/monarc/.docker-initialized" ]; then echo -e "${GREEN}First run detected, initializing application...${NC}" - + cd /var/www/html/monarc - - # Install composer dependencies - if [ ! -d "vendor" ]; then - echo -e "${YELLOW}Installing Composer dependencies...${NC}" - composer install --ignore-platform-req=php - fi - + + # Install composer dependencies (always, to ensure binaries like Phinx are present) + echo -e "${YELLOW}Installing Composer dependencies...${NC}" + composer install --ignore-platform-req=php --no-interaction + # Create module symlinks echo -e "${YELLOW}Creating module symlinks...${NC}" mkdir -p module/Monarc @@ -36,40 +41,65 @@ if [ ! -f "/var/www/html/monarc/.docker-initialized" ]; then ln -sfn ./../../vendor/monarc/core Core ln -sfn ./../../vendor/monarc/frontoffice FrontOffice cd /var/www/html/monarc - + # Clone frontend repositories echo -e "${YELLOW}Setting up frontend repositories...${NC}" 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 fi - + if [ ! -d "ng_anr" ]; then git clone --config core.fileMode=false https://github.com/monarc-project/ng-anr.git ng_anr fi - + cd /var/www/html/monarc - - # Check if database exists and create if needed + + # Check if CLI database exists and create databases if needed echo -e "${YELLOW}Setting up databases...${NC}" - DB_EXISTS=$(mysql -h"${DBHOST}" -u"${DBUSER_MONARC}" -p"${DBPASSWORD_MONARC}" -e "SHOW DATABASES LIKE '${DBNAME_CLI}';" | grep -c "${DBNAME_CLI}" || true) - + DB_EXISTS=$(mysql -h"${DBHOST}" -u"root" -p"${DBPASSWORD_ADMIN}" -e "SHOW DATABASES LIKE '${DBNAME_CLI}';" | grep -c "${DBNAME_CLI}" || true) + USE_BO_COMMON_ENABLED=0 + if is_true "${USE_BO_COMMON}"; then + USE_BO_COMMON_ENABLED=1 + fi + if [ "$DB_EXISTS" -eq 0 ]; then echo -e "${YELLOW}Creating databases...${NC}" - mysql -h"${DBHOST}" -u"${DBUSER_MONARC}" -p"${DBPASSWORD_MONARC}" -e "CREATE DATABASE ${DBNAME_CLI} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;" - mysql -h"${DBHOST}" -u"${DBUSER_MONARC}" -p"${DBPASSWORD_MONARC}" -e "CREATE DATABASE ${DBNAME_COMMON} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;" - - echo -e "${YELLOW}Populating databases...${NC}" - mysql -h"${DBHOST}" -u"${DBUSER_MONARC}" -p"${DBPASSWORD_MONARC}" ${DBNAME_COMMON} < db-bootstrap/monarc_structure.sql - mysql -h"${DBHOST}" -u"${DBUSER_MONARC}" -p"${DBPASSWORD_MONARC}" ${DBNAME_COMMON} < db-bootstrap/monarc_data.sql + mysql -h"${DBHOST}" -u"root" -p"${DBPASSWORD_ADMIN}" -e "CREATE DATABASE IF NOT EXISTS ${DBNAME_CLI} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;" + + if [ "$USE_BO_COMMON_ENABLED" -eq 0 ]; then + mysql -h"${DBHOST}" -u"root" -p"${DBPASSWORD_ADMIN}" -e "CREATE DATABASE IF NOT EXISTS ${DBNAME_COMMON} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;" + + echo -e "${YELLOW}Populating common database...${NC}" + export MYSQL_PWD="${DBPASSWORD_MONARC}" + mysql -h"${DBHOST}" -u"${DBUSER_MONARC}" ${DBNAME_COMMON} < db-bootstrap/monarc_structure.sql + mysql -h"${DBHOST}" -u"${DBUSER_MONARC}" ${DBNAME_COMMON} < db-bootstrap/monarc_data.sql + else + echo -e "${YELLOW}USE_BO_COMMON is enabled; skipping monarc_common creation and bootstrap.${NC}" + fi + fi + + echo -e "${YELLOW}Ensuring privileges for ${DBUSER_MONARC}...${NC}" + mysql -h"${DBHOST}" -u"root" -p"${DBPASSWORD_ADMIN}" -e "GRANT ALL PRIVILEGES ON ${DBNAME_CLI}.* TO '${DBUSER_MONARC}'@'%';" + if [ "$USE_BO_COMMON_ENABLED" -eq 0 ]; then + mysql -h"${DBHOST}" -u"root" -p"${DBPASSWORD_ADMIN}" -e "GRANT ALL PRIVILEGES ON ${DBNAME_COMMON}.* TO '${DBUSER_MONARC}'@'%';" + fi + mysql -h"${DBHOST}" -u"root" -p"${DBPASSWORD_ADMIN}" -e "FLUSH PRIVILEGES;" + + if [ "$USE_BO_COMMON_ENABLED" -eq 1 ]; then + COMMON_EXISTS=$(mysql -h"${DBHOST}" -u"root" -p"${DBPASSWORD_ADMIN}" -e "SHOW DATABASES LIKE '${DBNAME_COMMON}';" | grep -c "${DBNAME_COMMON}" || true) + if [ "$COMMON_EXISTS" -eq 0 ]; then + echo -e "${RED}USE_BO_COMMON is enabled, but ${DBNAME_COMMON} was not found on ${DBHOST}.${NC}" + echo -e "${RED}Ensure the BackOffice database is reachable and contains ${DBNAME_COMMON}.${NC}" + exit 1 + fi fi - - # Generate local config if it doesn't exist - if [ ! -f "config/autoload/local.php" ]; then - echo -e "${YELLOW}Creating local configuration...${NC}" - cat > config/autoload/local.php < config/autoload/local.php <