Skip to content

Commit

Permalink
[DONE] Fix remote encoding and other stuff (#1056)
Browse files Browse the repository at this point in the history
* add test for video search utils

* test_index_and_delete_es

* replace USE_DISTANT_ENCODING_TRANSCODING by USE_REMOTE_ENCODING_TRANSCODING - use store_remote_encoded_video to store video data at the end of encoding - fix discipline filter - change pod/video_encode_transcript/encoding_tasks.py to call store_remote_encoded_video in rest api

* remove import dressing in encode module to use it without django

* remove unused import

* remove unused import - fix pep8 compliance

* move json calling to prevent none objeect

* fix pep8

* create rest view to importing transcript - call it from task - remove old files

* fix transcritping

* fix import transcript error

* add new configuration

* fix access token link

* fix download file in main view

* add test to remote encoding

* update docker

* add wait docker and show running container

* add env file

* split env and start container

* start container on one line

* start container on one line remove bracket

* split build and run container

* add env to up container

* add elasticsearch verion

* export elasticsearch version

* move env

* use make to try

* add setting local

* remove touch

* fix file

* fix setting local

* remove unused dot

* remove brace

* use settings_local_docker_full_test file

* add detach to docker and add setting to xapi

* add docker exec to test

* remove -p and add detach

* remove unused option for docker up

* replace healthy by wait

* add test_encode_transcode command, use form to fix download view and prevent injection

* simple test to try

* fix test for download file, add encode video

* fix pep8 and increase delay to encode

* fix unit test and improve code after review

* change test remote encode in unit test

* change command to run test, add print

* call encode to prevent thread - check if run test and pod back run on the same db

* work on local - try on GH

* Add token and specify url to call back at the end of encoding

* change ES version and fix pep8

* fix token

* add staff status for user

* Add some translations

* use covergae to run test

* add transcripting in test - change setting to do it - improve transcripting model and task

* change transcode by transcript !

* fix pep8 in test settings

---------

Co-authored-by: Aymeric Jakobowski <[email protected]>
  • Loading branch information
ptitloup and AymericJak authored Mar 1, 2024
1 parent ab939b8 commit 935faac
Show file tree
Hide file tree
Showing 31 changed files with 718 additions and 221 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/pod_encoding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Pod Encoding Full Docker
run-name: ${{ github.actor }} is testing Pod encoding 🚀

on:
push:
branches:
- main
- master
- develop
- features/**
- dependabot/**
pull_request:
branches:
- main
- master
- develop
env:
DJANGO_SUPERUSER_USERNAME: "admin"
DJANGO_SUPERUSER_PASSWORD: "passwd"
DJANGO_SUPERUSER_EMAIL: "[email protected]"
ELASTICSEARCH_TAG: "elasticsearch:7.17.18"
ELASTICSEARCH_VERION: "elasticsearch:7.17.18"
NODE_TAG: "node:19"
PYTHON_TAG: "python:3.9-buster"
REDIS_TAG: "redis:alpine3.16"
DOCKER_ENV: "full"
GECKODRIVER_VER: "v0.29.0"
FIREFOX_VER: "87.0"

jobs:
Pod-Docker-Encoding-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
- name: Create settings local file
run: |
mv pod/custom/settings_local_docker_full_test.py pod/custom/settings_local.py
- name: cat settings local
run: cat pod/custom/settings_local.py
- name: Create env file containers
run: |
touch .env.dev
echo DJANGO_SUPERUSER_USERNAME=$DJANGO_SUPERUSER_USERNAME >> .env.dev
echo DJANGO_SUPERUSER_PASSWORD=$DJANGO_SUPERUSER_PASSWORD >> .env.dev
echo DJANGO_SUPERUSER_EMAIL=$DJANGO_SUPERUSER_EMAIL >> .env.dev
echo ELASTICSEARCH_TAG=$ELASTICSEARCH_TAG >> .env.dev
echo ELASTICSEARCH_VERSION=$ELASTICSEARCH_TAG >> .env.dev
echo NODE_TAG=$NODE_TAG >> .env.dev
echo PYTHON_TAG=$PYTHON_TAG >> .env.dev
echo REDIS_TAG=$REDIS_TAG >> .env.dev
echo DOCKER_ENV=full >> .env.dev
echo GECKODRIVER_VER=v0.29.0
echo FIREFOX_VER=87.0
- name: cat env
run: cat .env.dev
- name: make Build container
run: |
sudo rm -rf ./pod/log
sudo rm -rf ./pod/static
sudo rm -rf ./pod/node_modules
docker-compose -f ./docker-compose-full-dev-with-volumes.yml -p esup-pod build --build-arg ELASTICSEARCH_VERSION=$ELASTICSEARCH_TAG --build-arg NODE_VERSION=$NODE_TAG --build-arg PYTHON_VERSION=$PYTHON_TAG --no-cache
docker-compose -f ./docker-compose-full-dev-with-volumes.yml up --detach --force-recreate --always-recreate-deps
- name: Sleep for 60 seconds to wait run server on pod back
uses: jakejarvis/wait-action@master
with:
time: '60s'
- name: show running container
run: docker ps
- run: |
echo "🍏 Docker is UP ${{ job.status }}."
docker exec pod-back-with-volumes ps auxf
- name: run test in docker
run: docker exec pod-back-with-volumes coverage run --source='.' manage.py test_encode_transcript
- name: Stop containers
if: always()
run: docker-compose -f ./docker-compose-full-dev-with-volumes.yml down
- run: echo "END"
2 changes: 1 addition & 1 deletion dockerfile-dev-with-volumes/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ SESSION_REDIS = {
MIGRATION_MODULES = {'flatpages': 'pod.db_migrations'}
# Si DOCKER_ENV = full il faut activer l'encodage et la transcription distante
# USE_DISTANT_ENCODING_TRANSCODING = True
# USE_REMOTE_ENCODING_TRANSCODING = True
# ENCODING_TRANSCODING_CELERY_BROKER_URL = "redis://redis:6379/7"
# pour avoir le maximum de log sur la console
Expand Down
2 changes: 1 addition & 1 deletion dockerfile-dev-with-volumes/pod-back/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RUN mkdir /tmp/node_modules/
COPY --from=source-build-js /tmp/pod/node_modules/ /tmp/node_modules/
# TODO remove ES version - move it into env var
RUN pip3 install --no-cache-dir -r requirements-conteneur.txt \
&& pip3 install elasticsearch==8.9.0
&& pip3 install elasticsearch==7.17.7

# ENTRYPOINT :
COPY ./dockerfile-dev-with-volumes/pod-back/my-entrypoint-back.sh /tmp/my-entrypoint-back.sh
Expand Down
2 changes: 0 additions & 2 deletions dockerfile-dev-with-volumes/pod-back/my-entrypoint-back.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,5 @@ fi
# Le serveur de développement permet de tester vos futures modifications facilement.
# N'hésitez pas à lancer le serveur de développement pour vérifier vos modifications au fur et à mesure.
# À ce niveau, vous devriez avoir le site en français et en anglais et voir l'ensemble de la page d'accueil.
celery -A pod.video_encode_transcript.importing_tasks worker -l INFO -Q importing --concurrency 1 --detach -n import_encode
celery -A pod.video_encode_transcript.importing_transcript_tasks worker -l INFO -Q importing_transcript --concurrency 1 --detach -n import_transcript
python3 manage.py runserver 0.0.0.0:8080 --insecure
sleep infinity
75 changes: 75 additions & 0 deletions pod/custom/settings_local_docker_full_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
DEBUG = True

TEST_REMOTE_ENCODE = True
TEST_SETTINGS = True

ALLOWED_HOSTS = ["*"]

ADMINS = (
('Nicolas', '[email protected]'),
)

USE_PODFILE = True
USE_NOTIFICATIONS = False
EMAIL_ON_ENCODING_COMPLETION = False
SECRET_KEY = 'A_CHANGER'

# We specify here that we're using ES version 7\n
ES_VERSION = 7
ES_URL = ['http://elasticsearch:9200/']
CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'redis://redis:6379/3',
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
},
'KEY_PREFIX': 'pod'
},
'select2': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'redis://redis:6379/2',
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
},
},
}
SESSION_ENGINE = 'redis_sessions.session'
SESSION_REDIS = {
'host': 'redis',
'port': 6379,
'db': 4,
'prefix': 'session',
'socket_timeout': 1,
'retry_on_timeout': False,
}

# Only in containerized environments
MIGRATION_MODULES = {'flatpages': 'pod.db_migrations'}

# If DOCKER_ENV = full: activate encoding, transcription and remote xapi
USE_REMOTE_ENCODING_TRANSCODING = True
ENCODING_TRANSCODING_CELERY_BROKER_URL = 'redis://redis:6379/7'
POD_API_URL = "http://pod-back:8080/rest"
POD_API_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

USE_TRANSCRIPTION = True
TRANSCRIPTION_TYPE = "WHISPER"
TRANSCRIPTION_MODEL_PARAM = {
'WHISPER': {
'fr': {
'model': "small",
'download_root': "/usr/src/app/transcription/whisper/",
},
'en': {
'model': "small",
'download_root': "/usr/src/app/transcription/whisper/",
}
}
}

USE_XAPI_VIDEO = False
XAPI_CELERY_BROKER_URL = "redis://redis:6379/6"

# for maximum console logging\n
LOGGING = {}
18 changes: 1 addition & 17 deletions pod/dressing/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,13 @@
from unittest.mock import patch
from django.contrib.auth.models import User
from pod.authentication.models import AccessGroup
from pod.dressing.utils import get_dressings, get_position_value, get_dressing_input
from pod.dressing.utils import get_dressings, get_dressing_input
from pod.dressing.models import Dressing


class DressingUtilitiesTests(unittest.TestCase):
"""TestCase for Esup-Pod dressing utilities."""

def test_get_position_value(self):
"""Test for the get_position_value function."""
result = get_position_value("top_right", "720")
self.assertEqual(result, "overlay=main_w-overlay_w-36.0:36.0")

result = get_position_value("top_left", "720")
self.assertEqual(result, "overlay=36.0:36.0")

result = get_position_value("bottom_right", "720")
self.assertEqual(result, "overlay=main_w-overlay_w-36.0:main_h-overlay_h-36.0")

result = get_position_value("bottom_left", "720")
self.assertEqual(result, "overlay=36.0:main_h-overlay_h-36.0")

print(" ---> test_get_position_value: OK! --- DressingUtilsTest")

def test_get_dressing_input(self):
"""Test for the get_dressing_input function."""
dressing = Dressing(watermark=None, opening_credits=None, ending_credits=None)
Expand Down
22 changes: 0 additions & 22 deletions pod/dressing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,6 @@
from django.db.models import Q


def get_position_value(position: str, height: str) -> str:
"""
Obtain dimensions proportional to the video format.
Args:
position (str): proprerty "position" of the dressing object.
height (str): height of the source video.
Returns:
str: params for the ffmpeg command.
"""
height = str(float(height) * 0.05)
if position == "top_right":
return "overlay=main_w-overlay_w-" + height + ":" + height
elif position == "top_left":
return "overlay=" + height + ":" + height
elif position == "bottom_right":
return "overlay=main_w-overlay_w-" + height + ":main_h-overlay_h-" + height
elif position == "bottom_left":
return "overlay=" + height + ":main_h-overlay_h-" + height


def get_dressing_input(dressing: Dressing, FFMPEG_DRESSING_INPUT: str) -> str:
"""
Obtain the files necessary for encoding a dressed video.
Expand Down
36 changes: 33 additions & 3 deletions pod/main/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -3042,7 +3042,7 @@
"pod_version_end": "",
"pod_version_init": "3.1.0"
},
"USE_DISTANT_ENCODING_TRANSCODING": {
"USE_REMOTE_ENCODING_TRANSCODING": {
"default_value": false,
"description": {
"en": [
Expand All @@ -3054,7 +3054,37 @@
]
},
"pod_version_end": "",
"pod_version_init": "3.4.0"
"pod_version_init": "3.5.1"
},
"POD_API_URL": {
"default_value": "",
"description": {
"en": [
"Address of API rest to be called at the end of remote encoding or remote transcription.",
"Example : https://pod.univ.fr/rest/"
],
"fr": [
"Adresse de l'API rest a appeler en fin d'encodage distant ou de transcription à distance.",
"Exemple : https://pod.univ.fr/rest/"
]
},
"pod_version_end": "",
"pod_version_init": "3.5.1"
},
"POD_API_TOKEN": {
"default_value": "",
"description": {
"en": [
"Authentication token used for the call at the end of remote encoding or remote transcription.",
"To create it, go to Admin > Authentication token > token."
],
"fr": [
"Token d'authentification utilisé pour l'appel en fin d'encodage distant ou de transcription à distance.",
"Pour le créer, il faut aller dans la partie Admin > Jeton d'authentification > token."
]
},
"pod_version_end": "",
"pod_version_init": "3.5.1"
},
"VIDEO_RENDITIONS": {
"default_value": "[]",
Expand Down Expand Up @@ -5065,7 +5095,7 @@
"Mise en place du mode PWA grâce à l'application Django-pwa",
"Voici la configuration par défaut pour Pod, vous pouvez surcharger chaque variable dans votre fichier de configuration.",
"PWA_APP_NAME = \"Pod\"",
"PWA_APP_DESCRIPTION = _(",
"PWA_APP_DESCRIPTION = (",
" \"Pod is aimed at users of our institutions, by allowing the publication of \"",
" \"videos in the fields of research (promotion of platforms, etc.), training \"",
" \"(tutorials, distance training, student reports, etc.), institutional life (video \"",
Expand Down
15 changes: 15 additions & 0 deletions pod/main/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@
)


class DownloadFileForm(forms.Form):
"""Manage "Download File" form."""
filename = forms.FilePathField(
required=True,
path=settings.MEDIA_ROOT,
recursive=True,
allow_files=True,
allow_folders=False
)

def __init__(self, *args, **kwargs):
"""Init download file form."""
super(DownloadFileForm, self).__init__(*args, **kwargs)


class ContactUsForm(forms.Form):
"""Manage "Contact us" form."""

Expand Down
7 changes: 6 additions & 1 deletion pod/main/rest_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
urlpatterns = [
url(r"dublincore/$", video_views.DublinCoreView.as_view(), name="dublincore"),
url(
r"launch_encode_view/$",
r"^launch_encode_view/$",
encode_views.launch_encode_view,
name="launch_encode_view",
),
Expand All @@ -84,6 +84,11 @@
encode_views.store_remote_encoded_video,
name="store_remote_encoded_video",
),
url(
r"store_remote_transcripted_video/$",
encode_views.store_remote_transcripted_video,
name="store_remote_transcripted_video",
),
url(
r"accessgroups_set_users_by_name/$",
auth_views.accessgroups_set_users_by_name,
Expand Down
3 changes: 1 addition & 2 deletions pod/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""

import os
from django.utils.translation import gettext_lazy as _

##
# flatpages
Expand Down Expand Up @@ -312,7 +311,7 @@
# PWA

PWA_APP_NAME = "Pod"
PWA_APP_DESCRIPTION = _(
PWA_APP_DESCRIPTION = (
"Pod is aimed at users of our institutions, by allowing the publication of "
"videos in the fields of research (promotion of platforms, etc.), training "
"(tutorials, distance training, student reports, etc.), institutional life (video "
Expand Down
Binary file not shown.
4 changes: 4 additions & 0 deletions pod/main/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
)
USE_DOCKER = True
path = "pod/custom/settings_local.py"
ES_URL = ["http://127.0.0.1:9200/"]
ES_VERSION = 6
if os.path.exists(path):
_temp = __import__("pod.custom", globals(), locals(), ["settings_local"])
USE_DOCKER = getattr(_temp.settings_local, "USE_DOCKER", True)
ES_URL = getattr(_temp.settings_local, "ES_URL", ["http://127.0.0.1:9200/"])
ES_VERSION = getattr(_temp.settings_local, "ES_VERSION", 6)

for application in INSTALLED_APPS:
if application.startswith("pod"):
Expand Down
Loading

0 comments on commit 935faac

Please sign in to comment.