From 561ce7c45c6f7b1b0c642a5a5d5c659490837d8f Mon Sep 17 00:00:00 2001 From: Florentin Labelle <florentin.labelle@student-cs.fr> Date: Mon, 6 Jun 2022 00:52:47 +0200 Subject: [PATCH] Add corrections for Docker part --- README.md | 9 ++++----- solutions/2./2.1/2.1.1/.env | 4 ++++ solutions/2./2.1/2.1.3/.env | 4 ++++ solutions/2./2.2/2.2.1/.env | 11 +++++++++++ solutions/2./2.2/2.2.3/.env | 11 +++++++++++ solutions/2./2.2/2.2.3/Dockerfile | 19 +++++++++++++++++++ solutions/2./2.2/2.2.4/.env | 11 +++++++++++ .../2.2/2.2.4/Dockerfile} | 13 ++++++++++--- 8 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 solutions/2./2.1/2.1.1/.env create mode 100644 solutions/2./2.1/2.1.3/.env create mode 100644 solutions/2./2.2/2.2.1/.env create mode 100644 solutions/2./2.2/2.2.3/.env create mode 100644 solutions/2./2.2/2.2.3/Dockerfile create mode 100644 solutions/2./2.2/2.2.4/.env rename solutions/{dockerfiles/Back/Dockerfile.back.alpine => 2./2.2/2.2.4/Dockerfile} (54%) diff --git a/README.md b/README.md index 010dc56..16be646 100644 --- a/README.md +++ b/README.md @@ -94,18 +94,17 @@ Le back est fait en Django, tu dois donc: ``Attention: ne pas ajouter de fichier non désiré dans l'image (par exemple le .env ou les node_modules s'il y en a)`` #### 2.2.2 Tester l'image -Pour tester que le back fonctionne bien il va falloir d'abord mettre en place une base de donnée mysql, pour que le back s'y connecte. -``` -docker run -p 3306:3306 -e MYSQL_RANDOM_ROOT_PASSWORD=yes -e MYSQL_USER=vroum -e MYSQL_PASSWORD=password -e MYSQL_DATABASE=vroum -d mysql -``` +Pour tester que le back fonctionne bien il va falloir d'abord remplir un **.env** dans le dossier du back: + - Pensez à mettre `PRODUCTION` en `FALSE` pour utiliser du SQLite, les informations pour la BDD ne compte alors pas. Puis faire tourner le back: ``` docker run -p 8000:8000 --env-file .env vroum-back ``` -Attention à bien remplir le .env avec les bonnes valeur pour se connecter à la BDD. Faire des curl pour tester que tout marche à peu près bien. +Pour tester le back, tu peux ausi utiliser le front en lançant les deux conteneurs simultanément. + #### 2.2.3 Challenge supplémentaire (Facultatif et plus dur que pour le front) Il est souvent considéré comme une mauvaise pratique d'avoir des conteneurs qui tournent avec l'utilisateur **root** en production. Vérifie que ce n'est pas le cas ou alors fait les changements nécéssaires. diff --git a/solutions/2./2.1/2.1.1/.env b/solutions/2./2.1/2.1.1/.env new file mode 100644 index 0000000..e37704f --- /dev/null +++ b/solutions/2./2.1/2.1.1/.env @@ -0,0 +1,4 @@ +REACT_APP_API_URL=http://localhost:8000 +REACT_APP_LOGIN_ROUTE=/auth/login +REACT_APP_LOGOUT_ROUTE=/auth/logout +REACT_APP_CLIENT_URL=http://localhost:8080 \ No newline at end of file diff --git a/solutions/2./2.1/2.1.3/.env b/solutions/2./2.1/2.1.3/.env new file mode 100644 index 0000000..e37704f --- /dev/null +++ b/solutions/2./2.1/2.1.3/.env @@ -0,0 +1,4 @@ +REACT_APP_API_URL=http://localhost:8000 +REACT_APP_LOGIN_ROUTE=/auth/login +REACT_APP_LOGOUT_ROUTE=/auth/logout +REACT_APP_CLIENT_URL=http://localhost:8080 \ No newline at end of file diff --git a/solutions/2./2.2/2.2.1/.env b/solutions/2./2.2/2.2.1/.env new file mode 100644 index 0000000..270a2aa --- /dev/null +++ b/solutions/2./2.2/2.2.1/.env @@ -0,0 +1,11 @@ +BACK_ROOT=http://localhost:8000/api +FRONT_ROOT=http://localhost:8080 +CLIENT_ID=clientid +CLIENT_SECRET=clientsecret +PRODUCTION=FALSE +ALLOWED_HOSTS=localhost +DATABASE_NAME= +DATABASE_USER= +DATABASE_PASSWORD= +DATABASE_HOST= +SALT=verylongrandomstring \ No newline at end of file diff --git a/solutions/2./2.2/2.2.3/.env b/solutions/2./2.2/2.2.3/.env new file mode 100644 index 0000000..270a2aa --- /dev/null +++ b/solutions/2./2.2/2.2.3/.env @@ -0,0 +1,11 @@ +BACK_ROOT=http://localhost:8000/api +FRONT_ROOT=http://localhost:8080 +CLIENT_ID=clientid +CLIENT_SECRET=clientsecret +PRODUCTION=FALSE +ALLOWED_HOSTS=localhost +DATABASE_NAME= +DATABASE_USER= +DATABASE_PASSWORD= +DATABASE_HOST= +SALT=verylongrandomstring \ No newline at end of file diff --git a/solutions/2./2.2/2.2.3/Dockerfile b/solutions/2./2.2/2.2.3/Dockerfile new file mode 100644 index 0000000..eb1d5c8 --- /dev/null +++ b/solutions/2./2.2/2.2.3/Dockerfile @@ -0,0 +1,19 @@ +FROM python:3.8 +RUN useradd -m vroum +USER vroum + +WORKDIR /home/vroum + +COPY --chown=vroum:vroum requirements.txt /home/vroum/ +RUN pip install -r requirements.txt + +COPY --chown=vroum:vroum back/ /home/vroum/back/ +COPY --chown=vroum:vroum car/ /home/vroum/car/ +COPY --chown=vroum:vroum squad/ /home/vroum/squad/ +COPY --chown=vroum:vroum trip/ /home/vroum/trip/ +COPY --chown=vroum:vroum user/ /home/vroum/user/ +COPY --chown=vroum:vroum manage.py /home/vroum/manage.py + +ENTRYPOINT python3 manage.py makemigrations \ + && python3 manage.py migrate \ + && python3 manage.py runserver 0.0.0.0:8000 diff --git a/solutions/2./2.2/2.2.4/.env b/solutions/2./2.2/2.2.4/.env new file mode 100644 index 0000000..270a2aa --- /dev/null +++ b/solutions/2./2.2/2.2.4/.env @@ -0,0 +1,11 @@ +BACK_ROOT=http://localhost:8000/api +FRONT_ROOT=http://localhost:8080 +CLIENT_ID=clientid +CLIENT_SECRET=clientsecret +PRODUCTION=FALSE +ALLOWED_HOSTS=localhost +DATABASE_NAME= +DATABASE_USER= +DATABASE_PASSWORD= +DATABASE_HOST= +SALT=verylongrandomstring \ No newline at end of file diff --git a/solutions/dockerfiles/Back/Dockerfile.back.alpine b/solutions/2./2.2/2.2.4/Dockerfile similarity index 54% rename from solutions/dockerfiles/Back/Dockerfile.back.alpine rename to solutions/2./2.2/2.2.4/Dockerfile index f235325..260f2ba 100644 --- a/solutions/dockerfiles/Back/Dockerfile.back.alpine +++ b/solutions/2./2.2/2.2.4/Dockerfile @@ -1,17 +1,24 @@ FROM python:3.8-alpine3.15 -WORKDIR /back/ +RUN adduser -D vroum +USER vroum +WORKDIR /home/vroum # Required apk packages for building of mysqlclient and cffi python packages RUN apk update \ && apk add --virtual build-deps gcc musl-dev mariadb-dev libffi-dev -COPY requirements.txt /back/ +COPY requirements.txt /home/vroum RUN pip install -r requirements.txt # Remove apk packages that were only necessary at build time RUN apk del build-deps -COPY ./ /back/ +COPY --chown=vroum:vroum back/ /home/vroum/back/ +COPY --chown=vroum:vroum car/ /home/vroum/car/ +COPY --chown=vroum:vroum squad/ /home/vroum/squad/ +COPY --chown=vroum:vroum trip/ /home/vroum/trip/ +COPY --chown=vroum:vroum user/ /home/vroum/user/ +COPY --chown=vroum:vroum manage.py /home/vroum/manage.py ENTRYPOINT python3 manage.py makemigrations \ && python3 manage.py migrate \ && python3 manage.py runserver 0.0.0.0:8000 \ No newline at end of file -- GitLab