Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajoute la configuration de dev pour docker-compose - reprise #5012

Closed
wants to merge 9 commits into from
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
22 changes: 11 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
base.db
.sass-cache/
/static
/tutoriels-private
/tutoriels-public
/contents-private
/contents-public
tutoriels-private
tutoriels-public
contents-private
contents-public
/media
/articles-data
articles-data
/zds/_version.py

/tutoriels-private-test
/tutoriels-public-test
/media-test
/articles-data-test
/contents-private-test
/contents-public-test
tutoriels-private-test
tutoriels-public-test
media-test
articles-data-test
contents-private-test
contents-public-test

/apache-solr

Expand Down
27 changes: 27 additions & 0 deletions Dockerfile_back
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM python:3-stretch

RUN apt-get update \
&& apt-get install -y --no-install-recommends --no-install-suggests \
git python3-setuptools libxml2-dev python3-lxml \
libxslt-dev libz-dev python3-sqlparse libjpeg62-turbo \
libjpeg62-turbo-dev libfreetype6 libfreetype6-dev \
libffi-dev python-tox build-essential \
xvfb xauth firefox-esr wget \
&& pip install wheel \
&& wget https://github.com/mozilla/geckodriver/releases/download/v0.16.1/geckodriver-v0.16.1-linux64.tar.gz \
&& tar -xzf geckodriver-v0.16.1-linux64.tar.gz -C /bin/ \
&& rm -rf /var/lib/apt/lists/* \
/var/cache/* \
/usr/share/doc/* \
/tmp/*

RUN mkdir -p /zds
WORKDIR /zds

COPY requirements.txt requirements-dev.txt requirements-prod.txt Makefile ./scripts/docker_dev_entrypoint.sh ./scripts/wait-for-it.sh /zds/

RUN pip install --upgrade -r requirements-dev.txt

RUN pip install --upgrade -r requirements-prod.txt

ENV DISPLAY=":99.0" PYTHONIOENCODING="utf-8" DJANGO_SETTINGS_MODULE="zds.settings.docker"
14 changes: 14 additions & 0 deletions Dockerfile_front
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:8-slim

RUN mkdir -p /zds
WORKDIR /zds

ENV NODE_ENV=development

COPY package.json yarn.lock ./

COPY ./scripts/wait-for-it.sh ./

RUN yarn

CMD ["yarn", "run", "gulp"]
10 changes: 10 additions & 0 deletions Dockerfile_zmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:8-slim

RUN mkdir -p /zds/zmd
WORKDIR /zds/zmd

COPY zmd/* ./scripts/docker_zmd_entrypoint.sh ./

RUN npm -g install pm2

RUN npm install --production
80 changes: 66 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,47 @@ install-macos:
brew install gettext cairo --without-x11 py2cairo node && \
pip3 install virtualenv virtualenvwrapper

## docker
### back
docker-back-start:
docker-compose up back
docker-back-stop:
docker-compose stop back
docker-back-test:
docker-compose exec back ./scripts/docker_start_xvfb.sh python manage.py test --settings zds.settings.docker_test
docker-back-lint:
docker-compose exec back flake8 zds

### zmd
docker-zmd-start:
docker-compose up zmarkdown
docker-zmd-stop:
docker-compose stop zmarkdown

### tools
docker-wipe:
docker-compose exec back python manage.py flush --noinput && \
docker-compose exec back rm -rf contents-private/* && \
docker-compose exec back rm -rf contents-public/*
docker-fixtures:
make docker-wipe && \
docker-compose exec back python manage.py loaddata ./fixtures/*.yaml && \
docker-compose exec back python manage.py load_fixtures --size=medium --all && \
docker-compose exec back python manage.py es_manager index_all
docker-doc:
docker-compose exec back bash -c 'cd doc && make html'
docker-generate-pdf:
docker-compose exec back python manage.py generate_pdf
### front
docker-front-clean:
docker-compose exec front yarn run clean
docker-front-build:
docker-compose exec front yarn run build
docker-front-lint:
docker-compose exec front yarn run lint
docker-front-test:
docker-compose exec front yarn test

# dev back
## django
generate-pdf:
Expand Down Expand Up @@ -118,20 +159,31 @@ restart_db: wipe migrate fixtures

help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " build-front to build frontend code"
@echo " doc to generate the html documentation"
@echo " fixtures to load every fixtures"
@echo " generate-pdf to regenerate all PDFs"
@echo " index-all to setup and (re)index all things for search"
@echo " index-flagged to index flagged things for search"
@echo " help to get this help"
@echo " install-back to install backend dependencies"
@echo " install-front to install frontend dependencies"
@echo " install-debian to install debian dependencies"
@echo " install-ubuntu to install ubuntu dependencies"
@echo " install-fedora to install fedora dependencies"
@echo " install-archlinux to install archlinux dependencies"
@echo " install-macos to install os x dependencies"
@echo " build-front to build frontend code"
@echo " doc to generate the html documentation"
@echo " fixtures to load every fixtures"
@echo " generate-pdf to regenerate all PDFs"
@echo " index-all to setup and (re)index all things for search"
@echo " index-flagged to get this help"
@echo " install-back to install backend dependencies"
@echo " install-front to install frontend dependencies"
@echo " install-debian to install debian dependencies"
@echo " install-ubuntu to install ubuntu dependencies"
@echo " install-fedora to install fedora dependencies"
@echo " install-archlinux to install archlinux dependencies"
@echo " install-macos to install os x dependencies"
@echo " docker-back-start to install and start web site from docker"
@echo " docker-back-stop to stop all docker containers from docker"
@echo " docker-back-test to test back end web site from docker"
@echo " docker-back-lint to lint back end web site from docker"
@echo " docker-fixtures to generate data from docker"
@echo " docker-wipe to wipe data and contents files from docker"
@echo " docker-front-clean to clean front from docker"
@echo " docker-front-build to build front from docker"
@echo " docker-front-lint to lint front from docker"
@echo " docker-front-test to test front from docker"
@echo " docker-doc to generate documentation from docker"
@echo " docker-docker-generate-pdf to regenerate all pdf from docker"
@echo " lint-back to lint backend code (flake8)"
@echo " lint-front to lint frontend code (jshint)"
@echo " clean-back to clean *.pyc"
Expand Down
9 changes: 7 additions & 2 deletions doc/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Si vous voulez installer et démarrer une instance locale de ZdS, vous devez cli

.. toctree::
:maxdepth: 2
:glob:

install/*
install/docker
install/backend-linux-install
install/backend-os-x-install
install/backend-windows-install
install/frontend-install
install/install-es
install/deploy-in-production
81 changes: 81 additions & 0 deletions doc/source/install/docker.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
======
Docker
======

Il est possible de faire tourner facilement ZdS avec Docker et
docker-compose.

.. note::

Notez que c’est encore un peu expérimental.


Démarrage rapide
----------------

`Installez Docker et docker-compose`__ (vous aurez besoin des deux).

.. __: https://docs.docker.com/compose/install/

Clonez le dépot de ZdS avec Git et rendez-vous dans le dossier cloné :

.. code-block:: sh

$ cd zds-site

Installez et démarrer le site :

.. code-block:: sh

$ ./make docker-back-start

Ce script va se charger de télécharger toutes les
dépendances, de démarrer les conteneurs Docker et de tout installer
automatiquement.

.. warning::

Ceci peut prendre un certain temps la première fois que vous lancer cette commande, puisqu'il faut télécharger
les containers.

À la fin, les migrations sont appliquées et vous pourrez accéder au
site à l’addresses http://localhost:8000.

Appuyez sur Ctrl+C pour tout arrêter.

Des données de test
-------------------

Pour avoir un jeu de données qui vous permette de travailler, vous pouvez lancer la commande suivante:

.. code-block:: sh

$ make docker-fixtures

.. warning::

Cette commande peut prendre aussi un certain temps.

A la fin, vous disposerez des utilisateurs de test listés sur `cette page`_.

.. _cette page: ../utils/fixture_loaders.html#le-chargement-de-jeux-de-donnees-fixtures

Commandes principales
---------------------

Installer le site via docker vous oblige a passer uniquement par des commandes docker pour
le reste de vos actions. Donc dans le Makefile, vous ne pourrez utiliser que les commandes ``make docker-*``.

- ``make docker-back-start`` : Démarre ZdS. Écoute par défaut sur le port 8000.
- ``make docker-back-test`` : Lance les tests du backend.
- ``make docker-front-test``: Lance les tests du frontend.
- ``make docker-fixture`` : Applique des fixtures et indexe les données dans elasticsearch. À utiliser pendant que le backend tourne.
- ``make docker-wipe`` : Supprime la base de données et les contenus.
- ``make docker-back-lint`` : Lint le backend.
- ``make docker-front-lint`` : Lint le frontend.


.. note::

Notez que ces commandes ne sont pas toutes conçues pour être lancées
en parallèle.
73 changes: 73 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
version: '3'

services:
front:
build:
context: .
dockerfile: Dockerfile_front
volumes:
- .:/zds
zmarkdown:
build:
context: .
dockerfile: Dockerfile_zmd
working_dir: /zds/zmd/
command: ["./docker_zmd_entrypoint.sh"]
ports:
- "27272:27272"
expose:
- "27272"
db:
image: "mysql:5"
restart: always
ports:
- "3306:3306"
expose:
- "3306"
volumes:
- dbdata:/var/lib/mysql
- rundb:/var/run/mysqld
environment:
MYSQL_DATABASE: "zdsdb"
MYSQL_USER: "zds"
MYSQL_PASSWORD: "zds"
MYSQL_ROOT_PASSWORD: "root"

back:
build:
context: .
dockerfile: Dockerfile_back
working_dir: /zds
command: ["./scripts/wait-for-it.sh", "-t", "90", "-s", "db:3306", "--", "./scripts/docker_dev_entrypoint.sh"]
depends_on:
- db
- front
- zmarkdown
- elasticsearch
volumes:
- .:/zds
- rundb:/var/run/mysqld:ro
ports:
- "${ZDS_ADDRESS:-127.0.0.1}:${ZDS_PORT:-8000}:8000"
environment:
# An optional comma-separated list of the hostnames to allow.
# Sets Django’s ALLOWED_HOSTS configuration variable.
- "ZDS_ALLOWED_HOSTS=${ZDS_ALLOWED_HOSTS:-*}"
# Elasticsearch is enabled if this variable is nonempty
- "ZDS_ELASTICSEARCH=${ZDS_ELASTICSEARCH}"

elasticsearch:
image: "docker.elastic.co/elasticsearch/elasticsearch:5.5.2"
environment:
- "http.host=0.0.0.0"
- "transport.host=127.0.0.1"
- "xpack.security.enabled=false"
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- esdata:/usr/share/elasticsearch/data

volumes:
db:
esdata:
dbdata:
rundb:
3 changes: 3 additions & 0 deletions scripts/docker_dev_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh -e
python manage.py migrate
exec python manage.py runserver 0.0.0.0:8000
7 changes: 7 additions & 0 deletions scripts/docker_start_xvfb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

XVFB_WHD=${XVFB_WHD:-1280x720x16}

Xvfb $DISPLAY -ac -screen 0 $XVFB_WHD -nolisten tcp &

exec $@
5 changes: 5 additions & 0 deletions scripts/docker_zmd_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh -e
cd ./node_modules/zmarkdown

npm run server
pm2 monit
Loading