EspoCRM role: custom image + single data volume + runtime flag setter

• Build a custom image and replace upstream entrypoint with docker-entrypoint-custom.sh (strict fail on flag script).

• Introduce set_flags.php and wire via ESPOCRM_SET_FLAGS_SCRIPT; apply flags at container start; clear cache afterwards.

• Keep exactly one Docker volume (data:/var/www/html/); drop separate custom/extensions mounts.

• Compose: use custom image, add healthchecks & depends_on for daemon/websocket; keep service healthy gating.

• Ansible: deploy scripts, build & up via handlers; patch siteUrl as www-data; run upgrade non-fatal; always run flag setter.

• Vars/Env: add ESPO_INIT_* toggles and ESPOCRM_SET_FLAGS_SCRIPT; refactor variables for scripts & custom image paths.

Conversation context: https://chatgpt.com/share/68dd1992-020c-800f-bcf5-2db60cb4aab2
This commit is contained in:
2025-10-01 14:08:09 +02:00
parent 09a4c243d7
commit e7702948b8
9 changed files with 216 additions and 81 deletions

View File

@@ -37,7 +37,7 @@
- name: Ensure siteUrl matches canonical domain
ansible.builtin.shell: |
{{ docker_compose_command_exec }} -T {{ ESPOCRM_SERVICE }} php -r '
{{ docker_compose_command_exec }} -T --user {{ ESPOCRM_USER }} {{ ESPOCRM_SERVICE }} php -r '
require "/var/www/html/bootstrap.php";
$app = new \Espo\Core\Application();
$c = $app->getContainer();
@@ -54,57 +54,3 @@
chdir: "{{ docker_compose.directories.instance }}"
register: siteurl_set
changed_when: "'CHANGED' in siteurl_set.stdout"
- name: Ensure maintenance off, cron on, cache on (idempotent via ConfigWriter)
block:
- name: Apply config via ConfigWriter as app user
command: >
docker exec --user {{ ESPOCRM_USER }} {{ ESPOCRM_CONTAINER }}
php -r '
require "/var/www/html/bootstrap.php";
$app = new \Espo\Core\Application();
$c = $app->getContainer();
$cfg = $c->get("config");
$w = $c->get("injectableFactory")->create("\Espo\Core\Utils\Config\ConfigWriter");
$pairs = [
"maintenanceMode" => false,
"cronDisabled" => false,
"useCache" => true
];
$changed = false;
foreach ($pairs as $k => $v) {
if ($cfg->get($k) !== $v) { $w->set($k, $v); $changed = true; }
}
if ($changed) { $w->save(); echo "CHANGED"; }
'
register: cfg_set
changed_when: "'CHANGED' in cfg_set.stdout"
rescue:
- name: Apply config via ConfigWriter as root (fallback)
command: >
docker exec --user root {{ ESPOCRM_CONTAINER }}
php -r '
require "/var/www/html/bootstrap.php";
$app = new \Espo\Core\Application();
$c = $app->getContainer();
$cfg = $c->get("config");
$w = $c->get("injectableFactory")->create("\Espo\Core\Utils\Config\ConfigWriter");
$pairs = [
"maintenanceMode" => false,
"cronDisabled" => false,
"useCache" => true
];
$changed = false;
foreach ($pairs as $k => $v) {
if ($cfg->get($k) !== $v) { $w->set($k, $v); $changed = true; }
}
if ($changed) { $w->save(); echo "CHANGED"; }
'
register: cfg_set
changed_when: "'CHANGED' in cfg_set.stdout"
- name: Clear EspoCRM cache (only when config changed and we are updating)
command: >
docker exec --user {{ ESPOCRM_USER }} {{ ESPOCRM_CONTAINER }} php clear_cache.php
when: "'CHANGED' in cfg_set.stdout and MODE_UPDATE | bool"

View File

@@ -3,17 +3,53 @@
include_role:
name: sys-stk-full-stateful
vars:
docker_compose_flush_handlers: true
docker_compose_flush_handlers: false
- name: "Deploy '{{ ESPOCRM_ENTRYPOINT_SCRIPT_HOST_ABS }}'"
copy:
src: "{{ ESPOCRM_ENTRYPOINT_SCRIPT_FILE }}"
dest: "{{ ESPOCRM_ENTRYPOINT_SCRIPT_HOST_ABS }}"
notify:
- docker compose up
- docker compose build
- name: "Deploy '{{ ESPOCRM_SET_FLAG_SCRIPT_HOST_ABS }}'"
copy:
src: "{{ ESPOCRM_SET_FLAG_SCRIPT_FILE }}"
dest: "{{ ESPOCRM_SET_FLAG_SCRIPT_HOST_ABS }}"
notify:
- docker compose up
- docker compose build
- name: "Docker Compose Up for '{{ application_id }}'"
meta: flush_handlers
- name: Check if config.php exists in EspoCRM
command: docker exec --user root {{ ESPOCRM_CONTAINER }} test -f {{ ESPOCRM_CONFIG_FILE_PRIVATE }}
register: config_file_exists
changed_when: false
failed_when: false
failed_when: false
- name: Patch EspoCRM config.php
include_tasks: 01_patch_config.yml
when: config_file_exists.rc == 0
- name: Run EspoCRM upgrade (only when MODE_UPDATE is true)
command: >
docker exec --user {{ ESPOCRM_USER }} {{ ESPOCRM_CONTAINER }}
php command.php upgrade -y
register: espocrm_upgrade
changed_when: "'Upgrading' in espocrm_upgrade.stdout or 'successfully' in espocrm_upgrade.stdout"
failed_when: false
when: MODE_UPDATE | bool
- name: Run flag setter as root (fallback)
command: >
docker exec --user root {{ ESPOCRM_CONTAINER }}
php {{ ESPOCRM_SET_FLAG_SCRIPT_DOCKER }}
register: flags_result_root
changed_when: "'CHANGED' in flags_result_root.stdout"
- name: Flush handlers to make DB available before password reset
meta: flush_handlers