diff --git a/.env.sample b/.env.sample index 6d9daf5..5bb33e7 100644 --- a/.env.sample +++ b/.env.sample @@ -5,19 +5,19 @@ DOMAIN=civicrm.example.com ## Domain aliases #EXTRA_DOMAINS=', `www.civicrm.example.com`' -LETS_ENCRYPT_ENV=productionaber +LETS_ENCRYPT_ENV=production PROJECT_NAME=example +CIVICRM_COMPONENTS=CiviEvent,CiviContribute,CiviMember,CiviMail,CiviReport + CIVICRM_DB_NAME=civicrm CIVICRM_DB_USER=civicrm -CIVICRM_DB_PASS=xxx CIVICRM_DB_HOST=mysql CIVICRM_DB_PORT=3306 WORDPRESS_DB_NAME=wordpress WORDPRESS_DB_USER=wordpress -WORDPRESS_DB_PASS=xxx WORDPRESS_DB_HOST=mysql WORDPRESS_DB_PORT=3306 # WORDPRESS_TABLE_PREFIX diff --git a/civicrm.settings.php.generated b/civicrm.settings.php.generated new file mode 100644 index 0000000..8ad2bc0 --- /dev/null +++ b/civicrm.settings.php.generated @@ -0,0 +1,626 @@ + Resource URLs) + // $civicrm_setting['domain']['imageUploadURL'] = 'http://example.com/example-image-upload-url'; + + // Override the Custom CiviCRM CSS URL + // $civicrm_setting['domain']['customCSSURL'] = 'http://example.com/example-css-url' ; + + // Override the extensions resource URL + // $civicrm_setting['domain']['extensionsURL'] = 'http://example.com/pathtoextensiondir' + + // Disable display of Community Messages on home dashboard + // $civicrm_setting['domain']['communityMessagesUrl'] = false; + + // Disable automatic download / installation of extensions + // $civicrm_setting['domain']['ext_repo_url'] = false; + + // set triggers to be managed offline per CRM-18212 + // $civicrm_setting['domain']['logging_no_trigger_permission'] = 1; + + // Override the CMS root path defined by cmsRootPath. + // define('CIVICRM_CMSDIR', '/path/to/install/root/'); + + // Opt-out of announcements by the CiviCRM core team for releases, paid services, events, etc. Separate each preferred optout category with a comma: + // "offers": paid service offers + // "asks": requests for donations or membership signup/renewal to CiviCRM + // "releases": major release announcements + // "events": announcements of local/national upcoming events + // $civicrm_setting['domain']['communityMessagesUrl'] = 'https://alert.civicrm.org/alert?prot=1&ver={ver}&uf={uf}&sid={sid}&lang={lang}&co={co}&optout=offers,asks'; + + +/** + * If you are using any CiviCRM script in the bin directory that + * requires authentication, then you also need to set this key. + * We recommend using a 16-32 bit alphanumeric/punctuation key. + * More info at https://docs.civicrm.org/sysadmin/en/latest/setup/site-key/ + */ +if (!defined('CIVICRM_SITE_KEY')) { + define( 'CIVICRM_SITE_KEY', 'MaR3BWB95goByZnT5l2ti5IKGrMs6nda0O5ew07AU'); +} + +/** + * If credentials are stored in the database, the CIVICRM_CRED_KEYS will be + * used to encrypt+decrypt them. This is a space-delimited list of keys (ordered by + * priority). Put the preferred key first. Any old/deprecated keys may be + * listed after. + * + * Each key is in format "::", as in: + * + * Ex: define('CIVICRM_CRED_KEYS', 'aes-cbc:hkdf-sha256:RANDOM_1') + * Ex: define('CIVICRM_CRED_KEYS', 'aes-ctr-hs:b64:RANDOM_2 aes-ctr-hs:b64:RANDOM_3') + * Ex: define('CIVICRM_CRED_KEYS', '::MY_NEW_KEY ::MY_OLD_KEY') + * + * If cipher-suite or key-encoding is blank, they will use defaults ("aes-cbc" + * and "hkdf-sha256", respectively). + * + * More info at https://docs.civicrm.org/sysadmin/en/latest/setup/cred-key/ + */ +if (!defined('CIVICRM_CRED_KEYS') ) { + define( '_CIVICRM_CRED_KEYS', 'aes-cbc:hkdf-sha256:B5KYVWAGhBWh2Kf6J7yFiFStRCXVGrgGZ4y3EFtqFrsHGhoR8w'); + define( 'CIVICRM_CRED_KEYS', _CIVICRM_CRED_KEYS === '%%' . 'credKeys' . '%%' ? '' : _CIVICRM_CRED_KEYS ); + // Some old installers may not set a decent value, and this extra complexity is a failsafe. + // Feel free to simplify post-install. +} + +/** + * The signing key is used to generate and verify shareable tokens. + * + * This is a space-delimited list of keys (ordered by priority). Put the preferred + * key first. Any old/deprecated keys may be listed after. + * + * Each key is in format "::", as in: + * + * Ex: define('CIVICRM_SIGN_KEYS', 'jwt-hs256:hkdf-sha256:RANDOM_1') + * Ex: define('CIVICRM_SIGN_KEYS', 'jwt-hs256::RANDOM_2 jwt-hs256::RANDOM_3') + * Ex: define('CIVICRM_SIGN_KEYS', 'jwt-hs256:b64:RANDOM_4 jwt-hs256:b64:RANDOM_5') + * + * If key-encoding is blank, it will default to "hkdf-sha256". + */ +if (!defined('CIVICRM_SIGN_KEYS') ) { + define( '_CIVICRM_SIGN_KEYS', 'jwt-hs256:hkdf-sha256:R2dUDp0fu6mVM9TQ3ym2w36yDZkzxzjjAxBig5PYBUbBtVYvQVkGQ'); + define( 'CIVICRM_SIGN_KEYS', _CIVICRM_SIGN_KEYS === '%%' . 'signKeys' . '%%' ? '' : _CIVICRM_SIGN_KEYS ); + // Some old installers may not set a decent value, and this extra complexity is a failsafe. + // Feel free to simplify post-install. +} + +/** + * Enable this constant, if you want to send your email through the smarty + * templating engine(allows you to do conditional and more complex logic) + * + */ +if (!defined('CIVICRM_MAIL_SMARTY')) { + define( 'CIVICRM_MAIL_SMARTY', 0 ); +} + +/** + * This setting logs all emails to a file. Useful for debugging any mail (or civimail) issues. + * Enabling this setting will not send any email, ensure this is commented out in production + * The CIVICRM_MAIL_LOG is a debug option which disables MTA (mail transport agent) interaction. + * You must disable CIVICRM_MAIL_LOG before CiviCRM will talk to your MTA. + */ +// if (!defined('CIVICRM_MAIL_LOG')) { +// define( 'CIVICRM_MAIL_LOG', '/var/www/html/wp-content/uploads/civicrm/templates_c/mail.log'); +// } + +/** + * This setting will only work if CIVICRM_MAIL_LOG is defined. Mail will be logged and then sent. + */ +//if (!defined('CIVICRM_MAIL_LOG_AND_SEND')) { +// define( 'CIVICRM_MAIL_LOG_AND_SEND', 1); +//} + + +if (!defined('CIVICRM_DOMAIN_ID')) { + define( 'CIVICRM_DOMAIN_ID', 1); +} + +/** + * Setting to define the environment in which this CiviCRM instance is running. + * Note the setting here must be value from the option group 'Environment', + * (see Administration > System Settings > Option Groups, Options beside Environment) + * which by default has three option values: 'Production', 'Staging', 'Development'. + * NB: defining a value for environment here prevents it from being set + * via the browser. + */ +// $civicrm_setting['domain']['environment'] = 'Production'; + +/** + * Settings to enable external caching using a cache server. This is an + * advanced feature, and you should read and understand the documentation + * before you turn it on. We cannot store these settings in the DB since the + * config could potentially also be cached and we need to avoid an infinite + * recursion scenario. + * + * @see http://civicrm.org/node/126 + */ + +/** + * If you have a cache server configured and want CiviCRM to make use of it, + * set the following constant. You should only set this once you have your cache + * server up and working, because CiviCRM will not start up if your server is + * unavailable on the host and port that you specify. By default CiviCRM will use + * an in-memory array cache + * + * To use the php extension memcache use a value of 'Memcache' + * To use the php extension memcached use a value of 'Memcached' + * To use the php extension apc use a value of 'APCcache' + * To use the php extension redis use a value of 'Redis' + * To not use any caching (not recommended), use a value of 'NoCache' + * + */ +if (!defined('CIVICRM_DB_CACHE_CLASS')) { + define('CIVICRM_DB_CACHE_CLASS', 'ArrayCache'); +} + +/** + * Change this to the IP address of your cache server if it is not on the + * same machine (Unix). + */ +if (!defined('CIVICRM_DB_CACHE_HOST')) { + define('CIVICRM_DB_CACHE_HOST', 'localhost'); +} + +/** + * Change this if you are not using the standard port for your cache server. + * + * The standard port for Memcache & APCCache is 11211. For Redis it is 6379. + */ +if (!defined('CIVICRM_DB_CACHE_PORT')) { + if (CIVICRM_DB_CACHE_CLASS === 'Redis') { + define('CIVICRM_DB_CACHE_PORT', 6379 ); + } + else { + define('CIVICRM_DB_CACHE_PORT', 11211); + } +} + +/** + * Change this if your cache server requires a password (currently only works + * with Redis) + */ +if (!defined('CIVICRM_DB_CACHE_PASSWORD')) { + define('CIVICRM_DB_CACHE_PASSWORD', '' ); +} + +/** + * Items in cache will expire after the number of seconds specified here. + * Default value is 3600 (i.e., after an hour) + */ +if (!defined('CIVICRM_DB_CACHE_TIMEOUT')) { + define('CIVICRM_DB_CACHE_TIMEOUT', 3600 ); +} + +/** + * If you are sharing the same cache instance with more than one CiviCRM + * database, you will need to set a different value for the following argument + * so that each copy of CiviCRM will not interfere with other copies. If you only + * have one copy of CiviCRM, you may leave this set to ''. A good value for + * this if you have two servers might be 'server1_' for the first server, and + * 'server2_' for the second server. + */ +if (!defined('CIVICRM_DB_CACHE_PREFIX')) { + define('CIVICRM_DB_CACHE_PREFIX', ''); +} + +/** + * The cache system traditionally allowed a wide range of cache-keys, but some + * cache-keys are prohibited by PSR-16. + */ +if (!defined('CIVICRM_PSR16_STRICT')) { + define('CIVICRM_PSR16_STRICT', FALSE); +} + +/** + * If you have multilingual site and you are using the "inherit CMS language" + * configuration option, but wish to, for example, use fr_CA instead of the + * default fr_FR (for French), set one or more of the constants below to an + * appropriate regional value. + * + * Note that since 5.26.0 specifically https://github.com/civicrm/civicrm-core/pull/16700 + * This generally doesn't get used by WordPress especially if using the Polylang plugin. + * The reason is that the WordPress implementation has been changed to get the full locale + * from the WordPress plugin rather than just the 2 string language code. + */ +// define('CIVICRM_LANGUAGE_MAPPING_FR', 'fr_CA'); +// define('CIVICRM_LANGUAGE_MAPPING_EN', 'en_CA'); +// define('CIVICRM_LANGUAGE_MAPPING_ES', 'es_MX'); +// define('CIVICRM_LANGUAGE_MAPPING_PT', 'pt_BR'); +// define('CIVICRM_LANGUAGE_MAPPING_ZH', 'zh_TW'); +// define('CIVICRM_LANGUAGE_MAPPING_NL', 'nl_BE'); + +/** + * Native gettext improves performance of localized CiviCRM installations + * significantly. However, your host must enable the locale (language). + * On most GNU/Linux, Unix or MacOSX systems, you may view them with + * the command line by typing: "locale -a". + * + * On Debian or Ubuntu, you may reconfigure locales with: + * # dpkg-reconfigure locales + * + * For more information: + * https://lab.civicrm.org/dev/translation/-/wikis/Administrator-Guide#native-gettext + */ +// if (!defined('CIVICRM_GETTEXT_NATIVE')) { +// define('CIVICRM_GETTEXT_NATIVE', 1); +// } + +/** + * Define how many times to retry a transaction when the DB hits a deadlock + * (ie. the database is locked by another transaction). This is an + * advanced setting intended for high-traffic databases & experienced developers/ admins. + */ +define('CIVICRM_DEADLOCK_RETRIES', 3); + +if (CIVICRM_UF === 'UnitTests') { + if (!defined('CIVICRM_CONTAINER_CACHE')) define('CIVICRM_CONTAINER_CACHE', 'auto'); +} + +/** + * Whether to include the hash in config log filenames. Defaults to TRUE. + * Disable only if you have configured the logfiles to be outside the docroot + * using the civicrm.log path setting. + * + */ +// if (!defined('CIVICRM_LOG_HASH')) { +// define('CIVICRM_LOG_HASH', FALSE ); +// } + +/** + * The maximum size a log file may be before it's rotated, in bytes. + * Set to 0 to disable rotation (only recommended if you have an + * external logrotate configuration). + */ +// if (!defined('CIVICRM_LOG_ROTATESIZE')) { +// define('CIVICRM_LOG_ROTATESIZE', 0 ); +// } + +/** + * Which directories should we exclude when scanning the codebase for things + * like extension .info files, or .html partials or .xml files etc. This needs + * to be a valid preg_match() pattern. + * + * If you do not define it, a pattern that excludes dirs starting with a dot is + * used, e.g. to exclude .git/). Adding suitable patterns here can vastly speed + * up your container rebuilds and cache flushes. The pattern is matched against + * the absolute path. Remember to use your system's DIRECTORY_SEPARATOR the + * examples below assume / + * + * The default excludes node_modules (can be huge), various CiviCRM dirs that + * are unlikely to have anything we need to scan inside, and (what could be + * your) Drupal's private file storage area. It does not exclude + * vendor but you are likely to see an improvement by adding it. + * + * See https://docs.civicrm.org/sysadmin/en/latest/setup/optimizations/#exclude-dirs-that-do-not-need-to-be-scanned + * and also discussion on including vendor (excluded) in https://lab.civicrm.org/dev/core/-/issues/2031 + */ +if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' && !defined('CIVICRM_EXCLUDE_DIRS_PATTERN')) { + define('CIVICRM_EXCLUDE_DIRS_PATTERN', '@/(\.|node_modules|js/|css/|bower_components|packages/|sites/default/files/private)@'); +} + +/** + * + * Do not change anything below this line. Keep as is + * + */ + +$include_path = '.' . PATH_SEPARATOR . + $civicrm_root . PATH_SEPARATOR . + $civicrm_root . DIRECTORY_SEPARATOR . 'packages' . PATH_SEPARATOR . + get_include_path( ); +if ( set_include_path( $include_path ) === false ) { + echo "Could not set the include path

"; + exit( ); +} + +if (!defined('CIVICRM_CLEANURL')) { + if (function_exists('variable_get') && variable_get('clean_url', '0') != '0') { + define('CIVICRM_CLEANURL', 1 ); + } + elseif ( function_exists('config_get') && config_get('system.core', 'clean_url') != 0) { + define('CIVICRM_CLEANURL', 1 ); + } + elseif( function_exists('get_option') && get_option('permalink_structure') != '' ) { + define('CIVICRM_CLEANURL', 1 ); + } + else { + define('CIVICRM_CLEANURL', 0); + } +} + +// force PHP to auto-detect Mac line endings +if (version_compare(PHP_VERSION, '8.1') < 0) { + ini_set('auto_detect_line_endings', '1'); +} + +// make sure the memory_limit is at least 64 MB +$memLimitString = trim(ini_get('memory_limit')); +$memLimitUnit = strtolower(substr($memLimitString, -1)); +$memLimit = (int) $memLimitString; +switch ($memLimitUnit) { + case 'g': $memLimit *= 1024; + case 'm': $memLimit *= 1024; + case 'k': $memLimit *= 1024; +} +if ($memLimit >= 0 and $memLimit < 134217728) { + ini_set('memory_limit', '128M'); +} + +require_once 'CRM/Core/ClassLoader.php'; +CRM_Core_ClassLoader::singleton()->register(); diff --git a/compose.yml b/compose.yml index c2a0a90..91edd08 100644 --- a/compose.yml +++ b/compose.yml @@ -13,6 +13,7 @@ services: - CIVICRM_DB_PASS_FILE=/run/secrets/db_password - CIVICRM_DB_HOST=civicrm-db - CIVICRM_DB_PORT=3306 + - CIVICRM_COMPONENTS - WORDPRESS_DB_NAME=wordpress - WORDPRESS_DB_USER=wordpress - WORDPRESS_DB_PASS_FILE=/run/secrets/db_password @@ -38,7 +39,7 @@ services: target: /etc/apache2/sites-available/000-default.conf - source: entrypoint target: /usr/local/bin/entrypoint.sh - mode: 0555 + mode: 555 - source: civicrm-settings-php target: /usr/local/etc/civicrm/civicrm.settings.php entrypoint: /usr/local/bin/entrypoint.sh @@ -59,13 +60,14 @@ services: - "backupbot.backup=true" - "backupbot.backup.path=/var/www/html/wp-content/uploads" healthcheck: - test: ["CMD", "cv", "api", "system.get"] + test: [ "CMD", "cv", "api", "system.get" ] interval: 30s timeout: 10s retries: 10 start_period: 10s - db: &db + db: + &db image: "mariadb:10.8" volumes: - "mariadb:/var/lib/mysql" @@ -78,7 +80,11 @@ services: - db_password - db_root_password healthcheck: - test: ["CMD-SHELL", 'mysqladmin -p"$$(cat /run/secrets/db_root_password)" ping'] + test: + [ + "CMD-SHELL", + 'mysqladmin -p"$$(cat /run/secrets/db_root_password)" ping' + ] interval: 30s timeout: 10s retries: 10 @@ -94,7 +100,6 @@ services: backupbot.restore: "true" backupbot.restore.post-hook: "sh -c 'mysql -u root -p\"$$(cat /run/secrets/db_root_password)\" $${MYSQL_DATABASE} < /tmp/dump.sql && rm -f /tmp/dump.sql'" - civicrm-db: <<: *db volumes: @@ -102,6 +107,8 @@ services: environment: - MYSQL_DATABASE=civicrm - MYSQL_USER=civicrm + - MYSQL_PASSWORD_FILE=/run/secrets/db_password + - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/db_root_password networks: proxy: @@ -112,6 +119,7 @@ volumes: civicrm-db: data: + configs: apache-sites-available-conf: name: ${STACK_NAME}_apache_sites_available_conf_${APACHE_SITES_AVAILABLE_CONF_VERSION} @@ -144,4 +152,4 @@ secrets: name: ${STACK_NAME}_civicrm_cred_key_${SECRET_CIVICRM_CRED_KEY_VERSION} civicrm_sign_key: external: true - name: ${STACK_NAME}_civicrm_sign_key_${SECRET_CIVICRM_SIGN_KEY_VERSION} \ No newline at end of file + name: ${STACK_NAME}_civicrm_sign_key_${SECRET_CIVICRM_SIGN_KEY_VERSION} diff --git a/cron.sh b/cron.sh new file mode 100644 index 0000000..e69de29 diff --git a/entrypoint.sh b/entrypoint.sh index 89c46d4..fbec8e2 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -29,20 +29,32 @@ file_env "CIVICRM_SITE_KEY" file_env "CIVICRM_CRED_KEYS" file_env "SMTP_PASSWORD" +if [[ "${1-default}" == "cron" ]]; then + echo "Running cron job" + env + /usr/local/bin/php /usr/local/bin/cv api job.execute --user=admin --cwd=/var/www/html/ + exit $? +fi + until mysql -e '\q' -h db -p"${WORDPRESS_DB_PASS}" && mysql -e '\q' -h "${CIVICRM_DB_HOST}" -p"${CIVICRM_DB_PASS}"; do echo "Waiting for db container to come up" sleep 1 done; -echo "=== Running Docker Entrypoint" +echo "Running Docker Entrypoint" /usr/local/bin/civicrm-docker-entrypoint -echo "Installing Wordpress" -su civicrm -c "wp core install --locale=de_DE --url=$BASE_URL --title=$PROJECT_NAME --admin_user=admin --admin_email=$SMTP_USER" -su civicrm -c "wp language core install de_DE" -su civicrm -c "wp language core activate de_DE" - +# Check if Wordpress already installed +if su civicrm -c "wp core is-installed"; then + echo "Wordpress already installed" +else + echo "Installing Wordpress" + su civicrm -c "wp core install --locale=de_DE --url=$BASE_URL --title=$PROJECT_NAME --admin_user=admin --admin_email=$SMTP_USER" + su civicrm -c "wp language core install de_DE" + su civicrm -c "wp language core activate de_DE" +fi +# Setup Civicrm L10n if ! [[ -d /var/www/html/wp-content/plugins/civicrm/civicrm/l10n ]]; then echo "=== Moving Civicrm L10n" pushd /var/www/html/wp-content/plugins/civicrm/ @@ -54,30 +66,33 @@ if ! [[ -d /var/www/html/wp-content/plugins/civicrm/civicrm/l10n ]]; then popd fi +# Install Civicrm if ! [[ -f /var/www/html/wp-content/uploads/civicrm/is_installed ]]; then pushd /var/www/html/wp-content/uploads/civicrm/ - echo "=== Running Civicrm Docker Install" + echo "Running Civicrm Docker Install" touch is_installed rm -rf civicrm.settings.php su civicrm -c "wp plugin activate civicrm" # TODO: extract module and extension stuff to .env - su civicrm -c "cv core:install -vv --keep --db=mysql://$CIVICRM_DB_USER:$CIVICRM_DB_PASS@$CIVICRM_DB_HOST:$CIVICRM_DB_PORT/$CIVICRM_DB_NAME --lang de_DE --comp CiviEvent,CiviMember" - + su civicrm -c "cv core:install -vv --keep --db=mysql://$CIVICRM_DB_USER:$CIVICRM_DB_PASS@$CIVICRM_DB_HOST:$CIVICRM_DB_PORT/$CIVICRM_DB_NAME --lang de_DE --comp $CIVICRM_COMPONENTS" mv civicrm.settings.php civicrm.settings.php.generated cp /usr/local/etc/civicrm/civicrm.settings.php civicrm.settings.php chmod a-wx /var/www/html/wp-content/uploads/civicrm/civicrm.settings.php chown -R civicrm:civicrm templates_c popd -else - echo "=== Running Civicrm Upgrade" - echo "=== well, not yet" - # TODO: Should we run a upgrade here? +fi + # TODO: How do we upgrade a existing civicrm installation? # * run dump backup # * check version specifig upgrade steps: https://docs.civicrm.org/sysadmin/en/latest/upgrade/version-specific/ # * run upgrade # * cv flush -fi -echo "=== Running Webserver" +echo "Setting up cron" +printenv > /etc/environment +apt update && apt install -y cron +crontab -l | { cat; echo "*/5 * * * * /usr/local/bin/entrypoint.sh cron > /tmp/cronlog 2>&1"; } | crontab - +cron + +echo "Running Webserver" exec apache2-foreground \ No newline at end of file