From d9214e47b57f09649e296f9880133aa9db1a0474 Mon Sep 17 00:00:00 2001 From: Vladan Popovic Date: Sat, 6 Feb 2021 00:42:54 +0100 Subject: [PATCH] Rework the build and include coturn and riot web --- alpine/matrix/build.sh | 18 +++++++++--------- alpine/matrix/scripts/install-matrix.sh | 13 +++++++++++++ alpine/matrix/scripts/install-pip.sh | 7 +++---- alpine/matrix/scripts/install-riot.sh | 10 ++++++++++ alpine/matrix/scripts/install-turn.sh | 15 +++++++++++++++ alpine/matrix/scripts/install.sh | 16 ---------------- alpine/matrix/systemd/30-synapse-override.conf | 2 ++ .../systemd/matrix-appservice-irc.service | 10 ---------- alpine/matrix/systemd/matrix.service | 6 +++--- alpine/matrix/systemd/riot.service | 16 ++++++++++++++++ alpine/matrix/systemd/turn.service | 13 +++++++++++++ 11 files changed, 84 insertions(+), 42 deletions(-) create mode 100644 alpine/matrix/scripts/install-matrix.sh create mode 100644 alpine/matrix/scripts/install-riot.sh create mode 100644 alpine/matrix/scripts/install-turn.sh delete mode 100644 alpine/matrix/scripts/install.sh create mode 100644 alpine/matrix/systemd/30-synapse-override.conf delete mode 100644 alpine/matrix/systemd/matrix-appservice-irc.service create mode 100644 alpine/matrix/systemd/riot.service create mode 100644 alpine/matrix/systemd/turn.service diff --git a/alpine/matrix/build.sh b/alpine/matrix/build.sh index fb8db74..1b39dff 100644 --- a/alpine/matrix/build.sh +++ b/alpine/matrix/build.sh @@ -6,8 +6,8 @@ set -e IMAGE=/tmp/$NAME.raw [ -z $ROOTFS ] && ROOTFS=$(mktemp -d $NAME.XXX -t) -[ -z $ALPINE_VERSION ] && ALPINE_VERSION=3.12 -[ -z $ALPINE_RELEASE ] && ALPINE_RELEASE=0 +[ -z $ALPINE_VERSION ] && ALPINE_VERSION=3.13 +[ -z $ALPINE_RELEASE ] && ALPINE_RELEASE=1 ALPINE_TARBALL=alpine-minirootfs-$ALPINE_VERSION.$ALPINE_RELEASE-x86_64.tar.gz @@ -16,7 +16,7 @@ ALPINE_TARBALL=alpine-minirootfs-$ALPINE_VERSION.$ALPINE_RELEASE-x86_64.tar.gz mkdir -p $ROOTFS tar xf $ALPINE_TARBALL -C $ROOTFS/ \ - ./etc/apk ./usr ./lib ./bin ./sbin ./var + ./etc ./usr ./lib ./bin ./sbin ./var chmod 755 $ROOTFS @@ -24,20 +24,20 @@ mkdir -p \ $ROOTFS/etc/systemd/system \ $ROOTFS/var/{lib,run,tmp} \ $ROOTFS/{dev,tmp,proc,root,run,sys} \ - $ROOTFS/etc/matrix \ - $ROOTFS/var/lib/matrix-synapse \ + $ROOTFS/etc/$NAME \ + $ROOTFS/var/lib/$NAME \ $ROOTFS/run/systemd/unit-root/var/tmp touch $ROOTFS/etc/machine-id $ROOTFS/etc/resolv.conf -cp systemd/matrix.service $ROOTFS/etc/systemd/system/$NAME.service +cp -a systemd/${NAME}* $ROOTFS/etc/systemd/system/ cp conf/os-release $ROOTFS/etc/os-release sudo systemd-nspawn --directory $ROOTFS/ \ - --bind $HOME/dev/python/pyopenssl:/tmp/pyopenssl \ - --bind=$PWD/scripts/install.sh:/root/install.sh \ + --bind=$PWD/scripts/install-$NAME.sh:/root/install.sh \ /bin/sh /root/install.sh -mksquashfs $ROOTFS/ $IMAGE -all-root -noappend +sudo mksquashfs $ROOTFS/ $IMAGE -all-root -noappend +sudo systemctl stop $IMAGE || true sudo portablectl detach $IMAGE || true sudo portablectl attach $IMAGE sudo systemctl restart $NAME.service diff --git a/alpine/matrix/scripts/install-matrix.sh b/alpine/matrix/scripts/install-matrix.sh new file mode 100644 index 0000000..8ecc993 --- /dev/null +++ b/alpine/matrix/scripts/install-matrix.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +apk --no-cache add --no-scripts --no-commit-hooks synapse + +find /usr -name "__pycache__" -exec rm -rf {} + +find /usr -name "*.pyc" -exec rm {} + + +apk del alpine-keys + +rm -rf /etc/apk \ + /root/.cache \ + /root/.config \ + /var/cache/* diff --git a/alpine/matrix/scripts/install-pip.sh b/alpine/matrix/scripts/install-pip.sh index 9f1819a..0c1fc4b 100644 --- a/alpine/matrix/scripts/install-pip.sh +++ b/alpine/matrix/scripts/install-pip.sh @@ -13,21 +13,20 @@ apk --no-cache add --virtual .synapse-build \ py3-pip \ zlib-dev -pip3 install --upgrade pip setuptools +pip3 install --upgrade --force pip setuptools pip3 install https://github.com/matrix-org/synapse/tarball/master apk del .synapse-build -# Runtime packages. +# Runtime packages apk --no-cache add \ libjpeg-turbo \ libmagic \ - libressl2.7-libssl \ + libressl \ python3 find /usr -name "__pycache__" -exec rm -rf {} + find /usr -name "*.pyc" -exec rm {} + -find /usr -name "*yarn*" -exec rm -rf {} + apk del alpine-keys diff --git a/alpine/matrix/scripts/install-riot.sh b/alpine/matrix/scripts/install-riot.sh new file mode 100644 index 0000000..46047b7 --- /dev/null +++ b/alpine/matrix/scripts/install-riot.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +apk --no-cache add --no-scripts --no-commit-hooks riot-web nginx + +apk del alpine-keys + +rm -rf /etc/apk \ + /root/.cache \ + /root/.config \ + /var/cache/* diff --git a/alpine/matrix/scripts/install-turn.sh b/alpine/matrix/scripts/install-turn.sh new file mode 100644 index 0000000..c121ad9 --- /dev/null +++ b/alpine/matrix/scripts/install-turn.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +apk add --no-cache --purge -uU \ + --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \ + coturn sqlite-libs + +find /usr -name "__pycache__" -exec rm -rf {} + +find /usr -name "*.pyc" -exec rm {} + + +apk del alpine-keys + +rm -rf /etc/apk \ + /root/.cache \ + /root/.config \ + /var/cache/* diff --git a/alpine/matrix/scripts/install.sh b/alpine/matrix/scripts/install.sh deleted file mode 100644 index 185fd5f..0000000 --- a/alpine/matrix/scripts/install.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -apk --no-cache add --no-scripts --no-commit-hooks --initramfs-diskless-boot synapse - -find /usr -name "__pycache__" -exec rm -rf {} + -find /usr -name "*.pyc" -exec rm {} + - -apk del alpine-keys alpine-baselayout - -rm -rf /etc/apk \ - /etc/ssl \ - /etc/terminfo \ - /etc/synapse \ - /root/.cache \ - /root/.config \ - /var/cache/* diff --git a/alpine/matrix/systemd/30-synapse-override.conf b/alpine/matrix/systemd/30-synapse-override.conf new file mode 100644 index 0000000..f1446ce --- /dev/null +++ b/alpine/matrix/systemd/30-synapse-override.conf @@ -0,0 +1,2 @@ +[Service] +MemoryDenyWriteExecute=no diff --git a/alpine/matrix/systemd/matrix-appservice-irc.service b/alpine/matrix/systemd/matrix-appservice-irc.service deleted file mode 100644 index 940e77d..0000000 --- a/alpine/matrix/systemd/matrix-appservice-irc.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Matrix IRC gateway -After=matrix.service -Requires=matrix.service - -[Service] -Type=exec -ExecStart=/usr/local/bin/matrix-appservice-irc -c /etc/matrix/irc-config.yaml -f /etc/matrix/irc-registration.yaml -p 7881 -StateDirectory=matrix-appservice-irc -ConfigurationDirectory=matrix diff --git a/alpine/matrix/systemd/matrix.service b/alpine/matrix/systemd/matrix.service index 8f2e9d7..b9158c9 100644 --- a/alpine/matrix/systemd/matrix.service +++ b/alpine/matrix/systemd/matrix.service @@ -1,6 +1,5 @@ [Unit] Description=Synapse - Matrix homeserver -After=network-online.target Requires=network-online.target [Service] @@ -10,7 +9,8 @@ Environment=PYTHONDONTWRITEBYTECODE=1 ExecStart=/usr/bin/synctl start /etc/matrix/homeserver.yaml --no-daemonize ExecStop=/usr/bin/synctl stop /etc/matrix/homeserver.yaml +ExecReload=/opt/synapse/bin/synctl restart /etc/matrix/homeserver.yaml -StateDirectory=matrix-synapse -ConfigurationDirectory=matrix +StateDirectory=matrix RuntimeDirectory=matrix +ConfigurationDirectory=matrix diff --git a/alpine/matrix/systemd/riot.service b/alpine/matrix/systemd/riot.service new file mode 100644 index 0000000..b9158c9 --- /dev/null +++ b/alpine/matrix/systemd/riot.service @@ -0,0 +1,16 @@ +[Unit] +Description=Synapse - Matrix homeserver +Requires=network-online.target + +[Service] +Environment=LANG=en_US.UTF-8 +Environment=SYNAPSE_LOG_LEVEL=DEBUG +Environment=PYTHONDONTWRITEBYTECODE=1 + +ExecStart=/usr/bin/synctl start /etc/matrix/homeserver.yaml --no-daemonize +ExecStop=/usr/bin/synctl stop /etc/matrix/homeserver.yaml +ExecReload=/opt/synapse/bin/synctl restart /etc/matrix/homeserver.yaml + +StateDirectory=matrix +RuntimeDirectory=matrix +ConfigurationDirectory=matrix diff --git a/alpine/matrix/systemd/turn.service b/alpine/matrix/systemd/turn.service new file mode 100644 index 0000000..a23b882 --- /dev/null +++ b/alpine/matrix/systemd/turn.service @@ -0,0 +1,13 @@ +[Unit] +Description=Coturn - TURN/STUN server +Requires=network-online.target + +[Service] +Environment=LANG=en_US.UTF-8 + +ExecStart=/usr/bin/turnserver -c /etc/coturn/turnserver.conf +Restart=on-failure + +StateDirectory=turn +RuntimeDirectory=turn +ConfigurationDirectory=turn