Commit b2cab7bc authored by Mickaël Desfrênes's avatar Mickaël Desfrênes
Browse files

change README

parent 99e38315
Loading
Loading
Loading
Loading
+5 −70
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ APIs et interfaces de stockage de médias.

## Pré-requis

- Python >= 3.7
- Python >= 3.9
- PostgreSQL >= 11
- exiftool
- imagemagick (convert)
@@ -43,72 +43,7 @@ JAMA_DEBUG="0"

## Démarrage (développement)

    JAMA_DEBUG=1 ./manage.py runserver  # démarrage sur localhost:8000
    
## Mise en production (Debian)

Une possibilité parmi d'autres est d'utiliser un serveur WSGI monté derrière un serveur web en reverse proxy. 
Pour la partie web, exemple avec Apache :

    a2enmod proxy_http

En production, lorsque le debug est désactivé, l'application ne prend pas en charge le service des assets, on doit
donc collecter toutes les ressources statiques dans un dossier :

    ./manage.py collectstatic
    
Puis dans la configuration de votre vhost:

    <Directory /path/to/jama/static>
        Require all granted
    </Directory>
    ProxyPass /static !
    ProxyPass / http://127.0.0.1:8000/
    ProxyPassReverse / http://127.0.0.1:8000/

Toujours dans le virtualenv, installez gunicorn:

    pip install gunicorn
    
Gunicorn est un serveur d'applications pour Python. Il maintient un pool de workers.
    
Crééz ensuite un nouveau service pour systemd dans /etc/systemd/system/jama.service:

    [Unit]
    Description=Jama Service
    
    [Service]
    Type=simple
    User=YourAppUser
    Group=YourAppGroup
    UMask=007
    ExecStart=/path/to/your/venv/bin/gunicorn --error-logfile /path/to/error.log --timeout 120 -b 127.0.0.1:8000 -w 5 --pythonpath /path/to/jama jama.wsgi
    Environment="PATH=/usr/bin/:/path/to/your/venv/bin:$PATH"
    Environment="JAMA_SECRET=AddY0uRoWns3crEth3re"
    Environment="JAMA_DEBUG=0"
    Environment="JAMA_SITE=http://localhost:8000/"
    Environment="JAMA_DB_HOST=localhost"
    Environment="JAMA_DB_PORT=5432"
    Environment="JAMA_DB_NAME=dbname"
    Environment="JAMA_DB_USER=dbuser"
    Environment="JAMA_DB_PASSWORD=dbpassword"
    Environment="JAMA_IIIF_DIR=/path/to/iiif_dir"
    Environment="JAMA_FILES_DIR=/path/to/medias/sources"
    Environment="JAMA_IIIF_ENDPOINT=https://www.domain.tld/fcgi-bin/iipsrv.fcgi?IIIF="
    Restart=always
    RestartSec=5
    TimeoutStopSec=10
    
    [Install]
    WantedBy=multi-user.target
    
Puis mettez à jour systemd...

    systemctl daemon-reload
    
...avant de démarrer Jama :

    systemctl start jama
    JAMA_DEBUG=1 poetry run ./manage.py runserver  # démarrage sur localhost:8000

## Commandes CLI

@@ -117,7 +52,7 @@ Puis mettez à jour systemd...
Une commande permet d'ajouter des fichiers locaux à Jama au nom d'un
utilisateur Jama:

    ./manage.py addlocalfiles /var/fichiers_a_ajouter/ jacques 1 --extensions .jpg .tif
    poetry run ./manage.py addlocalfiles /var/fichiers_a_ajouter/ jacques 1 --extensions .jpg .tif

Ici, le dossier `fichiers_a_ajouter` sera parcouru récursivement et les fichiers
avec une extension _.jpg_ ou _.tif_ seront ajoutés dans Jama dans le project ayant l'identifiant 1, 
@@ -139,7 +74,7 @@ Les enregistrements retournés correspondent aux collections Jama pour lesquelle

## Mise en place d'un projet et d'un utilisateur de test:

    (venv) code/jama: ./manage.py shell
    (venv) code/jama: poetry run ./manage.py shell
    >>> from resources.models import APIKey, Project, ProjectAccess, Permission, Role
    >>> from django.contrib.auth.models import User
    >>> test_project, _ = Project.objects.get_or_create(label="test")
@@ -243,7 +178,7 @@ Ajoutez un script update.sh dans le répertoire de Jama. Un exemple, à adapter

Lancez le service Huey en charge de l'exécution des tâches asynchrones:

    manage.py run_huey
    ./manage.py run_huey

(idéalement, maintenez ce processus via systemd).

mise_en_production.md

0 → 100644
+64 −0
Original line number Diff line number Diff line
# Mise en production (Debian)

Une possibilité parmi d'autres est d'utiliser un serveur WSGI monté derrière un serveur web en reverse proxy. 
Pour la partie web, exemple avec Apache :

    a2enmod proxy_http

En production, lorsque le debug est désactivé, l'application ne prend pas en charge le service des assets, on doit
donc collecter toutes les ressources statiques dans un dossier :

    ./manage.py collectstatic
    
Puis dans la configuration de votre vhost:

    <Directory /path/to/jama/static>
        Require all granted
    </Directory>
    ProxyPass /static !
    ProxyPass / http://127.0.0.1:8000/
    ProxyPassReverse / http://127.0.0.1:8000/

Toujours dans le virtualenv, installez gunicorn:

    pip install gunicorn
    
Gunicorn est un serveur d'applications pour Python. Il maintient un pool de workers.
    
Crééz ensuite un nouveau service pour systemd dans /etc/systemd/system/jama.service:

    [Unit]
    Description=Jama Service
    
    [Service]
    Type=simple
    User=YourAppUser
    Group=YourAppGroup
    UMask=007
    ExecStart=/path/to/your/venv/bin/gunicorn --error-logfile /path/to/error.log --timeout 120 -b 127.0.0.1:8000 -w 5 --pythonpath /path/to/jama jama.wsgi
    Environment="PATH=/usr/bin/:/path/to/your/venv/bin:$PATH"
    Environment="JAMA_SECRET=AddY0uRoWns3crEth3re"
    Environment="JAMA_DEBUG=0"
    Environment="JAMA_SITE=http://localhost:8000/"
    Environment="JAMA_DB_HOST=localhost"
    Environment="JAMA_DB_PORT=5432"
    Environment="JAMA_DB_NAME=dbname"
    Environment="JAMA_DB_USER=dbuser"
    Environment="JAMA_DB_PASSWORD=dbpassword"
    Environment="JAMA_IIIF_DIR=/path/to/iiif_dir"
    Environment="JAMA_FILES_DIR=/path/to/medias/sources"
    Environment="JAMA_IIIF_ENDPOINT=https://www.domain.tld/fcgi-bin/iipsrv.fcgi?IIIF="
    Restart=always
    RestartSec=5
    TimeoutStopSec=10
    
    [Install]
    WantedBy=multi-user.target
    
Puis mettez à jour systemd...

    systemctl daemon-reload
    
...avant de démarrer Jama :

    systemctl start jama