Skip to content
Open
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pod/main/static/custom/img
!pod/custom/settings_local.py.example
settings_local.py
transcription/*
.*initialized

# Unit test utilities #
#######################
Expand Down
11 changes: 5 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ upgrade:

# Création des données initiales dans la BDD SQLite intégrée
createDB:
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
find . -path "*/migrations/*.pyc" -delete
find . -path "*/migrations/*.py" -not -name "__init__.py" -exec rm --force "{}" +
find . -path "*/migrations/*.pyc" -exec rm --force "{}" +
make updatedb
make migrate
python3 manage.py loaddata initial_data

# Mise à jour des fichiers de langue
lang:
Expand Down Expand Up @@ -78,7 +77,7 @@ pystyle:
statics:
cd pod; yarn install; yarn upgrade
# --clear Clear the existing files before trying to copy or link the original file.
python3 manage.py collectstatic --clear
python3 manage.py collectstatic --clear --verbosity 0

# Generate configuration docs in .MD format
createconfigs:
Expand Down Expand Up @@ -171,6 +170,6 @@ endif
sudo rm -rf ./pod/static
sudo rm -rf ./pod/node_modules
sudo rm -rf ./pod/db_migrations
sudo rm -rf ./pod/db.sqlite3
sudo rm -rf ./pod/db_remote.sqlite3
sudo rm -rf ./pod/*.sqlite3
sudo rm -rf ./pod/.*initialized
sudo rm -rf ./pod/media
1 change: 1 addition & 0 deletions docker-compose-dev-with-volumes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ services:
ports:
- 9200:9200
environment:
- logger.level=WARN
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms2g -Xmx2g"
Expand Down
1 change: 1 addition & 0 deletions docker-compose-full-dev-with-volumes-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ services:
ports:
- 9200:9200
environment:
- logger.level=WARN
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms2g -Xmx2g"
Expand Down
1 change: 1 addition & 0 deletions docker-compose-full-dev-with-volumes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ services:
ports:
- 9200:9200
environment:
- logger.level=WARN
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms2g -Xmx2g"
Expand Down
11 changes: 8 additions & 3 deletions dockerfile-dev-with-volumes/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ DOCKER_ENV=light
Renseignez le fichier pod/custom/settings_local.py comme ceci :
[source,python]
----
import os
INSTANCE = os.getenv("POD_INSTANCE", "pod")

USE_PODFILE = True
EMAIL_ON_ENCODING_COMPLETION = False
Expand All @@ -69,6 +71,7 @@ DEBUG = True
# on précise ici qu'on utilise ES version 8
ES_VERSION = 8
ES_URL = ['http://elasticsearch.localhost:9200/']
ES_INDEX = INSTANCE


CACHES = {
Expand All @@ -78,22 +81,23 @@ CACHES = {
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
"KEY_PREFIX": "pod"
"KEY_PREFIX": INSTANCE
},
"select2": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://redis.localhost:6379/2",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
"KEY_PREFIX": INSTANCE
},
}
SESSION_ENGINE = "redis_sessions.session"
SESSION_REDIS = {
"host": "redis.localhost",
"port": 6379,
"db": 4,
"prefix": "session",
"prefix": f"session-{INSTANCE}",
"socket_timeout": 1,
"retry_on_timeout": False,
}
Expand Down Expand Up @@ -148,7 +152,8 @@ Vous devriez obtenir ce message une fois esup-pod lancé
----
$ pod-dev-with-volumes | Superuser created successfully.
----
L'application esup-pod est dès lors disponible via cette URL : localhost:8000
L'application esup-pod est dès lors disponible via cette URL : pod.localhost:8000
Différentes instances peuvent être lancées, sur différents ports, en utilisant les variables d'environnement ``POD_INSTANCE`` et ``POD_PORT``.

=== Arrêt de la stack
$ CTRL+C dans la fenetre depuis laquelle l'application esup-pod a été lancée
Expand Down
19 changes: 11 additions & 8 deletions dockerfile-dev-with-volumes/pod-back/my-entrypoint-back.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
#!/bin/sh
echo "Launching commands into pod-dev"
INSTANCE="${POD_INSTANCE:-pod}"
PORT="${POD_PORT:-8000}"
echo "Launching commands into ${INSTANCE}-dev"
mkdir -p pod/node_modules
mkdir -p pod/db_migrations && touch pod/db_migrations/__init__.py
ln -fs /tmp/node_modules/* pod/node_modules
# Mise en route
# Base de données SQLite intégrée
BDD_FILE=/usr/src/app/pod/db.sqlite3
if test ! -f "$BDD_FILE"; then
echo "$BDD_FILE does not exist."
INIT_FILE="/usr/src/app/pod/.${INSTANCE}.initialized"
if test ! -f "$INIT_FILE"; then
echo "$INIT_FILE does not exist."
python3 manage.py create_pod_index
curl -XGET "elasticsearch:9200/pod/_search"
curl -XGET "elasticsearch.localhost:9200/${INSTANCE}/_search"
# Deployez les fichiers statiques
python3 manage.py collectstatic --no-input --clear
python3 manage.py collectstatic --no-input --clear --verbosity 0
# Lancez le script présent à la racine afin de créer les fichiers de migration, puis de les lancer pour créer la base de données SQLite intégrée.
make createDB
# SuperUtilisateur
# Il faut créer un premier utilisateur qui aura tous les pouvoirs sur votre instance.
python3 manage.py createsuperuser --noinput
touch "$INIT_FILE"
else
echo "$BDD_FILE exist."
echo "$INIT_FILE exist."
fi
# Serveur de développement
# 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.
python3 manage.py runserver 0.0.0.0:8000 --insecure
python3 manage.py runserver "0.0.0.0:${PORT}" --insecure
sleep infinity
19 changes: 11 additions & 8 deletions dockerfile-dev-with-volumes/pod/my-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
#!/bin/sh
echo "Launching commands into pod-dev"
INSTANCE="${POD_INSTANCE:-pod}"
PORT="${POD_PORT:-8000}"
echo "Launching commands into ${INSTANCE}-dev"
mkdir -p pod/node_modules
mkdir -p pod/db_migrations && touch pod/db_migrations/__init__.py
ln -fs /tmp/node_modules/* pod/node_modules
# Mise en route
# Base de données SQLite intégrée
BDD_FILE=/usr/src/app/pod/db.sqlite3
if test ! -f "$BDD_FILE"; then
echo "$BDD_FILE does not exist."
INIT_FILE="/usr/src/app/pod/.${INSTANCE}.initialized"
if test ! -f "$INIT_FILE"; then
echo "$INIT_FILE does not exist."
python3 manage.py create_pod_index
curl -XGET "elasticsearch.localhost:9200/pod/_search"
curl -XGET "elasticsearch.localhost:9200/${INSTANCE}/_search"
# Deployez les fichiers statiques
python3 manage.py collectstatic --no-input --clear
python3 manage.py collectstatic --no-input --clear --verbosity 0
# Lancez le script présent à la racine afin de créer les fichiers de migration, puis de les lancer pour créer la base de données SQLite intégrée.
make createDB
# SuperUtilisateur
# Il faut créer un premier utilisateur qui aura tous les pouvoirs sur votre instance.
python3 manage.py createsuperuser --noinput
touch "$INIT_FILE"
else
echo "$BDD_FILE exist."
echo "$INIT_FILE exist."
fi
# Serveur de développement
# 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.
python3 manage.py runserver 0.0.0.0:8000 --insecure
python3 manage.py runserver "0.0.0.0:${PORT}" --insecure
sleep infinity
9 changes: 9 additions & 0 deletions pod/dressing/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import unittest
from unittest.mock import patch
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.conf import settings
from pod.authentication.models import AccessGroup
from pod.dressing.utils import get_dressings, get_dressing_input
from pod.dressing.models import Dressing
Expand All @@ -12,6 +14,13 @@
class DressingUtilitiesTests(unittest.TestCase):
"""TestCase for Esup-Pod dressing utilities."""

def setUp(self):
"""Set up test data."""
Site.objects.get_or_create(
id=getattr(settings, 'SITE_ID', 1),
defaults={'domain': 'localhost:8000', 'name': 'localhost:8000'}
)

def test_get_dressing_input(self) -> None:
"""Test for the get_dressing_input function."""
dressing = Dressing(watermark=None, opening_credits=None, ending_credits=None)
Expand Down
24 changes: 24 additions & 0 deletions pod/main/apps.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonjour,
Merci pour ces travaux.
J'ai quand même un questionnement vis-à-vis de la nouvelle fonction load-data dans pod/main/apps.py.
Je n'ai pas testé, mais de ce que j'en comprends, les données initiales ne sont plus sauvegardées dans la base de données lors du createDB mais à chaque fois que Django démarre.
Typiquement, j'ai l'impression que l'adresse du site, dans la table django_site, sera mise à jour à chaque fois.
Dans mon cas - j'imagine que je ne suis pas le seul - je n'ai qu'un site, et j'ai donc la ligne : 1 / video.umontpellier.fr / video.umontpellier.fr

Avec cette modification, au démarrage, cela va changer cette adresse par : 1 / pod.localhost:8000 / pod.localhost:8000 ?
J'ai raté quelque chose ?

Merci

Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
"""Esup-pod Main applications."""

import os

from django.apps import AppConfig
from django.db.models.signals import post_migrate
from django.utils.translation import gettext_lazy as _
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.core.management import call_command

import json

SITE_ID = getattr(settings, "SITE_ID", 1)
INSTANCE = os.getenv("POD_INSTANCE", "pod")
PORT = os.getenv("POD_PORT", 8000)


def load_data(sender, **kwargs):
"""Load the initial_data fixture and create a Site object if needed."""
from django.contrib.sites.models import Site

call_command("loaddata", "initial_data.json")

site, created = Site.objects.get_or_create(id=SITE_ID)
if created:
domain = f"{INSTANCE}.localhost:{PORT}"
site.domain = domain
site.name = domain
site.save()


def create_missing_pages(sender, **kwargs) -> None:
"""Create missing flat pages from json fixtures."""
Expand Down Expand Up @@ -72,6 +94,7 @@ def create_missing_conf(sender, **kwargs) -> None:

print("---> Creating missing configurations...")
json_data = []

with open("./pod/main/fixtures/initial_data.json", encoding="utf-8") as data_file:
json_data = json.loads(data_file.read())

Expand Down Expand Up @@ -157,3 +180,4 @@ def ready(self):
post_migrate.connect(create_missing_conf, sender=self)
post_migrate.connect(create_missing_pages, sender=self)
post_migrate.connect(create_first_block, sender=self)
post_migrate.connect(load_data, sender=self)
9 changes: 9 additions & 0 deletions pod/main/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
# set the default Django settings module for the 'celery' program.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pod.settings")

try:
from pod.custom import settings_local
except ImportError:
from pod import settings as settings_local

INSTANCE = getattr(settings_local, "INSTANCE", None)

app = Celery("pod_project")

# Using a string here means the worker doesn't have to serialize
Expand All @@ -20,6 +27,8 @@
"pod.main.tasks.*": {"queue": "celery"},
"pod.main.celery.*": {"queue": "celery"},
}
if INSTANCE:
app.conf.broker_transport_options = {"global_keyprefix": INSTANCE}


@app.task(bind=True)
Expand Down
8 changes: 0 additions & 8 deletions pod/main/fixtures/initial_data.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
[
{
"model": "sites.site",
"pk": 1,
"fields": {
"domain": "pod.localhost:8000",
"name": "pod.localhost:8000"
}
},
{
"pk": 1,
"model": "main.configuration",
Expand Down
6 changes: 5 additions & 1 deletion pod/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import os
INSTANCE = os.getenv("POD_INSTANCE", None)

##
# flatpages
Expand Down Expand Up @@ -49,6 +50,8 @@
#
# https://docs.djangoproject.com/en/3.2/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ["pod.localhost"]
if INSTANCE:
ALLOWED_HOSTS.append(f"{INSTANCE}.localhost")

##
# Session settings
Expand Down Expand Up @@ -80,10 +83,11 @@
# to be used with Django.
#
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
default_db = f"db.{INSTANCE}.sqlite3" if INSTANCE else "db.sqlite3"
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
"NAME": os.path.join(BASE_DIR, default_db),
}
}

Expand Down
11 changes: 9 additions & 2 deletions pod/video/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.db.utils import IntegrityError
from django.template.defaultfilters import slugify
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
from django.urls import reverse
from django.conf import settings
Expand Down Expand Up @@ -218,7 +219,8 @@ def test_Type_with_attributs(self) -> None:
def test_delete_object(self) -> None:
"""Test delete object."""
Type.objects.get(id=1).delete()
self.assertEqual(Type.objects.all().count(), 0)
with self.assertRaises(Type.DoesNotExist):
Type.objects.get(id=1)
print(" ---> test_delete_object of TypeTestCase: OK!")


Expand Down Expand Up @@ -582,7 +584,8 @@ def test_VideoRendition_creation_with_values(self) -> None:
def test_delete_object(self) -> None:
self.create_video_rendition(resolution="640x365")
VideoRendition.objects.get(id=1).delete()
self.assertEqual(VideoRendition.objects.all().count(), 0)
with self.assertRaises(VideoRendition.DoesNotExist):
VideoRendition.objects.get(id=1)

print(" ---> test_delete_object of VideoRenditionTestCase: OK!")

Expand All @@ -593,6 +596,10 @@ class EncodingVideoTestCase(TestCase):
# fixtures = ['initial_data.json', ]

def setUp(self) -> None:
Site.objects.get_or_create(
id=getattr(settings, 'SITE_ID', 1),
defaults={'domain': 'localhost:8000', 'name': 'localhost:8000'}
)
user = User.objects.create(username="pod", password=PWD)
Type.objects.create(title="test")
Video.objects.create(
Expand Down
3 changes: 3 additions & 0 deletions pod/video_encode_transcript/encoding_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
DEFAULT_FROM_EMAIL = getattr(settings_local, "DEFAULT_FROM_EMAIL", "")
ADMINS = getattr(settings_local, "ADMINS", ())
DEBUG = getattr(settings_local, "DEBUG", True)
INSTANCE = getattr(settings_local, "INSTANCE", None)
TEST_REMOTE_ENCODE = getattr(settings_local, "TEST_REMOTE_ENCODE", False)

admins_email = [ad[1] for ad in ADMINS]
Expand All @@ -44,6 +45,8 @@
encoding_app.conf.task_routes = {
"pod.video_encode_transcript.encoding_tasks.*": {"queue": "encoding"}
}
if INSTANCE:
encoding_app.conf.broker_transport_options = {"global_keyprefix": INSTANCE}


# celery -A pod.video_encode_transcript.encoding_tasks worker -l INFO -Q encoding
Expand Down
Loading
Loading