From 30905b15d44f627f9d4b3c0ab5a2dc5b5feaa235 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 24 May 2026 14:12:23 +0200 Subject: [PATCH] feat: SuiteCRM Docker + compose + CI/CD --- .dockerignore | 7 ++ .env | 16 +++ .gitea/workflows/docker-build.yml | 38 ++++++++ Dockerfile | 96 ++++++++++++++++++ README.md | 155 +++++++++++++++++++++++++++++- apache-suitecrm.conf | 23 +++++ docker-compose.yml | 87 +++++++++++++++++ docker-entrypoint.sh | 22 +++++ 8 files changed, 442 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 .env create mode 100644 .gitea/workflows/docker-build.yml create mode 100644 Dockerfile create mode 100644 apache-suitecrm.conf create mode 100644 docker-compose.yml create mode 100644 docker-entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..41fc335 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.env +upload/ +cache/ +*.log +vendor/ +.env.local +.env.*.local diff --git a/.env b/.env new file mode 100644 index 0000000..18059af --- /dev/null +++ b/.env @@ -0,0 +1,16 @@ +# SuiteCRM Docker Compose Configuration +# Copy to .env and customize + +# SuiteCRM +SUITECRM_PORT=8080 +SUITECRM_SITE_URL=http://localhost:8080 + +# MariaDB +MYSQL_PORT=3307 +MYSQL_ROOT_PASSWORD=change_this_root_password +MYSQL_DATABASE=suitecrm +MYSQL_USER=suitecrm +MYSQL_PASSWORD=change_this_db_password + +# Redis (only with --profile full or --profile redis) +REDIS_PORT=6379 diff --git a/.gitea/workflows/docker-build.yml b/.gitea/workflows/docker-build.yml new file mode 100644 index 0000000..869775d --- /dev/null +++ b/.gitea/workflows/docker-build.yml @@ -0,0 +1,38 @@ +name: Docker Build & Push + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build-and-push: + runs-on: ubuntu-latest + container: + image: docker:27-dind + options: --privileged + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: git.kgessner.de + username: ${{ secrets.REGISTRY_USER }} + password: ${{ secrets.REGISTRY_TOKEN }} + + - name: Build and Push + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: | + git.kgessner.de/luiicode/sugar-crm:latest + git.kgessner.de/luiicode/sugar-crm:7.15.1 + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..efab976 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,96 @@ +# SuiteCRM 7.15.1 - PHP 8.1 + Apache +FROM php:8.1-apache + +LABEL maintainer="Kevin Gessner" +LABEL description="SuiteCRM 7.15.1 containerized with PHP 8.1 and Apache" + +# Install system dependencies and PHP extensions +RUN set -eux; \ + apt-get update && apt-get install -y --no-install-recommends \ + # Core + libzip-dev \ + libpng-dev \ + libjpeg-dev \ + libfreetype6-dev \ + libonig-dev \ + libxml2-dev \ + libldap2-dev \ + libc-client-dev \ + libkrb5-dev \ + libcurl4-openssl-dev \ + libicu-dev \ + # Utils + unzip \ + wget \ + curl \ + cron \ + msmtp \ + # Cleanup + && docker-php-ext-configure gd --with-freetype --with-jpeg \ + && docker-php-ext-configure imap --with-kerberos --with-imap-ssl \ + && docker-php-ext-install -j$(nproc) \ + pdo \ + pdo_mysql \ + mysqli \ + gd \ + mbstring \ + zip \ + xml \ + curl \ + ldap \ + imap \ + intl \ + calendar \ + opcache \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Configure PHP for SuiteCRM +RUN { \ + echo 'memory_limit = 512M'; \ + echo 'upload_max_filesize = 64M'; \ + echo 'post_max_size = 64M'; \ + echo 'max_execution_time = 600'; \ + echo 'max_input_time = 600'; \ + echo 'display_errors = Off'; \ + echo 'log_errors = On'; \ + echo 'date.timezone = Europe/Berlin'; \ + } > /usr/local/etc/php/conf.d/suitecrm.ini + +# Configure OPcache +RUN { \ + echo 'opcache.memory_consumption=256'; \ + echo 'opcache.interned_strings_buffer=16'; \ + echo 'opcache.max_accelerated_files=20000'; \ + echo 'opcache.revalidate_freq=2'; \ + echo 'opcache.fast_shutdown=1'; \ + } > /usr/local/etc/php/conf.d/opcache-recommended.ini + +# SuiteCRM version +ENV SUITECRM_VERSION=7.15.1 +ENV SUITECRM_SHA256=468b811addd21dfb29d411ee6e815dbdf7099f912347e88cd3e8d010d829db7a + +# Download and extract SuiteCRM +RUN set -eux; \ + wget -q "https://github.com/salesagility/SuiteCRM/releases/download/v${SUITECRM_VERSION}/SuiteCRM-${SUITECRM_VERSION}.zip" \ + -O /tmp/suitecrm.zip; \ + echo "${SUITECRM_SHA256} /tmp/suitecrm.zip" | sha256sum -c -; \ + unzip -q /tmp/suitecrm.zip -d /var/www/html/; \ + rm /tmp/suitecrm.zip; \ + chown -R www-data:www-data /var/www/html + +# Apache configuration +RUN a2enmod rewrite expires headers + +COPY apache-suitecrm.conf /etc/apache2/sites-available/000-default.conf +COPY docker-entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/docker-entrypoint.sh + +WORKDIR /var/www/html + +VOLUME ["/var/www/html/upload", "/var/www/html/custom", "/var/www/html/config_override.php"] + +EXPOSE 80 + +ENTRYPOINT ["docker-entrypoint.sh"] +CMD ["apache2-foreground"] diff --git a/README.md b/README.md index 213bf5d..54acd2f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,154 @@ -# sugar-crm +# SuiteCRM Docker — Containerized CRM Environment -Containerized SugarCRM/SuiteCRM environment with Docker Compose \ No newline at end of file +**SuiteCRM 7.15.1** — vollständig containerisiert mit Docker Compose. +Ein Befehl, alles läuft: SuiteCRM + MariaDB + (optional) Redis. + +## Systemanforderungen + +- Docker 20.10+ und Docker Compose v2 +- 2 GB RAM empfohlen (MariaDB Puffer) + +## Schnellstart + +```bash +# 1. Repository klonen +git clone https://git.kgessner.de/LuiiCode/sugar-crm.git +cd sugar-crm + +# 2. Umgebungsvariablen anpassen +cp .env.example .env +nano .env # Passwörter ändern! + +# 3. Starten +docker compose up -d + +# 4. SuiteCRM Installation im Browser abschließen: +# http://localhost:8080 +``` + +## Architektur + +``` +┌──────────────────────────────────────┐ +│ Docker Compose │ +│ │ +│ ┌──────────┐ ┌──────────┐ │ +│ │ SuiteCRM │ │ MariaDB │ Redis? │ +│ │ :8080 │ │ :3307 │ :6379 │ +│ │ PHP 8.1 │ │ 10.11 │ (opt.) │ +│ │ Apache │ │ │ │ +│ └──────────┘ └──────────┘ │ +│ │ │ │ +│ Volumes: Volumes: │ +│ - upload - /var/lib/mysql │ +│ - custom │ +│ - config │ +└──────────────────────────────────────┘ +``` + +## Services + +| Service | Image | Port | Profil | +|-----------|------------------|-------|---------------| +| suitecrm | Custom (PHP 8.1) | 8080 | standard | +| mariadb | mariadb:10.11 | 3307 | standard | +| redis | redis:7-alpine | 6379 | `redis`/`full`| + +## Konfiguration + +### Umgebungsvariablen (`.env`) + +| Variable | Default | Beschreibung | +|-----------------------|-----------------------------|-------------------------| +| `SUITECRM_PORT` | 8080 | Webinterface-Port | +| `SUITECRM_SITE_URL` | http://localhost:8080 | Öffentliche URL | +| `MYSQL_PORT` | 3307 | DB-Port (Host) | +| `MYSQL_ROOT_PASSWORD` | change_this… | Root-Passwort | +| `MYSQL_DATABASE` | suitecrm | Datenbank-Name | +| `MYSQL_USER` | suitecrm | Datenbank-Nutzer | +| `MYSQL_PASSWORD` | change_this… | Nutzer-Passwort | + +> ⚠️ **Sicherheit**: Immer `.env` Passwörter ändern vor erstem Start! + +## Kommandos + +```bash +# Grundbefehle +docker compose up -d # Alle Services starten +docker compose up -d redis # + Redis-Cache starten +docker compose down # Stoppen +docker compose down -v # Stoppen + ALLE DATEN LÖSCHEN + +# Logs +docker compose logs -f suitecrm # SuiteCRM-Logs verfolgen +docker compose logs mariadb # DB-Logs + +# Backup +docker compose exec mariadb mysqldump -u suitecrm -p suitecrm > backup.sql +tar -czf upload-backup.tar.gz -C /var/lib/docker/volumes/sugarcrmreponame_suitecrm_data/_data . +``` + +## SuiteCRM Installation (Erst-Start) + +Nach `docker compose up -d` im Browser `http://localhost:8080` öffnen: + +1. **License Agreement** → Akzeptieren +2. **System Check** → Alle Checks sollten grün sein +3. **Database Configuration**: + - Host: `mariadb` + - Database: `suitecrm` + - User: `suitecrm` + - Password: (aus `.env`) +4. **Site Configuration** → Admin-Nutzer anlegen +5. **Fertig!** SuiteCRM ist einsatzbereit. + +## Redis aktivieren + +```bash +# Mit Redis-Profil starten +docker compose --profile redis up -d + +# Oder Full-Stack (alles inkl. Redis) +docker compose --profile full up -d +``` + +Redis-Konfiguration in SuiteCRM Admin → System → Redis: +- Host: `redis` +- Port: `6379` + +## Elasticsearch (optional) + +Für Volltextsuche kann Elasticsearch ergänzt werden. Dazu in `docker-compose.yml` einfügen: + +```yaml + elasticsearch: + image: docker.elastic.co/elasticsearch/elasticsearch:7.17.24 + container_name: suitecrm-es + environment: + - discovery.type=single-node + - xpack.security.enabled=false + volumes: + - es_data:/usr/share/elasticsearch/data + networks: + - suitecrm-net +``` + +## Docker Image bauen & pushen + +```bash +# Lokal bauen +docker build -t suitecrm:7.15.1 . + +# In Gitea Registry pushen +docker tag suitecrm:7.15.1 git.kgessner.de/luiicode/sugar-crm:7.15.1 +docker login git.kgessner.de +docker push git.kgessner.de/luiicode/sugar-crm:7.15.1 +``` + +## CI/CD + +Bei jedem Push auf `main` baut Gitea Actions das Image automatisch und pusht es in die Gitea Container Registry. Workflow: `.gitea/workflows/docker-build.yml` + +--- + +**Version**: SuiteCRM 7.15.1 | **PHP**: 8.1 | **MariaDB**: 10.11 diff --git a/apache-suitecrm.conf b/apache-suitecrm.conf new file mode 100644 index 0000000..6caa327 --- /dev/null +++ b/apache-suitecrm.conf @@ -0,0 +1,23 @@ + + ServerAdmin webmaster@localhost + DocumentRoot /var/www/html + + + Options Indexes FollowSymLinks + AllowOverride All + Require all granted + + + # Protect sensitive files + + Require all denied + + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + # Security headers + Header always set X-Content-Type-Options "nosniff" + Header always set X-Frame-Options "SAMEORIGIN" + Header always set X-XSS-Protection "1; mode=block" + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..dd168e1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,87 @@ +# SuiteCRM Docker Compose Environment +# ==================================== +# Start: docker compose up -d +# Stop: docker compose down +# Data persists in Docker volumes unless you run: docker compose down -v + +services: + # --- SuiteCRM Application --- + suitecrm: + build: + context: . + dockerfile: Dockerfile + image: suitecrm:7.15.1 + container_name: suitecrm-app + restart: unless-stopped + ports: + - "${SUITECRM_PORT:-8080}:80" + environment: + - DATABASE_HOST=mariadb + - DATABASE_PORT=3306 + - DATABASE_NAME=${MYSQL_DATABASE:-suitecrm} + - DATABASE_USER=${MYSQL_USER:-suitecrm} + - DATABASE_PASSWORD=${MYSQL_PASSWORD:-suitecrm_secret} + - SUITECRM_SITE_URL=${SUITECRM_SITE_URL:-http://localhost:8080} + volumes: + - suitecrm_data:/var/www/html/upload + - suitecrm_custom:/var/www/html/custom + - suitecrm_config:/var/www/html/config_override.php + depends_on: + mariadb: + condition: service_healthy + networks: + - suitecrm-net + + # --- MariaDB Database --- + mariadb: + image: mariadb:10.11 + container_name: suitecrm-db + restart: unless-stopped + ports: + - "${MYSQL_PORT:-3307}:3306" + environment: + - MARIADB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-root_secret} + - MARIADB_DATABASE=${MYSQL_DATABASE:-suitecrm} + - MARIADB_USER=${MYSQL_USER:-suitecrm} + - MARIADB_PASSWORD=${MYSQL_PASSWORD:-suitecrm_secret} + volumes: + - mariadb_data:/var/lib/mysql + command: + - --character-set-server=utf8mb4 + - --collation-server=utf8mb4_unicode_ci + - --max-allowed-packet=64M + - --innodb-buffer-pool-size=256M + healthcheck: + test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"] + interval: 10s + timeout: 5s + retries: 5 + networks: + - suitecrm-net + + # --- Redis Cache (optional) --- + redis: + image: redis:7-alpine + container_name: suitecrm-redis + restart: unless-stopped + ports: + - "${REDIS_PORT:-6379}:6379" + volumes: + - redis_data:/data + command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru + networks: + - suitecrm-net + profiles: + - full + - redis + +volumes: + suitecrm_data: + suitecrm_custom: + suitecrm_config: + mariadb_data: + redis_data: + +networks: + suitecrm-net: + driver: bridge diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..c70a5a6 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +# Fix permissions +chown -R www-data:www-data /var/www/html/cache /var/www/html/upload /var/www/html/custom 2>/dev/null || true +chmod -R 755 /var/www/html 2>/dev/null || true +chmod -R 775 /var/www/html/cache /var/www/html/upload /var/www/html/custom 2>/dev/null || true + +# Generate SuiteCRM autoloader if missing +if [ ! -f /var/www/html/vendor/autoload.php ] && [ -f /var/www/html/composer.json ]; then + echo "Installing Composer dependencies..." + cd /var/www/html && composer install --no-dev --optimize-autoloader 2>/dev/null || true +fi + +# Set recommended permissions +touch /var/www/html/config.php 2>/dev/null || true +chmod 640 /var/www/html/config.php 2>/dev/null || true +chown www-data:www-data /var/www/html/config.php 2>/dev/null || true + +echo "SuiteCRM ready. Access http://localhost:8080 to complete installation." + +exec "$@"