Skip to content

Commit

Permalink
⚡️ make test synapse use postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
ad2ien committed Feb 21, 2024
1 parent 7cd653c commit de6eaf0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,5 @@ So far Keycloak version is set in the Dockerfile and in SPIs dependencies and th

## TODO

- [ ] Synapse db in PG

### SPI Dev

- [ ] kotlin
- [ ] tests
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ services:
image: postgres:15-alpine
volumes:
- keycloak-db:/var/lib/postgresql/data
- ./docker-test-config/db-init:/docker-entrypoint-initdb.d
ports:
- "5432:5432"
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=keycloak
- POSTGRES_MULTIPLE_DATABASES=synapse,keycloak
healthcheck:
test: ["CMD-SHELL", "sh -c 'pg_isready -U root -d keycloak'"]
interval: 10s
Expand Down Expand Up @@ -82,6 +83,8 @@ services:
depends_on:
keycloak-health:
condition: service_healthy
db:
condition: service_healthy
environment:
- SYNAPSE_CONFIG_PATH=/mx-conf/homeserver.yaml
- SSL_CERT_FILE=/mx-conf/cert/certificate.pem
Expand Down
22 changes: 22 additions & 0 deletions docker-test-config/db-init/multi-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e
set -u

function create_user_and_database() {
local database=$1
echo " Creating user and database '$database'"
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
CREATE USER $database;
CREATE DATABASE $database ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0;
GRANT ALL PRIVILEGES ON DATABASE $database TO $database;
EOSQL
}

if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES"
for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do
create_user_and_database $db
done
echo "Multiple databases created"
fi
13 changes: 10 additions & 3 deletions docker-test-config/mx-conf/homeserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ listeners:
- names: [client, federation]
compress: false
database:
name: sqlite3
name: psycopg2
txn_limit: 10000
args:
database: /data/homeserver.db
user: root
password: secret
dbname: synapse
host: db
port: 5432
cp_min: 5
cp_max: 10
log_config: "/data/matrix.local.log.config"
media_store_path: /data/media_store
registration_shared_secret: "rfFDSWR&.4C26b27gtCQuTp,*aSRf5sB.RMwL9G*39Kzf3r#T3"
Expand All @@ -41,7 +48,7 @@ oidc_providers:
skip_verification: true
issuer: "https://keycloak:8443/realms/eimis-realm"
client_id: "eimis-synapse"
client_secret: "PTE9SfKnTXy3f8vnhNc78MGxasnJThiK"
client_secret: "I_eat_kiwis_with_the_skin_on"
scopes: ["openid", "profile"]
user_mapping_provider:
config:
Expand Down

0 comments on commit de6eaf0

Please sign in to comment.