Skip to content

Commit

Permalink
[DONE] Utilisation de l'adresse pod.localhost pour le développement (
Browse files Browse the repository at this point in the history
…EsupPortail#1134)

* chore: use pod.localhost in the dev env

This replaces the 'pod-back' hostname in the docker network,
and 'localhost' elsewhere.

This way the same hostname is used inside and outside docker,
this avoids confusions while developing.

* refactor: use .localhost domains for elasticserach and redis
  • Loading branch information
azmeuk authored and LoanR committed Jun 18, 2024
1 parent 8803f55 commit be67cc5
Show file tree
Hide file tree
Showing 24 changed files with 69 additions and 55 deletions.
12 changes: 6 additions & 6 deletions CONFIGURATION_FR.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ Il faudra pour cela créer un fichier de langue et traduire chaque entrée.<br>
>> d’encodage ou de flux RSS si la variable `CONTACT_US_EMAIL` n’est pas renseignée.<br><br>
>> _ref : [docs.djangoproject.com](https://docs.djangoproject.com/fr/3.2/ref/settings/#admins)_<br>
* `ALLOWED_HOSTS`
> valeur par défaut : `['localhost']`
> valeur par défaut : `['pod.localhost']`
>> Une liste de chaînes représentant des noms de domaine/d’hôte que ce site Django peut servir.<br><br>
>> C’est une mesure de sécurité pour empêcher les attaques d’en-tête Host HTTP,<br>
>> qui sont possibles même avec bien des configurations de serveur Web apparemment sécurisées.<br><br>
Expand All @@ -359,15 +359,15 @@ Il faudra pour cela créer un fichier de langue et traduire chaque entrée.<br>
>> # },
>> "default": {
>> "BACKEND": "django_redis.cache.RedisCache",
>> "LOCATION": "redis://127.0.0.1:6379/1",
>> "LOCATION": "redis://redis.localhost:6379/1",
>> "OPTIONS": {
>> "CLIENT_CLASS": "django_redis.client.DefaultClient",
>> },
>> },
>> # Persistent cache setup for select2 (NOT DummyCache or LocMemCache).
>> "select2": {
>> "BACKEND": "django_redis.cache.RedisCache",
>> "LOCATION": "redis://127.0.0.1:6379/2",
>> "LOCATION": "redis://redis.localhost:6379/2",
>> "OPTIONS": {
>> "CLIENT_CLASS": "django_redis.client.DefaultClient",
>> },
Expand Down Expand Up @@ -1934,7 +1934,7 @@ Il est possible d’encoder en local ou en distant.<br>
Attention, il faut configurer Celery pour l’envoi des instructions pour l’encodage distant.<br>
* `CELERY_BROKER_URL`
> valeur par défaut : `redis://127.0.0.1:6379/5`
> valeur par défaut : `redis://redis.localhost:6379/5`
>> URL du courtier de messages où Celery stocke les ordres d’encodage et de transcription.<br>
* `CELERY_TO_ENCODE`
> valeur par défaut : `False`
Expand Down Expand Up @@ -1976,7 +1976,7 @@ Attention, il faut configurer Celery pour l’envoi des instructions pour l’en
>>
>> Il faut renseigner l’url du redis sur lequel Celery<br>
>> va chercher les ordres d’encodage et de transcription<br>
>> par exemple : "redis://redis:6379/7"<br>
>> par exemple : "redis://redis.localhost:6379/7"<br>
* `FORMAT_CHOICES`
> valeur par défaut : `()`
>> Format d’encodage réalisé sur la plateforme.<br>
Expand Down Expand Up @@ -2057,7 +2057,7 @@ Attention, il faut configurer Celery pour l’envoi des instructions pour l’en
> valeur par défaut : `30`
>> Valeur de timeout pour ElasticSearch.<br>
* `ES_URL`
> valeur par défaut : `["http://127.0.0.1:9200/"]`
> valeur par défaut : `["http://elasticsearch.localhost:9200/"]`
>> Adresse du ou des instances d’Elasticsearch utilisées pour<br>
>> l’indexation et la recherche de vidéo.<br>
* `ES_VERSION`
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ help:

# Démarre le serveur de test
start:
(sleep 15 ; open http://localhost:8000) &
python3 manage.py runserver localhost:8000 --insecure
(sleep 15 ; open http://pod.localhost:8000) &
python3 manage.py runserver pod.localhost:8000 --insecure
# --insecure let serve static files even when DEBUG=False

# Démarre le serveur de test en https auto-signé
starts:
# nécessite les django-extensions
# cf https://timonweb.com/django/https-django-development-server-ssl-certificate/
(sleep 15 ; open https://localhost:8000) &
python3 manage.py runserver_plus localhost:8000 --cert-file cert.pem --key-file key.pem
(sleep 15 ; open https://pod.localhost:8000) &
python3 manage.py runserver_plus pod.localhost:8000 --cert-file cert.pem --key-file key.pem

# Première installation de pod (BDD SQLite intégrée)
install:
Expand Down
5 changes: 4 additions & 1 deletion docker-compose-dev-with-volumes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ version: '3.7'
services:
pod:
container_name: pod-dev-with-volumes
hostname: pod.localhost
build:
context: .
dockerfile: dockerfile-dev-with-volumes/pod/Dockerfile
Expand All @@ -23,6 +24,7 @@ services:

elasticsearch:
container_name: elasticsearch-with-volumes
hostname: elasticsearch.localhost
build:
context: .
dockerfile: dockerfile-dev-with-volumes/elasticsearch/dockerfile-elasticsearch-dev
Expand All @@ -36,6 +38,7 @@ services:

redis:
container_name: redis-with-volumes
hostname: redis.localhost
image: ${REDIS_TAG}
env_file:
- ./.env.dev
Expand All @@ -44,7 +47,7 @@ services:

# redis-commander:
# container_name: redis-commander
# hostname: redis-commander
# hostname: redis-commander.localhost
# image: rediscommander/redis-commander:latest
# restart: always
# environment:
Expand Down
8 changes: 7 additions & 1 deletion docker-compose-full-dev-with-volumes-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ version: '3.7'
services:
pod-back:
container_name: pod-back-with-volumes
hostname: pod.localhost
build:
context: .
dockerfile: dockerfile-dev-with-volumes/pod-back/Dockerfile
Expand All @@ -23,6 +24,7 @@ services:

pod-encode:
container_name: pod-encode-with-volumes
hostname: pod-encode.localhost
build:
context: .
dockerfile: dockerfile-dev-with-volumes/pod-encode/Dockerfile
Expand All @@ -34,6 +36,7 @@ services:

pod-transcript:
container_name: pod-transcript-with-volumes
hostname: pod-transcript.localhost
build:
context: .
dockerfile: dockerfile-dev-with-volumes/pod-transcript/Dockerfile
Expand All @@ -45,6 +48,7 @@ services:

pod-xapi:
container_name: pod-xapi-with-volumes
hostname: pod-xapi.localhost
build:
context: .
dockerfile: dockerfile-dev-with-volumes/pod-xapi/Dockerfile
Expand All @@ -56,6 +60,7 @@ services:

elasticsearch:
container_name: elasticsearch-with-volumes
hostname: elasticsearch.localhost
build:
context: .
dockerfile: dockerfile-dev-with-volumes/elasticsearch/dockerfile-elasticsearch-dev
Expand All @@ -69,6 +74,7 @@ services:

redis:
container_name: redis-with-volumes
hostname: redis.localhost
image: ${REDIS_TAG}
env_file:
- ./.env.dev
Expand All @@ -86,7 +92,7 @@ services:

# redis-commander:
# container_name: redis-commander
# hostname: redis-commander
# hostname: redis-commander.localhost
# image: rediscommander/redis-commander:latest
# restart: always
# environment:
Expand Down
7 changes: 6 additions & 1 deletion docker-compose-full-dev-with-volumes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ services:

pod-encode:
container_name: pod-encode-with-volumes
hostname: pod-encode.localhost
build:
context: .
dockerfile: dockerfile-dev-with-volumes/pod-encode/Dockerfile
Expand All @@ -35,6 +36,7 @@ services:

pod-transcript:
container_name: pod-transcript-with-volumes
hostname: pod-transcript.localhost
build:
context: .
dockerfile: dockerfile-dev-with-volumes/pod-transcript/Dockerfile
Expand All @@ -46,6 +48,7 @@ services:

pod-xapi:
container_name: pod-xapi-with-volumes
hostname: pod-xapi.localhost
build:
context: .
dockerfile: dockerfile-dev-with-volumes/pod-xapi/Dockerfile
Expand All @@ -69,6 +72,7 @@ services:

elasticsearch:
container_name: elasticsearch-with-volumes
hostname: elasticsearch.localhost
build:
context: .
dockerfile: dockerfile-dev-with-volumes/elasticsearch/dockerfile-elasticsearch-dev
Expand All @@ -82,6 +86,7 @@ services:

redis:
container_name: redis-with-volumes
hostname: redis.localhost
image: ${REDIS_TAG}
env_file:
- ./.env.dev
Expand Down Expand Up @@ -118,7 +123,7 @@ services:

# redis-commander:
# container_name: redis-commander
# hostname: redis-commander
# hostname: redis-commander.localhost
# image: rediscommander/redis-commander:latest
# restart: always
# environment:
Expand Down
12 changes: 6 additions & 6 deletions dockerfile-dev-with-volumes/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ v1.2, 2023-08-30
== Docker / docker compose avec volumes sur la machine hôte

=== Conteneur ElasticSearch
http://localhost:9200
http://elasticsearch.localhost:9200

==== elasticsearch:8.8.1
===== OS/ARCH
Expand Down Expand Up @@ -68,29 +68,29 @@ SECRET_KEY = "A_CHANGER"
DEBUG = True
# on précise ici qu'on utilise ES version 8
ES_VERSION = 8
ES_URL = ['http://elasticsearch:9200/']
ES_URL = ['http://elasticsearch.localhost:9200/']
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://redis:6379/3",
"LOCATION": "redis://redis.localhost:6379/3",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
"KEY_PREFIX": "pod"
},
"select2": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://redis:6379/2",
"LOCATION": "redis://redis.localhost:6379/2",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
},
}
SESSION_ENGINE = "redis_sessions.session"
SESSION_REDIS = {
"host": "redis",
"host": "redis.localhost",
"port": 6379,
"db": 4,
"prefix": "session",
Expand All @@ -103,7 +103,7 @@ MIGRATION_MODULES = {'flatpages': 'pod.db_migrations'}
# Si DOCKER_ENV = full il faut activer l'encodage et la transcription distante
# USE_REMOTE_ENCODING_TRANSCODING = True
# ENCODING_TRANSCODING_CELERY_BROKER_URL = "redis://redis:6379/7"
# ENCODING_TRANSCODING_CELERY_BROKER_URL = "redis://redis.localhost:6379/7"
# pour avoir le maximum de log sur la console
LOGGING = {}
Expand Down
4 changes: 2 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 @@ -3,14 +3,14 @@ echo "Launching commands into pod-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
until nc -z elasticsearch 9200; do echo waiting for elasticsearch; sleep 10; done;
until nc -z elasticsearch.localhost 9200; do echo waiting for elasticsearch; sleep 10; done;
# 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."
python3 manage.py create_pod_index
curl -XGET "elasticsearch:9200/pod/_search"
curl -XGET "elasticsearch.localhost:9200/pod/_search"
# Deployez les fichiers statiques
python3 manage.py collectstatic --no-input --clear
# 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
echo "Launching commands into pod-dev"
until nc -z pod-back 8000; do echo waiting for pod-back; sleep 10; done;
until nc -z pod.localhost 8000; do echo waiting for pod-back; sleep 10; done;
# Serveur d'encodage
celery -A pod.video_encode_transcript.encoding_tasks worker -l INFO -Q encoding --concurrency 1 -n encode
sleep infinity
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
echo "Launching commands into pod-dev"
until nc -z pod-back 8000; do echo waiting for pod-back; sleep 10; done;
until nc -z pod.localhost 8000; do echo waiting for pod-back; sleep 10; done;
# Serveur d'encodage
celery -A pod.video_encode_transcript.transcripting_tasks worker -l INFO -Q transcripting --concurrency 1 -n transcript
sleep infinity
2 changes: 1 addition & 1 deletion dockerfile-dev-with-volumes/pod-xapi/my-entrypoint-xapi.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
echo "Launching commands into pod-dev"
until nc -z pod-back 8000; do echo waiting for pod-back; sleep 10; done;
until nc -z pod.localhost 8000; do echo waiting for pod-back; sleep 10; done;
# Serveur xAPI
celery -A pod.xapi.xapi_tasks worker -l INFO -Q xapi --concurrency 1 -n xapi
sleep infinity
2 changes: 1 addition & 1 deletion dockerfile-dev-with-volumes/pod/my-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ BDD_FILE=/usr/src/app/pod/db.sqlite3
if test ! -f "$BDD_FILE"; then
echo "$BDD_FILE does not exist."
python3 manage.py create_pod_index
curl -XGET "elasticsearch:9200/pod/_search"
curl -XGET "elasticsearch.localhost:9200/pod/_search"
# Deployez les fichiers statiques
python3 manage.py collectstatic --no-input --clear
# 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.
Expand Down
14 changes: 7 additions & 7 deletions pod/custom/settings_local_docker_full_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@

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

# 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:8000/rest"
ENCODING_TRANSCODING_CELERY_BROKER_URL = 'redis://redis.localhost:6379/7'
POD_API_URL = "http://pod.localhost:8000/rest"
POD_API_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

USE_TRANSCRIPTION = True
Expand All @@ -79,7 +79,7 @@
}

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

# for maximum console logging\n
LOGGING = {}
2 changes: 1 addition & 1 deletion pod/live/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def test_attributs(self):
event.id = None
self.assertEqual(event.__str__(), "None")
self.assertEqual(event.get_thumbnail_card(), "/static/img/default-event.svg")
self.assertEqual(event.get_full_url(), "//localhost:8000/live/event/0001-event1/")
self.assertEqual(event.get_full_url(), "//pod.localhost:8000/live/event/0001-event1/")
print(" ---> test_attributs of EventTestCase: OK!")

def test_add_thumbnail(self):
Expand Down
Loading

0 comments on commit be67cc5

Please sign in to comment.