diff --git a/web1/ansible/migrations/20261115_0006_check_calcom_postgres_volume.yml b/web1/ansible/migrations/20261115_0006_check_calcom_postgres_volume.yml new file mode 100644 index 00000000..c63c3468 --- /dev/null +++ b/web1/ansible/migrations/20261115_0006_check_calcom_postgres_volume.yml @@ -0,0 +1,39 @@ +--- +# Migration: 20261115_0006_check_calcom_postgres_volume +# Description: Make sure calcom's database is in calcom_database before the +# compose file mounts that volume at /var/lib/postgresql +# Background: calcom mounted calcom_database at /var/lib/postgresql/data. The +# PostgreSQL 18 images it was created with shipped /var/lib/postgresql/data +# as a symlink to `.`, so Docker resolved the mount to /var/lib/postgresql +# and the database (PGDATA /var/lib/postgresql/18/docker) landed in +# calcom_database, even though `docker inspect` shows the configured path. +# Current images no longer have the symlink: with a fresh anonymous volume, +# as after `docker compose down` + `up`, calcom_database would be mounted on a +# real /data directory, PGDATA would be empty, and the entrypoint would refuse +# to start +# Solution: the compose file now mounts calcom_database at /var/lib/postgresql. +# That only finds the database if it is in calcom_database/18/docker, so +# fail the deploy, before anything is stopped or changed, when the volume +# exists without it. Without the volume there is nothing to keep (new install) + +- name: Inspect the calcom_database volume + community.docker.docker_volume_info: + name: calcom_database + register: calcom_volume + +- name: Read the PostgreSQL version in calcom_database + ansible.builtin.slurp: + src: "{{ calcom_volume.volume.Mountpoint }}/18/docker/PG_VERSION" + register: calcom_pg_version + failed_when: false + when: calcom_volume.exists + +- name: Require calcom's database in calcom_database + ansible.builtin.assert: + that: calcom_pg_version.content | default('') | b64decode | trim == '18' + fail_msg: >- + calcom_database has no PostgreSQL 18 data directory at 18/docker, so the new + compose file would start calcom on an empty database. Find the volume that + calcom-database-1 really keeps 18/docker in and copy it into calcom_database + before deploying. + when: calcom_volume.exists diff --git a/web1/containers/calcom/docker-compose.yml b/web1/containers/calcom/docker-compose.yml index 354a81a1..297b4b0d 100644 --- a/web1/containers/calcom/docker-compose.yml +++ b/web1/containers/calcom/docker-compose.yml @@ -3,8 +3,11 @@ services: database: image: postgres:18.7-alpine3.23@sha256:60aac580d8dbe3093c097bb1d11f9e62999814d3a1da2c1aaf729c0b7db117f2 restart: unless-stopped + environment: + # PG18: version-specific PGDATA; volume mounts at /var/lib/postgresql + PGDATA: /var/lib/postgresql/18/docker volumes: - - database:/var/lib/postgresql/data + - database:/var/lib/postgresql env_file: - .env healthcheck: diff --git a/web3/ansible/migrations/20261115_0005_check_calcom_postgres_volume.yml b/web3/ansible/migrations/20261115_0005_check_calcom_postgres_volume.yml new file mode 100644 index 00000000..0823e46d --- /dev/null +++ b/web3/ansible/migrations/20261115_0005_check_calcom_postgres_volume.yml @@ -0,0 +1,39 @@ +--- +# Migration: 20261115_0005_check_calcom_postgres_volume +# Description: Make sure calcom's database is in calcom_database before the +# compose file mounts that volume at /var/lib/postgresql +# Background: calcom mounted calcom_database at /var/lib/postgresql/data. The +# PostgreSQL 18 images it was created with shipped /var/lib/postgresql/data +# as a symlink to `.`, so Docker resolved the mount to /var/lib/postgresql +# and the database (PGDATA /var/lib/postgresql/18/docker) landed in +# calcom_database, even though `docker inspect` shows the configured path. +# Current images no longer have the symlink: with a fresh anonymous volume, +# as after `docker compose down` + `up`, calcom_database would be mounted on a +# real /data directory, PGDATA would be empty, and the entrypoint would refuse +# to start +# Solution: the compose file now mounts calcom_database at /var/lib/postgresql. +# That only finds the database if it is in calcom_database/18/docker, so +# fail the deploy, before anything is stopped or changed, when the volume +# exists without it. Without the volume there is nothing to keep (new install) + +- name: Inspect the calcom_database volume + community.docker.docker_volume_info: + name: calcom_database + register: calcom_volume + +- name: Read the PostgreSQL version in calcom_database + ansible.builtin.slurp: + src: "{{ calcom_volume.volume.Mountpoint }}/18/docker/PG_VERSION" + register: calcom_pg_version + failed_when: false + when: calcom_volume.exists + +- name: Require calcom's database in calcom_database + ansible.builtin.assert: + that: calcom_pg_version.content | default('') | b64decode | trim == '18' + fail_msg: >- + calcom_database has no PostgreSQL 18 data directory at 18/docker, so the new + compose file would start calcom on an empty database. Find the volume that + calcom-database-1 really keeps 18/docker in and copy it into calcom_database + before deploying. + when: calcom_volume.exists diff --git a/web3/containers/calcom/docker-compose.yml b/web3/containers/calcom/docker-compose.yml index 354a81a1..297b4b0d 100644 --- a/web3/containers/calcom/docker-compose.yml +++ b/web3/containers/calcom/docker-compose.yml @@ -3,8 +3,11 @@ services: database: image: postgres:18.7-alpine3.23@sha256:60aac580d8dbe3093c097bb1d11f9e62999814d3a1da2c1aaf729c0b7db117f2 restart: unless-stopped + environment: + # PG18: version-specific PGDATA; volume mounts at /var/lib/postgresql + PGDATA: /var/lib/postgresql/18/docker volumes: - - database:/var/lib/postgresql/data + - database:/var/lib/postgresql env_file: - .env healthcheck: