Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create Dockerfile and necessary files for jitsi flist #296

Merged
merged 5 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tfgrid3/jitsi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
archive
34 changes: 34 additions & 0 deletions tfgrid3/jitsi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM ubuntu:22.04

Check failure

Code scanning / Trivy

Image user should not be 'root' High

Artifact: tfgrid3/jitsi/Dockerfile
Type: dockerfile
Vulnerability DS002
Severity: HIGH
Message: Specify at least 1 USER command in Dockerfile with non-root user as argument
Link: DS002

ENV DEBIAN_FRONTEND=noninteractive

RUN apt update && \
apt -y install wget openssh-server

RUN wget -O /sbin/zinit https://github.com/threefoldtech/zinit/releases/download/v0.2.5/zinit && \
chmod +x /sbin/zinit

RUN apt upgrade -y

COPY zinit /etc/zinit
COPY start.sh /start.sh

RUN chmod +x /sbin/zinit && chmod +x /start.sh

COPY scripts /root/scripts
COPY config /root/config

RUN chmod +x /root/scripts/*.sh

RUN apt install -y curl gnupg2 nginx-full apt-transport-https \
software-properties-common openjdk-11-jdk ufw && \
apt-add-repository universe -y

RUN curl -sL https://prosody.im/files/prosody-debian-packages.key -o /etc/apt/keyrings/prosody-debian-packages.key && \
echo "deb [signed-by=/etc/apt/keyrings/prosody-debian-packages.key] http://packages.prosody.im/debian $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/prosody-debian-packages.list && \
curl -sL https://download.jitsi.org/jitsi-key.gpg.key | gpg --dearmor -o /usr/share/keyrings/jitsi-keyring.gpg && \
echo "deb [signed-by=/usr/share/keyrings/jitsi-keyring.gpg] https://download.jitsi.org stable/" | tee /etc/apt/sources.list.d/jitsi-stable.list && \
apt update && \
apt install -y lua5.2

ENTRYPOINT ["zinit", "init"]
57 changes: 57 additions & 0 deletions tfgrid3/jitsi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Jitsi TF Image

The image contains:

- prosody xmpp server -- a communication server
- jicofo(used by Jitsi) -- conference orchestrator
- jitsi-videobridge(jvb) -- WebRTC compatible video router

Exposed ports:

- 80
- 443
- 10000
- 22
- 3478
- 5349

# Usage

If you want to build the image from scratch, follow the steps below:

1- Clone the repository and navigate to the jitsi directory

```bash
git clone git git@github.com:threefoldtech/tf-images.git
cd tfgrid3/jitsi
```

2- Edit it however you please

3- Build the image

```bash
docker build -t jitsi .
```

The following is just one way to convert the image to an flist, you can use any other method you prefer.

4- Push the image to docker hub

```bash
docker tag jitsi {dockerhub-username}/jitsi
```

5- Convert it to an flist using the convertor in [Zero-OS Hub](https://hub.grid.tf/docker-convert)

6- Deploy the container on the grid using the flist URL you got from the previous step

# Environment Variables

- `SSH_KEY` -- the ssh key to be used to access the container
- `JITSI_HOSTNAME` -- this is the domain name that will be used to access the jitsi server(fqdn)

---

- Current Docker Hub image: [eyadhussein/jitsi](https://hub.docker.com/repository/docker/eyadhussein/jitsi)
- Current flist: [jitsi flist](https://hub.grid.tf/eyadhussein.3bot/eyadhussein-jitsi-latest.flist.md)
204 changes: 204 additions & 0 deletions tfgrid3/jitsi/config/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
server_names_hash_bucket_size 64;

types {
# nginx's default mime.types doesn't include a mapping for wasm or wav.
application/wasm wasm;
audio/wav wav;
}
upstream prosody {
zone upstreams 64K;
server 127.0.0.1:5280;
keepalive 2;
}
upstream jvb1 {
zone upstreams 64K;
server 127.0.0.1:9090;
keepalive 2;
}
map $arg_vnode $prosody_node {
default prosody;
v1 v1;
v2 v2;
v3 v3;
v4 v4;
v5 v5;
v6 v6;
v7 v7;
v8 v8;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
listen 80;
listen [::]:80;
server_name {JITSI_HOSTNAME};

# Mozilla Guideline v5.4, nginx 1.17.7, OpenSSL 1.1.1d, intermediate configuration
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;

ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m; # about 40000 sessions
ssl_session_tickets off;

add_header Strict-Transport-Security "max-age=63072000" always;
set $prefix "";
set $custom_index "";
set $config_js_location /etc/jitsi/meet/{JITSI_HOSTNAME}-config.js;

ssl_certificate /etc/jitsi/meet/{JITSI_HOSTNAME}.crt;
ssl_certificate_key /etc/jitsi/meet/{JITSI_HOSTNAME}.key;

root /usr/share/jitsi-meet;

# ssi on with javascript for multidomain variables in config.js
ssi on;
ssi_types application/x-javascript application/javascript;

index index.html index.htm;
error_page 404 /static/404.html;

gzip on;
gzip_types text/plain text/css application/javascript application/json image/x-icon application/octet-stream application/wasm;
gzip_vary on;
gzip_proxied no-cache no-store private expired auth;
gzip_min_length 512;

include /etc/jitsi/meet/jaas/*.conf;

location = /config.js {
alias $config_js_location;
}

location = /external_api.js {
alias /usr/share/jitsi-meet/libs/external_api.min.js;
}

location = /_api/room-info {
proxy_pass http://prosody/room-info?prefix=$prefix&$args;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
}

location ~ ^/_api/public/(.*)$ {
autoindex off;
alias /etc/jitsi/meet/public/$1;
}

# ensure all static content can always be found first
location ~ ^/(libs|css|static|images|fonts|lang|sounds|.well-known)/(.*)$
{
add_header 'Access-Control-Allow-Origin' '*';
alias /usr/share/jitsi-meet/$1/$2;

# cache all versioned files
if ($arg_v) {
expires 1y;
}
}

# BOSH
location = /http-bind {
proxy_pass http://$prosody_node/http-bind?prefix=$prefix&$args;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header Connection "";
}

# xmpp websockets
location = /xmpp-websocket {
proxy_pass http://$prosody_node/xmpp-websocket?prefix=$prefix&$args;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
tcp_nodelay on;
}

# colibri (JVB) websockets for jvb1
location ~ ^/colibri-ws/default-id/(.*) {
proxy_pass http://jvb1/colibri-ws/default-id/$1$is_args$args;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
tcp_nodelay on;
}

# load test minimal client, uncomment when used
#location ~ ^/_load-test/([^/?&:'"]+)$ {
# rewrite ^/_load-test/(.*)$ /load-test/index.html break;
#}
#location ~ ^/_load-test/libs/(.*)$ {
# add_header 'Access-Control-Allow-Origin' '*';
# alias /usr/share/jitsi-meet/load-test/libs/$1;
#}

location ~ ^/conference-request/v1(\/.*)?$ {
proxy_pass http://127.0.0.1:8888/conference-request/v1$1;
add_header "Cache-Control" "no-cache, no-store";
add_header 'Access-Control-Allow-Origin' '*';
}
location ~ ^/([^/?&:'"]+)/conference-request/v1(\/.*)?$ {
rewrite ^/([^/?&:'"]+)/conference-request/v1(\/.*)?$ /conference-request/v1$2;
}

location ~ ^/([^/?&:'"]+)$ {
set $roomname "$1";
try_files $uri @root_path;
}

location @root_path {
rewrite ^/(.*)$ /$custom_index break;
}

location ~ ^/([^/?&:'"]+)/config.js$
{
set $subdomain "$1.";
set $subdir "$1/";

alias $config_js_location;
}

# Matches /(TENANT)/pwa-worker.js or /(TENANT)/manifest.json to rewrite to / and look for file
location ~ ^/([^/?&:'"]+)/(pwa-worker.js|manifest.json)$ {
set $subdomain "$1.";
set $subdir "$1/";
rewrite ^/([^/?&:'"]+)/(pwa-worker.js|manifest.json)$ /$2;
}

# BOSH for subdomains
location ~ ^/([^/?&:'"]+)/http-bind {
set $subdomain "$1.";
set $subdir "$1/";
set $prefix "$1";

rewrite ^/(.*)$ /http-bind;
}

# websockets for subdomains
location ~ ^/([^/?&:'"]+)/xmpp-websocket {
set $subdomain "$1.";
set $subdir "$1/";
set $prefix "$1";

rewrite ^/(.*)$ /xmpp-websocket;
}

location ~ ^/([^/?&:'"]+)/_api/room-info {
set $subdomain "$1.";
set $subdir "$1/";
set $prefix "$1";

rewrite ^/(.*)$ /_api/room-info;
}

# Anything that didn't match above, and isn't a real file, assume it's a room name and redirect to /
location ~ ^/([^/?&:'"]+)/(.*)$ {
set $subdomain "$1.";
set $subdir "$1/";
rewrite ^/([^/?&:'"]+)/(.*)$ /$2;
}
}
6 changes: 6 additions & 0 deletions tfgrid3/jitsi/scripts/install_jitsi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

echo "jitsi-videobridge2 jitsi-videobridge/jvb-hostname string $(hostname)" | debconf-set-selections
echo "jitsi-meet jitsi-meet/cert-choice select Generate a new self-signed certificate" | debconf-set-selections

apt install jitsi-meet -y
18 changes: 18 additions & 0 deletions tfgrid3/jitsi/scripts/jicofo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

. /lib/lsb/init-functions
. /etc/jitsi/jicofo/config

set -e

echo -n "Starting jicofo: "
export JICOFO_AUTH_PASSWORD JICOFO_MAX_MEMORY

SCRIPT_DIR="$(dirname "$(readlink -f /usr/share/jicofo/jicofo.sh)")"
mainClass="org.jitsi.jicofo.Main"
cp=$(JARS=($SCRIPT_DIR/jicofo*.jar $SCRIPT_DIR/lib/*.jar); IFS=:; echo "${JARS[*]}")

if [ -z "$JICOFO_MAX_MEMORY" ]; then JICOFO_MAX_MEMORY=3072m; fi

cd /usr/share/jicofo/
exec java -Xmx$JICOFO_MAX_MEMORY -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -Djdk.tls.ephemeralDHKeySize=2048 $JAVA_SYS_PROPS -cp $cp $mainClass "$@"
14 changes: 14 additions & 0 deletions tfgrid3/jitsi/scripts/jvb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

. /etc/jitsi/videobridge/config

echo -n "Starting jvb: "

SCRIPT_DIR="$(dirname "$(readlink -f /usr/share/jitsi-videobridge/jvb.sh)")"
mainClass="org.jitsi.videobridge.MainKt"
cp=$SCRIPT_DIR/jitsi-videobridge.jar:$SCRIPT_DIR/lib/*

if [ -z "$VIDEOBRIDGE_MAX_MEMORY" ]; then VIDEOBRIDGE_MAX_MEMORY=3072m; fi
if [ -z "$VIDEOBRIDGE_GC_TYPE" ]; then VIDEOBRIDGE_GC_TYPE=G1GC; fi

exec java -Xmx$VIDEOBRIDGE_MAX_MEMORY $VIDEOBRIDGE_DEBUG_OPTIONS -XX:+Use$VIDEOBRIDGE_GC_TYPE -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -Djdk.tls.ephemeralDHKeySize=2048 -Djdk.net.usePlainDatagramSocketImpl=true $JAVA_SYS_PROPS -cp $cp $mainClass "$@"
5 changes: 5 additions & 0 deletions tfgrid3/jitsi/scripts/nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

sed -i "s/{JITSI_HOSTNAME}/$JITSI_HOSTNAME/g" /root/config/nginx.conf
cp /root/config/nginx.conf "/etc/nginx/sites-enabled/${JITSI_HOSTNAME}.conf"
/usr/sbin/nginx
17 changes: 17 additions & 0 deletions tfgrid3/jitsi/scripts/prosody.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e

USER=prosody
PIDFILE=/run/prosody/prosody.pid

mkdir -p "$(dirname "$PIDFILE")"
chown "$USER:adm" "$(dirname "$PIDFILE")"

echo "Starting Prosody XMPP Server as user $USER..."
if su -s /bin/bash -c /usr/bin/prosody "$USER"; then
echo "Prosody started successfully."
else
echo "Failed to start Prosody."
exit 1
fi
6 changes: 6 additions & 0 deletions tfgrid3/jitsi/scripts/setup_hostname.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

echo "$JITSI_HOSTNAME" > /etc/hostname
PUBLIC_IP=$(curl -s ifconfig.me)
echo "$PUBLIC_IP $JITSI_HOSTNAME" >> /etc/hosts
hostname "$JITSI_HOSTNAME"
9 changes: 9 additions & 0 deletions tfgrid3/jitsi/scripts/ufw.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 10000/udp
ufw allow 22/tcp
ufw allow 3478/udp
ufw allow 5349/tcp
echo y | ufw enable
8 changes: 8 additions & 0 deletions tfgrid3/jitsi/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

mkdir -p /var/run/sshd
mkdir -p /root/.ssh
touch /root/.ssh/authorized_keys

chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys
Loading
Loading