Skip to content

Commit c196e60

Browse files
committed
Makefile+patches
1 parent 3ddc077 commit c196e60

4 files changed

Lines changed: 100 additions & 0 deletions

File tree

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
VERSION=v1.142.1
2+
3+
all: build-main push-main build-e2e push-e2e
4+
5+
build-main:
6+
DOCKER_BUILDKIT=1 docker build -t ghcr.io/code-tool/matrix-stack/synapse:${VERSION} --build-arg SYNAPSE_PKG_VER=${VERSION} --target main -f build/Dockerfile build
7+
8+
push-main: build-main
9+
docker push ghcr.io/code-tool/matrix-stack/synapse:${VERSION}
10+
11+
build-e2e:
12+
DOCKER_BUILDKIT=1 docker build -t ghcr.io/code-tool/matrix-stack/synapse:${VERSION}-e2e-optimized --build-arg SYNAPSE_PKG_VER=${VERSION} --target e2e -f build/Dockerfile build
13+
14+
push-e2e: build-e2e
15+
docker push ghcr.io/code-tool/matrix-stack/synapse:${VERSION}-e2e-optimized

build/Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
ARG SYNAPSE_PKG_VER="v1.142.1"
2+
ARG PYTHON_PKG_VER="3.13"
3+
4+
# stage 1 : build pip
5+
FROM matrixdotorg/synapse:${SYNAPSE_PKG_VER} AS pipwheels
6+
RUN apt-get update \
7+
&& apt-get install -y --no-install-recommends \
8+
git \
9+
build-essential \
10+
patch \
11+
libpq-dev\
12+
&& rm -rf /var/cache/apt/*
13+
WORKDIR /wheels
14+
RUN pip install psycopg2
15+
RUN pip wheel --no-cache-dir --wheel-dir /wheels \
16+
git+https://github.com/matrix-org/synapse-s3-storage-provider.git@2dbba1020fe6fb84d79f1a23c925e508d9ba15e1 \
17+
git+https://gitlab.com/zerodotfive/googlesamlhandler.git@cb239e5d98bbe00465945c49661a9ca9ca134328
18+
19+
# stage 2 : apply workers.patch
20+
FROM pipwheels as workers_patch
21+
ARG PYTHON_PKG_VER
22+
COPY workers.patch /tmp/workers.patch
23+
RUN patch $(ls /usr/local/lib/python$PYTHON_PKG_VER/site-packages/synapse/config/workers.py) \
24+
< /tmp/workers.patch \
25+
&& rm /tmp/workers.patch
26+
27+
# stage 3 : apply e2e_room_keys.patch
28+
FROM pipwheels as e2e_patch
29+
ARG PYTHON_PKG_VER
30+
COPY e2e_room_keys.patch /tmp/e2e_room_keys.patch
31+
RUN patch $(ls /usr/local/lib/python${PYTHON_PKG_VER}/site-packages/synapse/storage/databases/main/e2e_room_keys.py) \
32+
< /tmp/e2e_room_keys.patch \
33+
&& rm /tmp/e2e_room_keys.patch
34+
35+
# stage 4 : base version with workers names
36+
FROM matrixdotorg/synapse:$SYNAPSE_PKG_VER as main
37+
ARG PYTHON_PKG_VER
38+
RUN --mount=type=bind,from=pipwheels,source=/wheels,target=/wheels \
39+
pip install --no-cache-dir /wheels/*
40+
COPY --from=workers_patch \
41+
/usr/local/lib/python${PYTHON_PKG_VER}/site-packages/synapse/config/workers.py \
42+
/usr/local/lib/python${PYTHON_PKG_VER}/site-packages/synapse/config/workers.py
43+
44+
# stage 5 : base version with e2e_room_keys table optimization
45+
FROM main as e2e
46+
ARG PYTHON_PKG_VER
47+
COPY --from=e2e_patch \
48+
/usr/local/lib/python${PYTHON_PKG_VER}/site-packages/synapse/storage/databases/main/e2e_room_keys.py \
49+
/usr/local/lib/python${PYTHON_PKG_VER}/site-packages/synapse/storage/databases/main/e2e_room_keys.py

build/e2e_room_keys.patch

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--- a/synapse/storage/databases/main/e2e_room_keys.py
2+
+++ b/synapse/storage/databases/main/e2e_room_keys.py
3+
@@ -400,13 +400,16 @@ class EndToEndRoomKeyStore(EndToEndRoomKeyBackgroundStore):
4+
# it doesn't exist.
5+
return 0
6+
7+
- return await self.db_pool.simple_select_one_onecol(
8+
- table="e2e_room_keys",
9+
+ row = await self.db_pool.simple_select_one_onecol(
10+
+ table="e2e_room_keys_counts",
11+
keyvalues={"user_id": user_id, "version": version_int},
12+
- retcol="COUNT(*)",
13+
+ retcol="cnt",
14+
desc="count_e2e_room_keys",
15+
+ allow_none=True,
16+
)
17+
18+
+ return row or 0
19+
+
20+
@trace
21+
async def delete_e2e_room_keys(
22+
self,

build/workers.patch

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--- workers.py 2023-08-30 15:13:45.131604043 +0300
2+
+++ workers.py 2023-08-30 15:19:35.119581079 +0300
3+
@@ -225,7 +225,10 @@
4+
# The shared secret used for authentication when connecting to the main synapse.
5+
self.worker_replication_secret = config.get("worker_replication_secret", None)
6+
7+
- self.worker_name = config.get("worker_name", self.worker_app)
8+
+ from os import environ
9+
+ self.worker_name = self.worker_app
10+
+ if self.worker_app:
11+
+ self.worker_name = config.get("worker_name", environ.get("HOSTNAME"))
12+
self.instance_name = self.worker_name or MAIN_PROCESS_INSTANCE_NAME
13+
14+
# FIXME: Remove this check after a suitable amount of time.

0 commit comments

Comments
 (0)