diff --git a/.docker/.mautic_env b/.docker/.mautic_env new file mode 100644 index 00000000..c6a06a35 --- /dev/null +++ b/.docker/.mautic_env @@ -0,0 +1,20 @@ +# use this file for environment variables that can be used. +# see https://docs.mautic.org/en/7.x/ + +MAUTIC_DB_HOST="${MYSQL_HOST}" +MAUTIC_DB_PORT="${MYSQL_PORT}" +MAUTIC_DB_DATABASE="${MYSQL_DATABASE}" +MAUTIC_DB_USER="${MYSQL_USER}" +MAUTIC_DB_PASSWORD="${MYSQL_PASSWORD}" + +MAUTIC_MESSENGER_DSN_EMAIL="doctrine://default" +MAUTIC_MESSENGER_DSN_HIT="doctrine://default" + +MAUTIC_AUTO_INSTALL="false" +MAUTIC_FORCE_INSTALL="false" +MAUTIC_SITE_URL="http://localhost" +MAUTIC_ADMIN_FIRSTNAME="Admin" +MAUTIC_ADMIN_LASTNAME="Mautic" +MAUTIC_ADMIN_USERNAME="admin" +MAUTIC_ADMIN_EMAIL="admin@example.com" +MAUTIC_ADMIN_PASSWORD="ChangeMe123!" diff --git a/.docker/Dockerfile.apache b/.docker/Dockerfile.apache index 20adb829..bc62c947 100644 --- a/.docker/Dockerfile.apache +++ b/.docker/Dockerfile.apache @@ -1,4 +1,4 @@ -FROM php:8.1-apache +FROM php:8.3-apache LABEL vendor="Mautic" LABEL maintainer="LibreCode coop" @@ -62,7 +62,7 @@ ENV DOCKER_MAUTIC_WORKERS_CONSUME_EMAIL=2 \ # Install NVM ENV NVM_DIR=/usr/local/nvm \ - NODE_VERSION=20.18.1 + NODE_VERSION=25.2.1 SHELL ["/bin/bash", "-o", "pipefail", "-c"] # hadolint ignore=SC1091 RUN mkdir -p /usr/local/nvm && \ diff --git a/.docker/Dockerfile.fpm b/.docker/Dockerfile.fpm index f09e76d0..5a8ecd14 100644 --- a/.docker/Dockerfile.fpm +++ b/.docker/Dockerfile.fpm @@ -1,4 +1,4 @@ -FROM php:8.1-fpm +FROM php:8.3-fpm LABEL vendor="Mautic" LABEL maintainer="LibreCode coop" @@ -56,7 +56,7 @@ ENV DOCKER_MAUTIC_WORKERS_CONSUME_EMAIL=2 \ # Install NVM ENV NVM_DIR=/usr/local/nvm \ - NODE_VERSION=20.18.1 + NODE_VERSION=25.2.1 SHELL ["/bin/bash", "-o", "pipefail", "-c"] # hadolint ignore=SC1091 RUN mkdir -p /usr/local/nvm && \ diff --git a/.docker/scripts/entrypoint.sh b/.docker/scripts/entrypoint.sh index 461fd00d..31661d06 100644 --- a/.docker/scripts/entrypoint.sh +++ b/.docker/scripts/entrypoint.sh @@ -17,7 +17,7 @@ elif [ "$DOCKER_MAUTIC_ROLE" = "mautic_web" ]; then nvm use default cd /var/www || { echo "Directory not found /var/www"; exit 1; } - COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_PROCESS_TIMEOUT=10000 composer create-project mautic/recommended-project:"${MAUTIC_VERSION:-5.x-dev}" html --no-interaction + COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_PROCESS_TIMEOUT=10000 composer create-project mautic/recommended-project:"${MAUTIC_VERSION:-7.x-dev}" html --no-interaction chown -R www-data: html cd html || { echo "Directory not found /var/www/html"; exit 1; } rm -rf var/cache/js diff --git a/.docker/scripts/entrypoint_mautic_web.sh b/.docker/scripts/entrypoint_mautic_web.sh index b6439e70..80a29760 100644 --- a/.docker/scripts/entrypoint_mautic_web.sh +++ b/.docker/scripts/entrypoint_mautic_web.sh @@ -1,8 +1,58 @@ #!/bin/bash -chown -R www-data:www-data /var/www/html/config /var/www/html/var/logs /var/www/html/docroot/media +set -e -# wait untill the db is fully up before proceeding +prepare_install_dirs() { + mkdir -p /var/www/html/var/cache /var/www/html/var/logs + chown -R www-data:www-data /var/www/html/config /var/www/html/var /var/www/html/docroot/media +} + +prepare_install_dirs + +mautic_site_url="${MAUTIC_SITE_URL:-http://localhost}" +mautic_admin_firstname="${MAUTIC_ADMIN_FIRSTNAME:-Admin}" +mautic_admin_lastname="${MAUTIC_ADMIN_LASTNAME:-Mautic}" +mautic_admin_username="${MAUTIC_ADMIN_USERNAME:-admin}" +mautic_admin_email="${MAUTIC_ADMIN_EMAIL:-admin@example.com}" +mautic_admin_password="${MAUTIC_ADMIN_PASSWORD:-ChangeMe123!}" +mautic_db_table_prefix="${MAUTIC_DB_TABLE_PREFIX:-}" +mautic_db_backup_tables="${MAUTIC_DB_BACKUP_TABLES:-true}" +mautic_db_backup_prefix="${MAUTIC_DB_BACKUP_PREFIX:-bak_}" +mautic_force_install="${MAUTIC_FORCE_INSTALL:-false}" + +install_mautic() { + local mautic_db_name="${MAUTIC_DB_DATABASE:-${MAUTIC_DB_NAME:-mautic}}" + local cmd + + printf -v cmd 'php /var/www/html/bin/console mautic:install %q --force --db_driver=pdo_mysql --db_host=%q --db_port=%q --db_name=%q --db_user=%q --db_password=%q --db_table_prefix=%q --db_backup_tables=%q --db_backup_prefix=%q --admin_firstname=%q --admin_lastname=%q --admin_username=%q --admin_email=%q --admin_password=%q' \ + "$mautic_site_url" \ + "$MAUTIC_DB_HOST" \ + "$MAUTIC_DB_PORT" \ + "$mautic_db_name" \ + "$MAUTIC_DB_USER" \ + "$MAUTIC_DB_PASSWORD" \ + "$mautic_db_table_prefix" \ + "$mautic_db_backup_tables" \ + "$mautic_db_backup_prefix" \ + "$mautic_admin_firstname" \ + "$mautic_admin_lastname" \ + "$mautic_admin_username" \ + "$mautic_admin_email" \ + "$mautic_admin_password" + + su -s /bin/bash www-data -c "$cmd" +} + +install_mautic_plugins() { + su -s /bin/bash www-data -c 'php /var/www/html/bin/console mautic:plugins:install' +} + +mautic_is_installed() { + # shellcheck disable=SC2016 + php -r 'if (!file_exists("/var/www/html/config/local.php")) { exit(1); } include "/var/www/html/config/local.php"; exit(isset($parameters["db_driver"], $parameters["site_url"]) ? 0 : 1);' +} + +# wait until the db is fully up before proceeding while [[ $(mysqladmin --host="$MAUTIC_DB_HOST" --port="$MAUTIC_DB_PORT" --user="$MAUTIC_DB_USER" --password="$MAUTIC_DB_PASSWORD" ping) != "mysqld is alive" ]]; do sleep 1 done @@ -10,7 +60,6 @@ done # generate a local config file if it doesn't exist. # This is needed to ensure the db credentials can be prefilled in the UI, as env vars aren't taken into account. if [ ! -f /var/www/html/config/local.php ]; then - su -s /bin/bash www-data -c 'touch /var/www/html/config/local.php' cat <<'EOF' > /var/www/html/config/local.php @@ -29,11 +78,50 @@ $parameters = array( EOF fi +if [ "$mautic_force_install" = "true" ]; then + rm -f /var/www/html/config/local.php +fi + +prepare_install_dirs + +if [ "$MAUTIC_AUTO_INSTALL" = "true" ] && [ -f /var/www/html/config/local.php ]; then + if ! mautic_is_installed; then + rm -f /var/www/html/config/local.php + fi +fi + +if [ "$MAUTIC_AUTO_INSTALL" = "true" ] && [ ! -f /var/www/html/config/local.php ]; then + MAUTIC_SITE_URL="$mautic_site_url" \ + MAUTIC_ADMIN_FIRSTNAME="$mautic_admin_firstname" \ + MAUTIC_ADMIN_LASTNAME="$mautic_admin_lastname" \ + MAUTIC_ADMIN_USERNAME="$mautic_admin_username" \ + MAUTIC_ADMIN_EMAIL="$mautic_admin_email" \ + MAUTIC_ADMIN_PASSWORD="$mautic_admin_password" \ + MAUTIC_DB_TABLE_PREFIX="$mautic_db_table_prefix" \ + MAUTIC_DB_BACKUP_TABLES="$mautic_db_backup_tables" \ + MAUTIC_DB_BACKUP_PREFIX="$mautic_db_backup_prefix" \ + install_mautic + + install_mautic_plugins +fi + # prepare mautic with test data if [ "$DOCKER_MAUTIC_LOAD_TEST_DATA" = "true" ]; then su -s /bin/bash www-data -c 'php /var/www/html/bin/console doctrine:migrations:sync-metadata-storage' # mautic installation with dummy password and email, as the next step (doctrine:fixtures:load) will overwrite those - su -s /bin/bash www-data -c 'php /var/www/html/bin/console mautic:install --force --admin_email willchange@mautic.org --admin_password willchange http://localhost' + if ! mautic_is_installed; then + MAUTIC_SITE_URL="$mautic_site_url" \ + MAUTIC_ADMIN_FIRSTNAME="$mautic_admin_firstname" \ + MAUTIC_ADMIN_LASTNAME="$mautic_admin_lastname" \ + MAUTIC_ADMIN_USERNAME="$mautic_admin_username" \ + MAUTIC_ADMIN_EMAIL="$mautic_admin_email" \ + MAUTIC_ADMIN_PASSWORD="$mautic_admin_password" \ + MAUTIC_DB_TABLE_PREFIX="$mautic_db_table_prefix" \ + MAUTIC_DB_BACKUP_TABLES="$mautic_db_backup_tables" \ + MAUTIC_DB_BACKUP_PREFIX="$mautic_db_backup_prefix" \ + install_mautic + fi + install_mautic_plugins su -s /bin/bash www-data -c 'php /var/www/html/bin/console doctrine:fixtures:load -n' fi diff --git a/.github/workflows/build_publish.yml b/.github/workflows/build_publish.yml index 401c585d..fe0b95ae 100644 --- a/.github/workflows/build_publish.yml +++ b/.github/workflows/build_publish.yml @@ -8,10 +8,10 @@ on: required: true overwrite_latest_major: type: boolean - description: "Overwrite latest major tag (e.g.`5`). This should only be checked if you're releasing the latest release." + description: "Overwrite latest major tag (e.g.`7`). This should only be checked if you're releasing the latest release." overwrite_latest_minor: type: boolean - description: "Overwrite latest minor tag (e.g.`5.0`). This should only be checked if you're releasing the latest release within the minor release." + description: "Overwrite latest minor tag (e.g.`7.0`). This should only be checked if you're releasing the latest release within the minor release." tag_as_latest: type: boolean description: "Tag this release as latest" diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..d82349df --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "volumes/mautic/docroot/plugins/MauticCrmBundle"] + path = volumes/mautic/docroot/plugins/MauticCrmBundle + url = https://github.com/mautomic-com/mautic-crm-bundle.git + branch = main diff --git a/README.md b/README.md index 23173547..d3a584a5 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,20 @@ # Mautic Docker image and examples > [!NOTE] -> _This version refers to Docker images and examples for Mautic 5. If you would like information about older versions, see https://github.com/mautic/docker-mautic/tree/mautic4._ +> _This version refers to Docker images and examples for Mautic 7. If you would like information about older versions, see https://github.com/mautic/docker-mautic/tree/mautic4._ > [!NOTE] > This fork was made to make possible use xdebug +If you want the CRM plugin submodule checked out on clone, use: + +```bash +git clone --recurse-submodules https://github.com/LibreCodeCoop/mautic-docker.git +``` + ## Versions -all Mautic 5 Docker images follow the following naming stategy. +all Mautic 7 Docker images follow the following naming stategy. `-` @@ -18,9 +24,9 @@ There are some defaults if parts are omitted: some examples: -* `5-apache`: latest stable version of Mautic 5 of the `apache` variant -* `5.0-fpm`: latest version in the 5.0 minor release in the `fpm` variant -* `5.0.3-apache`: specific point release of the `apache` variant +* `7-apache`: latest stable version of Mautic 7 of the `apache` variant +* `7.0-fpm`: latest version in the 7.0 minor release in the `fpm` variant +* `7.0.3-apache`: specific point release of the `apache` variant ## Variants @@ -73,8 +79,8 @@ The `examples` folder contains examples of `docker-compose` setups that use the You can build your own images easily using the `docker build` command in the root of this directory: ``` -docker build . -f Dockerfile.apache -t librecodecoop/mautic:5-apache -docker build . -f Dockerfile.fpm -t librecodecoop/mautic:5-fpm +docker build . -f Dockerfile.apache -t librecodecoop/mautic:7-apache +docker build . -f Dockerfile.fpm -t librecodecoop/mautic:7-fpm ``` ## Persistent storage @@ -119,6 +125,14 @@ You can get all available environments looking at a docker-compose.yml file that - `DOCKER_MAUTIC_ROLE`: which role does the container has to perform. Defaults to `mautic_web`, other supported values are `mautic_worker` and `mautic_cron`. + - `MAUTIC_AUTO_INSTALL`: when `true`, the web container runs `mautic:install` automatically on first boot. + Defaults to `false`. + - `MAUTIC_FORCE_INSTALL`: when `true`, the web container clears any partial local install state and runs `mautic:install` again. + Defaults to `false`. + - `MAUTIC_SITE_URL`: site URL passed to the installer. + Defaults to `http://localhost`. + - `MAUTIC_ADMIN_FIRSTNAME`, `MAUTIC_ADMIN_LASTNAME`, `MAUTIC_ADMIN_USERNAME`, `MAUTIC_ADMIN_EMAIL`, `MAUTIC_ADMIN_PASSWORD`: admin account fields used by the automated install. + Defaults are `Admin`, `Mautic`, `admin`, `admin@example.com`, and `ChangeMe123!`. - `DOCKER_MAUTIC_LOAD_TEST_DATA`: should the test data be loaded on start or not. Defaults to `false`, other supported value is `true`. This variable is only usable when using the `web` role. @@ -141,10 +155,35 @@ Technically, every setting of Mautic you can set via the UI or via the `local.ph e.g. the `messenger_dsn_hit` can be set via the `MAUTIC_MESSENGER_DSN_HIT` environment variable. See the general Mautic documentation for more info. +#### Automated installation + +To install Mautic without using the browser installer, set `MAUTIC_AUTO_INSTALL=true` and provide the DB/admin variables through your environment or `.env` file. + +Example: + +```env +MAUTIC_AUTO_INSTALL=true +MAUTIC_FORCE_INSTALL=true +MAUTIC_SITE_URL=http://localhost +MAUTIC_ADMIN_FIRSTNAME=Admin +MAUTIC_ADMIN_LASTNAME=Mautic +MAUTIC_ADMIN_USERNAME=admin +MAUTIC_ADMIN_EMAIL=admin@example.com +MAUTIC_ADMIN_PASSWORD=ChangeMe123! +``` + +Use `MAUTIC_FORCE_INSTALL=true` on the first boot when you want to skip the browser installer entirely, or when you are reusing a volume that already contains a partial install state. + +This repository also tracks the CRM bundle as a git submodule under `volumes/mautic/docroot/plugins/MauticCrmBundle`. If you clone the repository manually, initialize submodules before starting the stack: + +```bash +git submodule update --init --recursive +``` + ### Customization Currently this image has no easy way to extend Mautic (e.g. adding extra `composer` dependencies or installing extra plugins or themes). -This is an ongoing effort we hope to support in an upcoming 5.x release. +This is an ongoing effort we hope to support in an upcoming 7.x release. For now, please build your own images based on the official ones to add the needed dependencies, plugins and themes. @@ -184,4 +223,4 @@ You can also reach the Mautic community through its [online forums](https://www. You are invited to contribute new features, fixes, or updates, large or small; we are always thrilled to receive pull requests, and do our best to process them as fast as we can. -Before you start to code, we recommend discussing your plans through a [GitHub issue](https://github.com/librecodecoop/mautic-docker/issues), especially for more ambitious contributions. This gives other contributors a chance to point you in the right direction, give you feedback on your design, and help you find out if someone else is working on the same thing. \ No newline at end of file +Before you start to code, we recommend discussing your plans through a [GitHub issue](https://github.com/librecodecoop/mautic-docker/issues), especially for more ambitious contributions. This gives other contributors a chance to point you in the right direction, give you feedback on your design, and help you find out if someone else is working on the same thing. diff --git a/docker-compose.yml b/docker-compose.yml index f4789e7a..846052f6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ x-mautic-volumes: &mautic-volumes - ./volumes/cron:/opt/mautic/cron:z x-mautic-environments: &mautic-environments - MAUTIC_VERSION: ${MAUTIC_VERSION:-5.x-dev} + MAUTIC_VERSION: ${MAUTIC_VERSION:-7.x-dev} TZ: ${TZ:-CET} HOST_UID: ${HOST_UID:-1000} HOST_GID: ${HOST_GID:-1000} @@ -12,6 +12,18 @@ x-mautic-environments: &mautic-environments MAUTIC_DB_USER: ${MAUTIC_DB_USER:-mautic} MAUTIC_DB_PASSWORD: ${MAUTIC_DB_PASSWORD:-mautic} MAUTIC_DB_NAME: ${MAUTIC_DB_NAME:-mautic} + MAUTIC_DB_DATABASE: ${MAUTIC_DB_DATABASE:-mautic} + MAUTIC_DB_TABLE_PREFIX: ${MAUTIC_DB_TABLE_PREFIX:-} + MAUTIC_DB_BACKUP_TABLES: ${MAUTIC_DB_BACKUP_TABLES:-true} + MAUTIC_DB_BACKUP_PREFIX: ${MAUTIC_DB_BACKUP_PREFIX:-bak_} + MAUTIC_AUTO_INSTALL: ${MAUTIC_AUTO_INSTALL:-false} + MAUTIC_FORCE_INSTALL: ${MAUTIC_FORCE_INSTALL:-false} + MAUTIC_SITE_URL: ${MAUTIC_SITE_URL:-http://localhost} + MAUTIC_ADMIN_FIRSTNAME: ${MAUTIC_ADMIN_FIRSTNAME:-Admin} + MAUTIC_ADMIN_LASTNAME: ${MAUTIC_ADMIN_LASTNAME:-Mautic} + MAUTIC_ADMIN_USERNAME: ${MAUTIC_ADMIN_USERNAME:-admin} + MAUTIC_ADMIN_EMAIL: ${MAUTIC_ADMIN_EMAIL:-admin@example.com} + MAUTIC_ADMIN_PASSWORD: ${MAUTIC_ADMIN_PASSWORD:-ChangeMe123!} MAUTIC_RUN_CRON_JOBS: ${MAUTIC_RUN_CRON_JOBS:-true} XDEBUG_CONFIG: ${XDEBUG_CONFIG:-} MAUTIC_MESSENGER_DSN_EMAIL: ${MAUTIC_MESSENGER_DSN_EMAIL:-doctrine://default} @@ -19,7 +31,7 @@ x-mautic-environments: &mautic-environments services: mautic_web: - image: ghcr.io/librecodecoop/mautic:${MAUTIC_VERSION:-5.x-dev}-${IMAGE_TYPE:-apache} + image: ghcr.io/librecodecoop/mautic:${MAUTIC_VERSION:-7.x-dev}-${IMAGE_TYPE:-apache} # build: # context: .docker/ # dockerfile: Dockerfile.${IMAGE_TYPE:-apache} @@ -37,7 +49,7 @@ services: retries: 100 mautic_cron: - image: ghcr.io/librecodecoop/mautic:${MAUTIC_VERSION:-5.x-dev}-${IMAGE_TYPE:-apache} + image: ghcr.io/librecodecoop/mautic:${MAUTIC_VERSION:-7.x-dev}-${IMAGE_TYPE:-apache} # build: # context: .docker/ # dockerfile: Dockerfile.${IMAGE_TYPE:-apache} @@ -51,7 +63,7 @@ services: condition: service_healthy mautic_worker: - image: ghcr.io/librecodecoop/mautic:${MAUTIC_VERSION:-5.x-dev}-${IMAGE_TYPE:-apache} + image: ghcr.io/librecodecoop/mautic:${MAUTIC_VERSION:-7.x-dev}-${IMAGE_TYPE:-apache} # build: # context: .docker/ # dockerfile: Dockerfile.${IMAGE_TYPE:-apache} diff --git a/volumes/mautic/docroot/plugins/MauticCrmBundle b/volumes/mautic/docroot/plugins/MauticCrmBundle new file mode 160000 index 00000000..7d68d72e --- /dev/null +++ b/volumes/mautic/docroot/plugins/MauticCrmBundle @@ -0,0 +1 @@ +Subproject commit 7d68d72ecd099a88358851cf32107b9f8ccc672d