Skip to content

Commit 0296651

Browse files
authored
Python requirements and Docker version upgrades (mediacms-io#826)
v3.0.0: Python, Django, Celery and other version upgrades
1 parent 487e098 commit 0296651

17 files changed

+140
-60
lines changed

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.8-buster AS compile-image
1+
FROM python:3.11.4-bookworm AS compile-image
22

33
SHELL ["/bin/bash", "-c"]
44

@@ -24,7 +24,7 @@ RUN wget -q http://zebulon.bok.net/Bento4/binaries/Bento4-SDK-1-6-0-637.x86_64-u
2424
rm Bento4-SDK-1-6-0-637.x86_64-unknown-linux.zip
2525

2626
############ RUNTIME IMAGE ############
27-
FROM python:3.8-slim-buster as runtime-image
27+
FROM python:3.11.4-bookworm as runtime-image
2828

2929
ENV PYTHONUNBUFFERED=1
3030
ENV PYTHONDONTWRITEBYTECODE=1

Dockerfile-dev

+57-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mediacms/mediacms:latest
1+
FROM python:3.11.4-bookworm AS compile-image
22

33
SHELL ["/bin/bash", "-c"]
44

@@ -7,10 +7,65 @@ ENV VIRTUAL_ENV=/home/mediacms.io
77
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
88
ENV PIP_NO_CACHE_DIR=1
99

10-
RUN cd /home/mediacms.io && python3 -m venv $VIRTUAL_ENV
10+
RUN mkdir -p /home/mediacms.io/mediacms/{logs} && cd /home/mediacms.io && python3 -m venv $VIRTUAL_ENV
1111

12+
# Install dependencies:
1213
COPY requirements.txt .
1314
COPY requirements-dev.txt .
1415
RUN pip install -r requirements-dev.txt
1516

17+
18+
COPY . /home/mediacms.io/mediacms
1619
WORKDIR /home/mediacms.io/mediacms
20+
21+
RUN wget -q http://zebulon.bok.net/Bento4/binaries/Bento4-SDK-1-6-0-637.x86_64-unknown-linux.zip && \
22+
unzip Bento4-SDK-1-6-0-637.x86_64-unknown-linux.zip -d ../bento4 && \
23+
mv ../bento4/Bento4-SDK-1-6-0-637.x86_64-unknown-linux/* ../bento4/ && \
24+
rm -rf ../bento4/Bento4-SDK-1-6-0-637.x86_64-unknown-linux && \
25+
rm -rf ../bento4/docs && \
26+
rm Bento4-SDK-1-6-0-637.x86_64-unknown-linux.zip
27+
28+
############ RUNTIME IMAGE ############
29+
FROM python:3.11.4-bookworm as runtime-image
30+
31+
ENV PYTHONUNBUFFERED=1
32+
ENV PYTHONDONTWRITEBYTECODE=1
33+
34+
# See: https://github.com/celery/celery/issues/6285#issuecomment-715316219
35+
ENV CELERY_APP='cms'
36+
37+
# Use these to toggle which processes supervisord should run
38+
ENV ENABLE_UWSGI='yes'
39+
ENV ENABLE_NGINX='yes'
40+
ENV ENABLE_CELERY_BEAT='yes'
41+
ENV ENABLE_CELERY_SHORT='yes'
42+
ENV ENABLE_CELERY_LONG='yes'
43+
ENV ENABLE_MIGRATIONS='yes'
44+
45+
# Set up virtualenv
46+
ENV VIRTUAL_ENV=/home/mediacms.io
47+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
48+
49+
COPY --chown=www-data:www-data --from=compile-image /home/mediacms.io /home/mediacms.io
50+
51+
RUN apt-get update -y && apt-get -y upgrade && apt-get install --no-install-recommends \
52+
supervisor nginx imagemagick procps wget xz-utils -y && \
53+
rm -rf /var/lib/apt/lists/* && \
54+
apt-get purge --auto-remove && \
55+
apt-get clean
56+
57+
RUN wget -q https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz && \
58+
mkdir -p ffmpeg-tmp && \
59+
tar -xf ffmpeg-release-amd64-static.tar.xz --strip-components 1 -C ffmpeg-tmp && \
60+
cp -v ffmpeg-tmp/ffmpeg ffmpeg-tmp/ffprobe ffmpeg-tmp/qt-faststart /usr/local/bin && \
61+
rm -rf ffmpeg-tmp ffmpeg-release-amd64-static.tar.xz
62+
63+
WORKDIR /home/mediacms.io/mediacms
64+
65+
EXPOSE 9000 80
66+
67+
RUN chmod +x ./deploy/docker/entrypoint.sh
68+
69+
ENTRYPOINT ["./deploy/docker/entrypoint.sh"]
70+
71+
CMD ["./deploy/docker/start.sh"]

HISTORY.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# History
22

3+
## 3.0.0
4+
5+
### Features
6+
- Updates Python/Django requirements and Dockerfile to use latest 3.11 Python - https://github.com/mediacms-io/mediacms/pull/826/files. This update requires some manual steps, for existing (not new) installations. Check the update section under the [Admin docs](https://github.com/mediacms-io/mediacms/blob/main/docs/admins_docs.md#2-server-installation), either for single server or for Docker Compose installations
7+
- Upgrade postgres on Docker Compose - https://github.com/mediacms-io/mediacms/pull/749
8+
9+
### Fixes
10+
- video player options for HLS - https://github.com/mediacms-io/mediacms/pull/832
11+
- AVI videos not correctly recognised as videos - https://github.com/mediacms-io/mediacms/pull/833
12+
313
## 2.1.0
414

515
### Fixes

cms/settings.py

+2
Original file line numberDiff line numberDiff line change
@@ -485,3 +485,5 @@
485485
r'/accounts/confirm-email/.*/$',
486486
r'/api/v[0-9]+/',
487487
]
488+
489+
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

cms/urls.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import debug_toolbar
2-
from django.conf.urls import include, re_path
2+
from django.conf.urls import include
33
from django.contrib import admin
4-
from django.urls import path
4+
from django.urls import path, re_path
55
from django.views.generic.base import TemplateView
66
from drf_yasg import openapi
77
from drf_yasg.views import get_schema_view

deploy/local_install/celery_beat.service

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ User=www-data
88
Group=www-data
99
Restart=always
1010
RestartSec=10
11-
Environment=APP_DIR="/home/mediacms.io/mediacms"
11+
WorkingDirectory=/home/mediacms.io/mediacms
1212
Environment=CELERY_BIN="/home/mediacms.io/bin/celery"
13-
Environment=CELERY_APP="cms"
1413
Environment=CELERYD_PID_FILE="/home/mediacms.io/mediacms/pids/beat%n.pid"
1514
Environment=CELERYD_LOG_FILE="/home/mediacms.io/mediacms/logs/beat%N.log"
1615
Environment=CELERYD_LOG_LEVEL="INFO"
17-
Environment=APP_DIR="/home/mediacms.io/mediacms"
1816

19-
ExecStart=/bin/sh -c '${CELERY_BIN} beat -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS} --workdir=${APP_DIR}'
17+
ExecStart=/bin/sh -c '${CELERY_BIN} -A cms beat --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL}'
2018
ExecStop=/bin/kill -s TERM $MAINPID
2119

2220
[Install]

deploy/local_install/celery_long.service

+4-6
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,21 @@ User=www-data
88
Group=www-data
99
Restart=always
1010
RestartSec=10
11-
Environment=APP_DIR="/home/mediacms.io/mediacms"
11+
WorkingDirectory=/home/mediacms.io/mediacms
1212
Environment=CELERYD_NODES="long1"
1313
Environment=CELERY_QUEUE="long_tasks"
1414
Environment=CELERY_BIN="/home/mediacms.io/bin/celery"
15-
Environment=CELERY_APP="cms"
1615
Environment=CELERYD_MULTI="multi"
1716
Environment=CELERYD_OPTS="-Ofair --prefetch-multiplier=1"
1817
Environment=CELERYD_PID_FILE="/home/mediacms.io/mediacms/pids/%n.pid"
1918
Environment=CELERYD_LOG_FILE="/home/mediacms.io/mediacms/logs/%N.log"
2019
Environment=CELERYD_LOG_LEVEL="INFO"
21-
Environment=APP_DIR="/home/mediacms.io/mediacms"
2220

23-
ExecStart=/bin/sh -c '${CELERY_BIN} multi start ${CELERYD_NODES} -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS} --workdir=${APP_DIR} -Q ${CELERY_QUEUE}'
21+
ExecStart=/bin/sh -c '${CELERY_BIN} -A cms multi start ${CELERYD_NODES} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS} -Q ${CELERY_QUEUE}'
2422

25-
ExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait ${CELERYD_NODES} --pidfile=${CELERYD_PID_FILE}'
23+
ExecStop=/bin/sh -c '${CELERY_BIN} -A cms multi stopwait ${CELERYD_NODES} --pidfile=${CELERYD_PID_FILE}'
2624

27-
ExecReload=/bin/sh -c '${CELERY_BIN} multi restart ${CELERYD_NODES} -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS} --workdir=${APP_DIR} -Q ${CELERY_QUEUE}'
25+
ExecReload=/bin/sh -c '${CELERY_BIN} -A cms multi restart ${CELERYD_NODES} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS} -Q ${CELERY_QUEUE}'
2826

2927
[Install]
3028
WantedBy=multi-user.target

deploy/local_install/celery_short.service

+4-6
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ User=www-data
88
Group=www-data
99
Restart=always
1010
RestartSec=10
11-
Environment=APP_DIR="/home/mediacms.io/mediacms"
11+
WorkingDirectory=/home/mediacms.io/mediacms
1212
Environment=CELERYD_NODES="short1 short2"
1313
Environment=CELERY_QUEUE="short_tasks"
1414
# Absolute or relative path to the 'celery' command:
1515
Environment=CELERY_BIN="/home/mediacms.io/bin/celery"
1616
# App instance to use
1717
# comment out this line if you don't use an app
18-
Environment=CELERY_APP="cms"
1918
# or fully qualified:
2019
#CELERY_APP="proj.tasks:app"
2120
# How to call manage.py
@@ -28,13 +27,12 @@ Environment=CELERYD_OPTS="--soft-time-limit=300 -c10"
2827
Environment=CELERYD_PID_FILE="/home/mediacms.io/mediacms/pids/%n.pid"
2928
Environment=CELERYD_LOG_FILE="/home/mediacms.io/mediacms/logs/%N.log"
3029
Environment=CELERYD_LOG_LEVEL="INFO"
31-
Environment=APP_DIR="/home/mediacms.io/mediacms"
3230

33-
ExecStart=/bin/sh -c '${CELERY_BIN} multi start ${CELERYD_NODES} -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS} --workdir=${APP_DIR} -Q ${CELERY_QUEUE}'
31+
ExecStart=/bin/sh -c '${CELERY_BIN} -A cms multi start ${CELERYD_NODES} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS} -Q ${CELERY_QUEUE}'
3432

35-
ExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait ${CELERYD_NODES} --pidfile=${CELERYD_PID_FILE}'
33+
ExecStop=/bin/sh -c '${CELERY_BIN} -A cms multi stopwait ${CELERYD_NODES} --pidfile=${CELERYD_PID_FILE}'
3634

37-
ExecReload=/bin/sh -c '${CELERY_BIN} multi restart ${CELERYD_NODES} -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS} --workdir=${APP_DIR} -Q ${CELERY_QUEUE}'
35+
ExecReload=/bin/sh -c '${CELERY_BIN} -A cms multi restart ${CELERYD_NODES} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS} -Q ${CELERY_QUEUE}'
3836

3937
[Install]
4038
WantedBy=multi-user.target

docs/admins_docs.md

+22-4
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ This page is created for MediaCMS administrators that are responsible for settin
2525

2626
## 2. Server Installation
2727

28-
The core dependencies are Python3, Django3, Celery, PostgreSQL, Redis, ffmpeg. Any system that can have these dependencies installed, can run MediaCMS. But we strongly suggest installing on Linux Ubuntu 18 or 20 versions.
28+
The core dependencies are Python3, Django3, Celery, PostgreSQL, Redis, ffmpeg. Any system that can have these dependencies installed, can run MediaCMS. But we strongly suggest installing on Linux Ubuntu (tested on versions 20, 22).
2929

30-
Installation on a Ubuntu 18 or 20 system with git utility installed should be completed in a few minutes with the following steps.
30+
Installation on an Ubuntu system with git utility installed should be completed in a few minutes with the following steps.
3131
Make sure you run it as user root, on a clear system, since the automatic script will install and configure the following services: Celery/PostgreSQL/Redis/Nginx and will override any existing settings.
3232

33-
Automated script - tested on Ubuntu 18, Ubuntu 20, and Debian Buster
33+
Automated script - tested on Ubuntu 20, Ubuntu 22 and Debian Buster
3434

3535
```bash
3636
mkdir /home/mediacms.io && cd /home/mediacms.io/
@@ -49,10 +49,16 @@ If you've used the above way to install MediaCMS, update with the following:
4949
cd /home/mediacms.io/mediacms # enter mediacms directory
5050
source /home/mediacms.io/bin/activate # use virtualenv
5151
git pull # update code
52+
pip install -r requirements.txt -U # run pip install to update
5253
python manage.py migrate # run Django migrations
5354
sudo systemctl restart mediacms celery_long celery_short # restart services
5455
```
5556

57+
### Update from version 2 to version 3
58+
Version 3 is using Django 4 and Celery 5, and needs a recent Python 3.x version. If you are updating from an older version, make sure Python is updated first. Version 2 could run on Python 3.6, but version 3 needs Python3.8 and higher.
59+
60+
61+
5662
### Configuration
5763
Checkout the configuration section here.
5864

@@ -66,7 +72,7 @@ Database can be backed up with pg_dump and media_files on /home/mediacms.io/medi
6672
## Installation
6773
Install a recent version of [Docker](https://docs.docker.com/get-docker/), and [Docker Compose](https://docs.docker.com/compose/install/).
6874

69-
For Ubuntu 18/20 systems this is:
75+
For Ubuntu 20/22 systems this is:
7076

7177
```bash
7278
curl -fsSL https://get.docker.com -o get-docker.sh
@@ -112,6 +118,18 @@ docker-compose down
112118
docker-compose up
113119
```
114120

121+
### Update from version 2 to version 3
122+
Version 3 is using Python 3.11 and PostgreSQL 15. If you are updating from an older version, that was using PostgreSQL 13, the automatic update will not work, as you will receive the following message when the PostgreSQL container starts:
123+
124+
```
125+
db_1 | 2023-06-27 11:07:42.959 UTC [1] FATAL: database files are incompatible with server
126+
db_1 | 2023-06-27 11:07:42.959 UTC [1] DETAIL: The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 15.2.
127+
```
128+
129+
At this point there are two options: either edit the Docker Compose file and make use of the existing postgres:13 image, or otherwise you have to perform the migration from postgresql 13 to version 15. More notes on https://github.com/mediacms-io/mediacms/pull/749
130+
131+
132+
115133
## Configuration
116134
Checkout the configuration docs here.
117135

files/tasks.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
from datetime import datetime, timedelta
88

99
from celery import Task
10-
from celery.decorators import task
10+
from celery import shared_task as task
1111
from celery.exceptions import SoftTimeLimitExceeded
1212
from celery.signals import task_revoked
13-
from celery.task.control import revoke
13+
14+
# from celery.task.control import revoke
1415
from celery.utils.log import get_task_logger
1516
from django.conf import settings
1617
from django.core.cache import cache
@@ -460,10 +461,11 @@ def check_running_states():
460461
if (now - encoding.update_date).seconds > settings.RUNNING_STATE_STALE:
461462
media = encoding.media
462463
profile = encoding.profile
463-
task_id = encoding.task_id
464+
# task_id = encoding.task_id
464465
# terminate task
465-
if task_id:
466-
revoke(task_id, terminate=True)
466+
# TODO: not imported
467+
# if task_id:
468+
# revoke(task_id, terminate=True)
467469
encoding.delete()
468470
media.encode(profiles=[profile])
469471
# TODO: allign with new code + chunksize...

files/urls.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.conf import settings
2-
from django.conf.urls import include, re_path
2+
from django.conf.urls import include
33
from django.conf.urls.static import static
4-
from django.urls import path
4+
from django.urls import path, re_path
55

66
from . import management_views, views
77
from .feeds import IndexRSSFeed, SearchRSSFeed

files/views.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from datetime import datetime, timedelta
22

3-
from celery.task.control import revoke
43
from django.conf import settings
54
from django.contrib import messages
65
from django.contrib.auth.decorators import login_required
@@ -1396,5 +1395,6 @@ class TaskDetail(APIView):
13961395
permission_classes = (permissions.IsAdminUser,)
13971396

13981397
def delete(self, request, uid, format=None):
1399-
revoke(uid, terminate=True)
1398+
# This is not imported!
1399+
# revoke(uid, terminate=True)
14001400
return Response(status=status.HTTP_204_NO_CONTENT)

install.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# should be run as root and only on Ubuntu 18/20, Debian 10/11 (Buster/Bullseye) versions!
2+
# should be run as root and only on Ubuntu 20/22, Debian 10/11 (Buster/Bullseye) versions!
33
echo "Welcome to the MediacMS installation!";
44

55
if [ `id -u` -ne 0 ]
@@ -22,11 +22,11 @@ done
2222

2323

2424
osVersion=$(lsb_release -d)
25-
if [[ $osVersion == *"Ubuntu 20"* ]] || [[ $osVersion == *"Ubuntu 18"* ]] || [[ $osVersion == *"buster"* ]] || [[ $osVersion == *"bullseye"* ]]; then
25+
if [[ $osVersion == *"Ubuntu 20"* ]] || [[ $osVersion == *"Ubuntu 22"* ]] || [[ $osVersion == *"buster"* ]] || [[ $osVersion == *"bullseye"* ]]; then
2626
echo 'Performing system update and dependency installation, this will take a few minutes'
2727
apt-get update && apt-get -y upgrade && apt-get install python3-venv python3-dev virtualenv redis-server postgresql nginx git gcc vim unzip imagemagick python3-certbot-nginx certbot wget xz-utils -y
2828
else
29-
echo "This script is tested for Ubuntu 18 and 20 versions only, if you want to try MediaCMS on another system you have to perform the manual installation"
29+
echo "This script is tested for Ubuntu 20/22 versions only, if you want to try MediaCMS on another system you have to perform the manual installation"
3030
exit
3131
fi
3232

requirements.txt

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
Django==3.1.12
2-
djangorestframework==3.12.2
3-
django-allauth==0.44.0
4-
psycopg2-binary==2.8.6
5-
uwsgi==2.0.19.1
6-
django-redis==4.12.1
7-
celery==4.4.7
8-
drf-yasg==1.20.0
9-
Pillow==8.2.0
1+
Django==4.2.2
2+
djangorestframework==3.14.0
3+
django-allauth==0.54.0
4+
psycopg==3.1.9
5+
uwsgi==2.0.21
6+
django-redis==5.3.0
7+
celery==5.3.1
8+
drf-yasg==1.21.6
9+
Pillow==9.5.0
1010
django-imagekit==4.1.0
11-
markdown==3.3.6
12-
django-filter==21.1
13-
filetype==1.0.10
14-
django-mptt==0.13.4
11+
markdown==3.4.3
12+
django-filter==23.2
13+
filetype==1.2.0
14+
django-mptt==0.14.0
1515
django-crispy-forms==1.13.0
16-
requests==2.25.0
16+
requests==2.31.0
1717
django-celery-email==3.0.0
18-
m3u8==1.0.0
19-
django-ckeditor==6.2.0
20-
django-debug-toolbar==3.2.4
21-
django-login-required-middleware==0.6.1
18+
m3u8==3.5.0
19+
django-ckeditor==6.6.1
20+
django-debug-toolbar==4.1.0
21+
django-login-required-middleware==0.9.0

uploader/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
from django.conf.urls import re_path
2+
from django.urls import re_path
33

44
from . import views
55

users/urls.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from django.conf.urls import re_path
2-
from django.urls import path
1+
from django.urls import path, re_path
32

43
from . import views
54

version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "2.0.0"
1+
VERSION = "3.0.0"

0 commit comments

Comments
 (0)