xTHExBEASTx commited on
Commit
df3ac6b
·
verified ·
1 Parent(s): ea6f21d

Upload 5 files

Browse files
Files changed (5) hide show
  1. Dockerfile +103 -0
  2. config.yml.template +76 -0
  3. custom_nginx.conf +58 -0
  4. start.sh +69 -0
  5. supervisord.conf +71 -0
Dockerfile ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-bullseye
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive
4
+ ENV LIBRETIME_VERSION=4.5.0
5
+ ENV PYTHONUNBUFFERED=1
6
+
7
+ # Install System Dependencies
8
+ RUN apt-get update && apt-get install -y --no-install-recommends \
9
+ postgresql postgresql-contrib \
10
+ rabbitmq-server \
11
+ icecast2 \
12
+ liquidsoap \
13
+ nginx \
14
+ supervisor \
15
+ sudo \
16
+ curl \
17
+ git \
18
+ lsb-release \
19
+ locales \
20
+ make \
21
+ unzip \
22
+ php-fpm php-pgsql php-curl php-gd php-mbstring php-xml php-bcmath php-intl php-zip php-opcache \
23
+ gettext libpq-dev gcc libc6-dev \
24
+ && rm -rf /var/lib/apt/lists/*
25
+
26
+ # Generate Locale
27
+ RUN echo "en_US.UTF_8 UTF-8" > /etc/locale.gen && locale-gen
28
+
29
+ # Clone LibreTime
30
+ RUN git clone --depth 1 --branch ${LIBRETIME_VERSION} https://github.com/libretime/libretime.git /usr/src/libretime
31
+
32
+ WORKDIR /usr/src/libretime
33
+
34
+ # Install Python Components
35
+ # 1. Shared
36
+ WORKDIR /usr/src/libretime/shared
37
+ RUN pip install .
38
+
39
+ # 2. API Client
40
+ WORKDIR /usr/src/libretime/api-client
41
+ RUN pip install .
42
+
43
+ # 3. API
44
+ WORKDIR /usr/src/libretime/api
45
+ RUN pip install .[prod]
46
+
47
+ # 4. Analyzer
48
+ WORKDIR /usr/src/libretime/analyzer
49
+ RUN pip install .
50
+
51
+ # 5. Playout
52
+ WORKDIR /usr/src/libretime/playout
53
+ RUN pip install .
54
+
55
+ # 6. Worker
56
+ WORKDIR /usr/src/libretime/worker
57
+ RUN pip install .
58
+
59
+ # Legacy Setup
60
+ WORKDIR /usr/src/libretime/legacy
61
+ # Install composer
62
+ RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
63
+ RUN composer install --no-dev --no-interaction
64
+ RUN make locale-build
65
+
66
+ # Move Legacy to final location
67
+ RUN mkdir -p /usr/share/libretime
68
+ RUN cp -r /usr/src/libretime/legacy /usr/share/libretime/legacy
69
+
70
+ # Config Setup
71
+ RUN mkdir -p /etc/libretime /var/log/libretime /var/lib/libretime /srv/libretime
72
+
73
+ # Nginx
74
+ RUN rm /etc/nginx/sites-enabled/default
75
+ COPY custom_nginx.conf /etc/nginx/custom_nginx.conf
76
+
77
+ # Supervisor
78
+ COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
79
+
80
+ # Start Script
81
+ COPY start.sh /start.sh
82
+ COPY config.yml.template /etc/libretime/config.yml.template
83
+ RUN chmod +x /start.sh
84
+
85
+ # User Setup
86
+ RUN useradd -m -u 1000 user
87
+ RUN chown -R user:user /var/lib/postgresql /var/lib/rabbitmq /var/log/libretime /etc/libretime /var/lib/libretime /srv/libretime /var/lib/nginx /var/log/nginx /var/log/supervisor /var/run/postgresql /var/log/icecast2
88
+
89
+ # Ensure PHP run directory exists and is writable
90
+ RUN mkdir -p /run/php && chown -R user:user /run/php
91
+
92
+ # Fix PHP FPM config to run as user
93
+ # Debian 11 uses /etc/php/7.4/fpm/pool.d/www.conf
94
+ RUN sed -i 's/www-data/user/g' /etc/php/7.4/fpm/pool.d/www.conf
95
+
96
+ # Fix Icecast config to disable changeowner
97
+ RUN sed -i 's/<changeowner>/<!--<changeowner>/g' /etc/icecast2/icecast.xml
98
+ RUN sed -i 's/}<\/changeowner>/}<\/changeowner>-->/g' /etc/icecast2/icecast.xml
99
+
100
+ EXPOSE 7860
101
+
102
+ USER user
103
+ CMD ["/start.sh"]
config.yml.template ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ general:
2
+ public_url: http://localhost:7860
3
+ api_key: changeme_api_key
4
+ secret_key: changeme_secret_key
5
+ allowed_cors_origins: []
6
+ timezone: UTC
7
+ cache_ahead_hours: 1
8
+ auth: local
9
+
10
+ storage:
11
+ path: /srv/libretime
12
+
13
+ database:
14
+ host: localhost
15
+ port: 5432
16
+ name: libretime
17
+ user: libretime
18
+ password: libretime
19
+
20
+ rabbitmq:
21
+ host: localhost
22
+ port: 5672
23
+ vhost: /libretime
24
+ user: libretime
25
+ password: libretime
26
+
27
+ email:
28
+ from_address: no-reply@localhost
29
+ host: localhost
30
+ port: 25
31
+ encryption:
32
+ user: ""
33
+ password: ""
34
+ timeout: 30
35
+
36
+ playout:
37
+ liquidsoap_host: localhost
38
+ liquidsoap_port: 1234
39
+ record_file_format: ogg
40
+ record_bitrate: 256
41
+ record_samplerate: 44100
42
+ record_channels: 2
43
+ record_sample_size: 16
44
+
45
+ liquidsoap:
46
+ server_listen_address: 0.0.0.0
47
+ server_listen_port: 1234
48
+ harbor_listen_address: ["0.0.0.0"]
49
+
50
+ stream:
51
+ inputs:
52
+ main:
53
+ mount: main
54
+ port: 8001
55
+ secure: false
56
+ show:
57
+ mount: show
58
+ port: 8002
59
+ secure: false
60
+
61
+ outputs:
62
+ icecast:
63
+ - host: localhost
64
+ port: 8000
65
+ source_password: hackme
66
+ admin_password: hackme
67
+ mount: main
68
+ public_url: http://localhost:8000/main
69
+ audio:
70
+ format: ogg
71
+ bitrate: 256
72
+ name: LibreTime!
73
+ description: LibreTime Radio!
74
+ website: https://libretime.org
75
+ genre: various
76
+ enabled: true
custom_nginx.conf ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ worker_processes 1;
2
+ daemon off;
3
+ pid /tmp/nginx.pid;
4
+ error_log /var/log/nginx/error.log warn;
5
+
6
+ events {
7
+ worker_connections 1024;
8
+ }
9
+
10
+ http {
11
+ include /etc/nginx/mime.types;
12
+ default_type application/octet-stream;
13
+ access_log /var/log/nginx/access.log;
14
+ sendfile on;
15
+ keepalive_timeout 65;
16
+
17
+ # LibreTime Server Block
18
+ server {
19
+ listen 7860;
20
+ server_name localhost;
21
+
22
+ root /usr/share/libretime/legacy/public;
23
+ index index.php index.html index.htm;
24
+
25
+ client_max_body_size 512M;
26
+ client_body_timeout 300s;
27
+
28
+ location ~ \.php$ {
29
+ fastcgi_buffers 64 4K;
30
+ fastcgi_split_path_info ^(.+\.php)(/.+)$;
31
+ try_files $fastcgi_script_name =404;
32
+ include fastcgi_params;
33
+ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
34
+ set $path_info $fastcgi_path_info;
35
+ fastcgi_param PATH_INFO $path_info;
36
+ fastcgi_pass 127.0.0.1:9000; # We will configure PHP-FPM to listen here
37
+ }
38
+
39
+ location / {
40
+ try_files $uri $uri/ /index.php$is_args$args;
41
+ }
42
+
43
+ location ~ ^/api/(v2|browser) {
44
+ proxy_set_header Host $http_host;
45
+ proxy_set_header X-Real-IP $remote_addr;
46
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
47
+ proxy_set_header X-Forwarded-Proto $scheme;
48
+ proxy_redirect off;
49
+ proxy_pass http://127.0.0.1:9001;
50
+ }
51
+
52
+ # Internal path for serving media files from the API.
53
+ location /api/_media {
54
+ internal;
55
+ alias /srv/libretime;
56
+ }
57
+ }
58
+ }
start.sh ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ PG_DATA="/var/lib/postgresql/data"
5
+ RABBIT_DATA="/var/lib/rabbitmq"
6
+
7
+ # Ensure directories exist
8
+ mkdir -p "$PG_DATA"
9
+ mkdir -p "$RABBIT_DATA"
10
+ mkdir -p /var/log/libretime /var/log/icecast2 /var/log/nginx /var/log/supervisor
11
+ mkdir -p /run/php
12
+
13
+ # 1. Config Generation
14
+ if [ ! -f /etc/libretime/config.yml ]; then
15
+ echo "Generating config.yml..."
16
+ cp /etc/libretime/config.yml.template /etc/libretime/config.yml
17
+ fi
18
+
19
+ # 2. Setup Postgres
20
+ if [ ! -s "$PG_DATA/PG_VERSION" ]; then
21
+ echo "Initializing PostgreSQL..."
22
+ /usr/lib/postgresql/13/bin/initdb -D "$PG_DATA"
23
+ echo "host all all 127.0.0.1/32 trust" >> "$PG_DATA/pg_hba.conf"
24
+ echo "host all all ::1/128 trust" >> "$PG_DATA/pg_hba.conf"
25
+
26
+ echo "Starting PG for setup..."
27
+ /usr/lib/postgresql/13/bin/pg_ctl -D "$PG_DATA" -w start
28
+
29
+ echo "Creating LibreTime DB and User..."
30
+ createdb -h localhost libretime || true
31
+ psql -h localhost -c "CREATE USER libretime WITH PASSWORD 'libretime';" || true
32
+ psql -h localhost -c "GRANT ALL PRIVILEGES ON DATABASE libretime TO libretime;" || true
33
+ psql -h localhost -c "ALTER USER libretime CREATEDB;" || true
34
+
35
+ echo "Stopping PG..."
36
+ /usr/lib/postgresql/13/bin/pg_ctl -D "$PG_DATA" stop
37
+ fi
38
+
39
+ # 3. Setup RabbitMQ (Environment var usually handles this, or default is fine)
40
+ # We assume default guest:guest or libretime:libretime via env in Dockerfile/Supervisor?
41
+ # Supervisor sets HOME=/var/lib/rabbitmq.
42
+ # We might need to enable plugins or set user.
43
+ # For simplicity, we stick to default 'guest' if localhost, but config uses 'libretime'.
44
+ # We need to create rabbitmq user if not exists.
45
+ # We'll do it in background or let it fail?
46
+ # Better: Start rabbitmq server detached, configure, stop.
47
+ echo "Configuring RabbitMQ..."
48
+ /usr/sbin/rabbitmq-server -detached
49
+ sleep 10
50
+ rabbitmqctl add_user libretime libretime || true
51
+ rabbitmqctl set_permissions -p / libretime ".*" ".*" ".*" || true
52
+ rabbitmqctl add_vhost /libretime || true
53
+ rabbitmqctl set_permissions -p /libretime libretime ".*" ".*" ".*" || true
54
+ rabbitmqctl stop
55
+
56
+ # 4. Migrations
57
+ echo "Starting PostgreSQL for migration..."
58
+ /usr/lib/postgresql/13/bin/pg_ctl -D "$PG_DATA" -w start
59
+
60
+ echo "Running LibreTime Migrations..."
61
+ export LIBRETIME_CONFIG_FILEPATH=/etc/libretime/config.yml
62
+ libretime-api collectstatic --noinput
63
+ libretime-api migrate --noinput
64
+
65
+ echo "Stopping PostgreSQL..."
66
+ /usr/lib/postgresql/13/bin/pg_ctl -D "$PG_DATA" stop
67
+
68
+ echo "Starting Supervisor..."
69
+ exec supervisord -c /etc/supervisor/conf.d/supervisord.conf
supervisord.conf ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [supervisord]
2
+ nodaemon=true
3
+ logfile=/var/log/supervisor/supervisord.log
4
+ pidfile=/var/run/supervisord.pid
5
+ user=user
6
+
7
+ [program:postgresql]
8
+ command=/usr/lib/postgresql/13/bin/postgres -D /var/lib/postgresql/data
9
+ user=user
10
+ autorestart=true
11
+ priority=1
12
+
13
+ [program:rabbitmq]
14
+ command=/usr/sbin/rabbitmq-server
15
+ user=user
16
+ environment=HOME="/var/lib/rabbitmq"
17
+ autorestart=true
18
+ priority=2
19
+
20
+ [program:icecast]
21
+ command=icecast2 -c /etc/icecast2/icecast.xml
22
+ user=user
23
+ autorestart=true
24
+ priority=3
25
+
26
+ [program:php-fpm]
27
+ command=/usr/sbin/php-fpm7.4 -F
28
+ user=user
29
+ autorestart=true
30
+ priority=4
31
+
32
+ [program:nginx]
33
+ command=nginx -c /etc/nginx/custom_nginx.conf
34
+ user=user
35
+ autorestart=true
36
+ priority=5
37
+
38
+ [program:libretime-api]
39
+ command=/usr/local/bin/gunicorn --workers=2 --worker-class=libretime_api.gunicorn.Worker --bind=0.0.0.0:9001 libretime_api.asgi
40
+ user=user
41
+ autorestart=true
42
+ environment=LIBRETIME_CONFIG_FILEPATH="/etc/libretime/config.yml"
43
+ priority=10
44
+
45
+ [program:libretime-worker]
46
+ command=/usr/local/bin/libretime-worker
47
+ user=user
48
+ autorestart=true
49
+ environment=LIBRETIME_CONFIG_FILEPATH="/etc/libretime/config.yml"
50
+ priority=11
51
+
52
+ [program:libretime-analyzer]
53
+ command=/usr/local/bin/libretime-analyzer
54
+ user=user
55
+ autorestart=true
56
+ environment=LIBRETIME_CONFIG_FILEPATH="/etc/libretime/config.yml"
57
+ priority=12
58
+
59
+ [program:libretime-playout]
60
+ command=/usr/local/bin/libretime-playout
61
+ user=user
62
+ autorestart=true
63
+ environment=LIBRETIME_CONFIG_FILEPATH="/etc/libretime/config.yml"
64
+ priority=13
65
+
66
+ [program:libretime-liquidsoap]
67
+ command=/usr/local/bin/libretime-liquidsoap
68
+ user=user
69
+ autorestart=true
70
+ environment=LIBRETIME_CONFIG_FILEPATH="/etc/libretime/config.yml"
71
+ priority=14