Skip to content

Commit dd08c8e

Browse files
authored
Rétro-portage des améliorations Docker #1328 (#1337)
* chore: use Debian 12 instead of Debian 11 in Docker containers * chore: auto-restart celery process on file change with watchdog * chore: add healthchecks in the docker images * chore: rely on Docker healthchecks to start services avoid explicit looping on entrypoints to know if services are ready, and let Docker handle the checks itself with the containers HEALTHCHECKs * chore: reduce the number of Docker COPY calls
1 parent 4aa9144 commit dd08c8e

17 files changed

+72
-51
lines changed

.env.dev-exemple

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ DJANGO_SUPERUSER_EMAIL=<MAIL>
44
### You can use internal registry
55
ELASTICSEARCH_TAG=elasticsearch:8.13.0
66
NODE_TAG=node:23
7-
PYTHON_TAG=python:3.9-bullseye
7+
PYTHON_TAG=python:3.9-bookworm
88
REDIS_TAG=redis:alpine3.16
99
### DOCKER_ENV: You can specify light or full.
1010
### In case of value changing, you have to rebuild and restart your container.

docker-compose-dev-with-volumes.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ services:
1212
context: .
1313
dockerfile: dockerfile-dev-with-volumes/pod/Dockerfile
1414
depends_on:
15-
- elasticsearch
16-
- redis
15+
elasticsearch:
16+
condition: service_healthy
17+
redis:
18+
condition: service_healthy
1719
env_file:
1820
- ./.env.dev
1921
ports:
@@ -42,6 +44,8 @@ services:
4244
- ./.env.dev
4345
ports:
4446
- 6379:6379
47+
healthcheck:
48+
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
4549

4650
# redis-commander:
4751
# container_name: redis-commander

docker-compose-full-dev-with-volumes-test.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ services:
1212
context: .
1313
dockerfile: dockerfile-dev-with-volumes/pod-back/Dockerfile
1414
depends_on:
15-
- elasticsearch
16-
- redis
15+
elasticsearch:
16+
condition: service_healthy
17+
redis:
18+
condition: service_healthy
1719
env_file:
1820
- ./.env.dev
1921
ports:
@@ -27,7 +29,8 @@ services:
2729
context: .
2830
dockerfile: dockerfile-dev-with-volumes/pod-encode/Dockerfile
2931
depends_on:
30-
- pod-back
32+
pod-back:
33+
condition: service_healthy
3134
env_file:
3235
- ./.env.dev
3336
volumes: *pod-volumes
@@ -39,7 +42,8 @@ services:
3942
context: .
4043
dockerfile: dockerfile-dev-with-volumes/pod-transcript/Dockerfile
4144
depends_on:
42-
- pod-back
45+
pod-back:
46+
condition: service_healthy
4347
env_file:
4448
- ./.env.dev
4549
volumes: *pod-volumes
@@ -51,7 +55,8 @@ services:
5155
context: .
5256
dockerfile: dockerfile-dev-with-volumes/pod-xapi/Dockerfile
5357
depends_on:
54-
- pod-back
58+
pod-back:
59+
condition: service_healthy
5560
env_file:
5661
- ./.env.dev
5762
volumes: *pod-volumes
@@ -78,6 +83,8 @@ services:
7883
- ./.env.dev
7984
ports:
8085
- 6379:6379
86+
healthcheck:
87+
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
8188

8289
pa11y-ci:
8390
container_name: pa11y-ci

docker-compose-full-dev-with-volumes.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ services:
1212
context: .
1313
dockerfile: dockerfile-dev-with-volumes/pod-back/Dockerfile
1414
depends_on:
15-
- elasticsearch
16-
- redis
15+
elasticsearch:
16+
condition: service_healthy
17+
redis:
18+
condition: service_healthy
1719
env_file:
1820
- ./.env.dev
1921
ports:
@@ -27,7 +29,8 @@ services:
2729
context: .
2830
dockerfile: dockerfile-dev-with-volumes/pod-encode/Dockerfile
2931
depends_on:
30-
- pod-back
32+
pod-back:
33+
condition: service_healthy
3134
env_file:
3235
- ./.env.dev
3336
volumes: *pod-volumes
@@ -39,7 +42,8 @@ services:
3942
context: .
4043
dockerfile: dockerfile-dev-with-volumes/pod-transcript/Dockerfile
4144
depends_on:
42-
- pod-back
45+
pod-back:
46+
condition: service_healthy
4347
env_file:
4448
- ./.env.dev
4549
volumes: *pod-volumes
@@ -51,7 +55,8 @@ services:
5155
context: .
5256
dockerfile: dockerfile-dev-with-volumes/pod-xapi/Dockerfile
5357
depends_on:
54-
- pod-back
58+
pod-back:
59+
condition: service_healthy
5560
env_file:
5661
- ./.env.dev
5762
volumes: *pod-volumes
@@ -78,6 +83,8 @@ services:
7883
- ./.env.dev
7984
ports:
8085
- 6379:6379
86+
healthcheck:
87+
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
8188

8289
# redis-commander:
8390
# container_name: redis-commander

dockerfile-dev-with-volumes/README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ DJANGO_SUPERUSER_PASSWORD=
5252
DJANGO_SUPERUSER_EMAIL=
5353
ELASTICSEARCH_TAG=elasticsearch:8.13.0
5454
NODE_TAG=node:23
55-
PYTHON_TAG=python:3.9-bullseye
55+
PYTHON_TAG=python:3.9-bookworm
5656
REDIS_TAG=redis:alpine3.16
5757
DOCKER_ENV=light
5858
----

dockerfile-dev-with-volumes/elasticsearch/dockerfile-elasticsearch-dev

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
# Conteneur elasticsearch
77
ARG ELASTICSEARCH_VERSION
88
FROM $ELASTICSEARCH_VERSION
9-
# TODO
10-
#FROM harbor.urba.univ-lille.fr/store/elasticsearch:7.17.7
9+
10+
HEALTHCHECK --timeout=3s --start-period=60s --start-interval=1s CMD \
11+
curl --fail --silent http://elasticsearch.localhost:9200/_cluster/health || exit 1
1112

1213
RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-icu
1314

dockerfile-dev-with-volumes/pod-back/Dockerfile

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,29 @@ FROM $PYTHON_VERSION
2020
#FROM harbor.urba.univ-lille.fr/store/python:3.7-buster
2121

2222
RUN apt-get update \
23-
&& apt-get install -y --no-install-recommends netcat gettext \
23+
&& apt-get install --yes --no-install-recommends \
24+
gettext \
25+
curl \
2426
&& apt-get clean\
2527
&& rm -rf /var/lib/apt/lists/*
2628

2729
WORKDIR /usr/src/app
2830

29-
COPY ./requirements.txt .
30-
COPY ./requirements-encode.txt .
31-
COPY ./requirements-conteneur.txt .
32-
COPY ./requirements-dev.txt .
31+
COPY ./requirements.txt ./requirements-encode.txt ./requirements-conteneur.txt ./requirements-dev.txt .
3332
RUN mkdir /tmp/node_modules/
3433

3534
COPY --from=source-build-js /tmp/pod/node_modules/ /tmp/node_modules/
3635
# TODO remove ES version - move it into env var
37-
RUN pip3 install --no-cache-dir -r requirements-conteneur.txt \
36+
RUN pip3 install --no-cache-dir \
37+
--requirement requirements-dev.txt \
38+
--requirement requirements-conteneur.txt \
3839
&& pip3 install elasticsearch==7.17.7
3940

4041
# ENTRYPOINT:
4142
COPY ./dockerfile-dev-with-volumes/pod-back/my-entrypoint-back.sh /tmp/my-entrypoint-back.sh
4243
RUN chmod 755 /tmp/my-entrypoint-back.sh
4344

44-
ENTRYPOINT ["bash", "/tmp/my-entrypoint-back.sh"]
45+
HEALTHCHECK --timeout=3s --start-period=60s --start-interval=1s CMD \
46+
curl --fail http://pod.localhost:8000 || exit 1
47+
48+
ENTRYPOINT ["bash", "/tmp/my-entrypoint-back.sh"]

dockerfile-dev-with-volumes/pod-back/my-entrypoint-back.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ echo "Launching commands into pod-dev"
33
mkdir -p pod/node_modules
44
mkdir -p pod/db_migrations && touch pod/db_migrations/__init__.py
55
ln -fs /tmp/node_modules/* pod/node_modules
6-
until nc -z elasticsearch.localhost 9200; do echo waiting for elasticsearch; sleep 10; done;
76
# Mise en route
87
# Base de données SQLite intégrée
98
BDD_FILE=/usr/src/app/pod/db.sqlite3
109
if test ! -f "$BDD_FILE"; then
1110
echo "$BDD_FILE does not exist."
1211
python3 manage.py create_pod_index
13-
curl -XGET "elasticsearch.localhost:9200/pod/_search"
12+
curl -XGET "elasticsearch:9200/pod/_search"
1413
# Deployez les fichiers statiques
1514
python3 manage.py collectstatic --no-input --clear
1615
# 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.

dockerfile-dev-with-volumes/pod-encode/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ COPY ./pod/ .
1818

1919
RUN apt-get update \
2020
&& apt-get install -y --no-install-recommends \
21-
netcat \
2221
ffmpeg \
2322
&& apt-get clean\
2423
&& rm -rf /var/lib/apt/lists/*
2524

2625
WORKDIR /usr/src/app
2726

28-
COPY ./requirements-encode.txt .
27+
COPY ./requirements-encode.txt ./requirements-conteneur.txt .
2928

30-
RUN pip3 install --no-cache-dir -r requirements-encode.txt
29+
RUN pip3 install --no-cache-dir \
30+
--requirement requirements-encode.txt \
31+
--requirement requirements-conteneur.txt
3132

3233
# ENTRYPOINT:
3334
COPY ./dockerfile-dev-with-volumes/pod-encode/my-entrypoint-encode.sh /tmp/my-entrypoint-encode.sh
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
echo "Launching commands into pod-dev"
3-
until nc -z pod.localhost 8000; do echo waiting for pod-back; sleep 10; done;
43
# Serveur d'encodage
4+
watchmedo auto-restart --directory=/usr/src/app --pattern=*.py --recursive -- \
55
celery -A pod.video_encode_transcript.encoding_tasks worker -l INFO -Q encoding --concurrency 1 -n encode
66
sleep infinity

0 commit comments

Comments
 (0)