From faf3db7d496e053c9519103c3b0e9bdc5b6f7023 Mon Sep 17 00:00:00 2001 From: Gitouche <26656-gitouche@users.noreply.framagit.org> Date: Sat, 29 Jul 2023 15:51:24 +0200 Subject: [PATCH] matrix : refonte avec podman-compose --- podman-matrix/.gitlab-ci.yml | 4 +-- podman-matrix/10_install.sh | 46 ++++++++++++++++++++--------- podman-matrix/container-compose.yml | 28 ++++++++++++++++++ podman-matrix/vars.sh | 4 +-- 4 files changed, 64 insertions(+), 18 deletions(-) create mode 100644 podman-matrix/container-compose.yml diff --git a/podman-matrix/.gitlab-ci.yml b/podman-matrix/.gitlab-ci.yml index 577ca61..c4cb1b5 100644 --- a/podman-matrix/.gitlab-ci.yml +++ b/podman-matrix/.gitlab-ci.yml @@ -6,8 +6,8 @@ before_script: - podman container rm --force synapse-generate - podman container rm --force buildkitd - rm -f ~/.config/systemd/user/pod-podman-matrix.service && systemctl --user daemon-reload - - podman volume rm --force matrixdotorg_synapse-data - - podman volume rm --force matrixdotorg_synapse-pgsql + - podman volume rm --force podman-matrix_matrixdotorg_synapse-data + - podman volume rm --force podman-matrix_matrixdotorg_synapse-pgsql matrix: stage: test diff --git a/podman-matrix/10_install.sh b/podman-matrix/10_install.sh index e7eacc9..3b298cb 100755 --- a/podman-matrix/10_install.sh +++ b/podman-matrix/10_install.sh @@ -20,25 +20,43 @@ if ! podman volume exists ${dbvolume} ; then exit 1 fi +cat <> .env +POSTGRES_PASSWORD=${GARBAYE_MATRIX_POSTGRES_PASSWORD} +POSTGRES_USER=${container_name} +POSTGRES_DB=${container_name} +POSTGRES_INITDB_ARGS=--encoding=UTF8 --locale=C +EOT + +export postgres_image +export postgres_version +export synapse_image +export synapse_version +export listen_if +export listen_port + if ! podman image exists ${synapse_image}:${synapse_version}; then podman image pull ${synapse_image}:${synapse_version} || exit 1 fi podman image pull ${postgres_image}:${postgres_version} && -if ! podman network exists ${project_name}_default; then - podman network create ${project_name}_default -fi -podman pod create --name ${pod_name} --infra=true --infra-name=${project_name}_infra --share='' && -podman container run -d --name ${db_container_name} --pod ${pod_name} --requires=${project_name}_infra --net ${project_name}_default \ - --mount type=volume,src=${dbvolume},dst=/var/lib/postgresql/data/ \ - -e POSTGRES_PASSWORD=${GARBAYE_MATRIX_POSTGRES_PASSWORD} \ - -e POSTGRES_USER=${container_name} \ - -e POSTGRES_DB=${container_name} \ - -e POSTGRES_INITDB_ARGS="--encoding=UTF8 --locale=C" \ - ${postgres_image}:${postgres_version} && -podman container run -d --name ${container_name} --pod ${pod_name} --requires=${project_name}_infra --net ${project_name}_default \ - --mount type=volume,src=${confvolume},dst=/data --publish ${listen_if}:${listen_port}:8008 ${synapse_image}:${synapse_version} && +podman-compose --pod-args="--infra=true --infra-name=${project_name}_infra --share=" --podman-run-args "--requires=${project_name}_infra --env-file .env" up -d && + +end=$((SECONDS+30)) +while [ $SECONDS -lt $end ]; do + sleep 1 + if check_container_running synapse; then + podman logs synapse 2>&1 | grep -qe 'Preparing for databases' && + break + else + podman logs synapse 2>&1 | grep -qe 'psycopg2.OperationalError: could not connect to server: Connection refused' && + podman healthcheck run synapse-db && + echo "Oops, synapse didn't wait for PostgreSQL, restarting" + podman start synapse + fi +done && + echo -n "Waiting for background tasks to end... " && -( podman container logs -f ${container_name} 2>&1 & ) | grep -q 'No more background updates to do' && +( podman container logs --tail=10 -f ${container_name} 2>&1 & ) | grep -q 'No more background updates to do' && echo "OK." && podman pod stop ${pod_name} && echo "Done. Pod built and stopped." +shred -u .env diff --git a/podman-matrix/container-compose.yml b/podman-matrix/container-compose.yml new file mode 100644 index 0000000..3856d8f --- /dev/null +++ b/podman-matrix/container-compose.yml @@ -0,0 +1,28 @@ + +services: + synapse-db: + image: "${postgres_image}:${postgres_version}" + container_name: synapse-db + volumes: + - matrixdotorg_synapse-pgsql:/var/lib/postgresql/data/:Z + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + + synapse: + image: "${synapse_image}:${synapse_version}" + container_name: synapse + ports: + - ${listen_if}:${listen_port}:8008 + volumes: + - matrixdotorg_synapse-data:/data:Z + depends_on: + synapse-db: + condition: service_healthy + restart: true + +volumes: + matrixdotorg_synapse-pgsql: + matrixdotorg_synapse-data: diff --git a/podman-matrix/vars.sh b/podman-matrix/vars.sh index 2ca49e2..226d386 100644 --- a/podman-matrix/vars.sh +++ b/podman-matrix/vars.sh @@ -14,7 +14,7 @@ project_name=${PWD##*/} pod_name="pod_${project_name}" service_name="pod-${pod_name}.service" upstream_images="${synapse_image} ${postgres_image}" -confvolume='matrixdotorg_synapse-data' -dbvolume='matrixdotorg_synapse-pgsql' +confvolume='podman-matrix_matrixdotorg_synapse-data' +dbvolume='podman-matrix_matrixdotorg_synapse-pgsql' container_name='synapse' db_container_name='synapse-db'