feat(web-app-espocrm): ensure 'siteUrl' is updated to canonical domain on deploy

Use EspoCRM's ConfigWriter API to patch the 'siteUrl' setting during updates.
This makes the process idempotent, avoids brittle regex replacements, and
ensures the running configuration stays in sync with the deployment domain.

https://chatgpt.com/share/689bb860-ba90-800f-adb5-4fa5a992b267
This commit is contained in:
2025-08-12 23:55:35 +02:00
parent c744ebe3f9
commit a4d8de2152

View File

@@ -21,3 +21,23 @@
docker exec --user root {{ espocrm_name }}
sed -i "s/'password' => .*/'password' => '{{ database_password }}',/" {{ espocrm_config_file }}
notify: docker compose restart
- name: Ensure siteUrl matches canonical domain
ansible.builtin.shell: |
docker compose exec -T web php -r '
require "/var/www/html/bootstrap.php";
$app = new \Espo\Core\Application();
$c = $app->getContainer();
$cfg = $c->get("config");
$writer = $c->get("injectableFactory")->create("\Espo\Core\Utils\Config\ConfigWriter");
$new = "{{ domains | get_url(application_id, WEB_PROTOCOL) }}";
if ($cfg->get("siteUrl") !== $new) {
$writer->set("siteUrl", $new);
$writer->save();
echo "CHANGED";
}
'
args:
chdir: "{{ docker_compose.directories.instance }}"
register: siteurl_set
changed_when: "'CHANGED' in siteurl_set.stdout"