No virtualenv in production
This commit is contained in:
parent
032c9086f8
commit
4fedc48e7f
8 changed files with 114 additions and 22 deletions
27
README.md
27
README.md
|
|
@ -92,16 +92,7 @@ production néccessite **une installation de Debian Bullseye ou plus récent**.
|
||||||
$ sudo chmod g+rwx -R static media
|
$ sudo chmod g+rwx -R static media
|
||||||
```
|
```
|
||||||
|
|
||||||
3. **Création d'un environment de travail Python décorrélé du système.**
|
3. **Configuration de UWSGI et NGINX.**
|
||||||
|
|
||||||
```bash
|
|
||||||
$ python3 -m venv venv --system-site-packages
|
|
||||||
$ source venv/bin/activate # entrer dans l'environnement
|
|
||||||
(env)$ pip3 install -r requirements.txt
|
|
||||||
(env)$ deactivate # sortir de l'environnement
|
|
||||||
```
|
|
||||||
|
|
||||||
4. **Configuration de UWSGI et NGINX.**
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ sudo cp docs/uwsgi_photos.ini /etc/uwsgi/apps-available/uwsgi_photos.ini
|
$ sudo cp docs/uwsgi_photos.ini /etc/uwsgi/apps-available/uwsgi_photos.ini
|
||||||
|
|
@ -110,7 +101,7 @@ production néccessite **une installation de Debian Bullseye ou plus récent**.
|
||||||
$ sudo ln -s /etc/nginx/sites-available/photos.crans.org /etc/nginx/sites-enabled/
|
$ sudo ln -s /etc/nginx/sites-available/photos.crans.org /etc/nginx/sites-enabled/
|
||||||
```
|
```
|
||||||
|
|
||||||
5. **Base de données.**
|
4. **Base de données.**
|
||||||
En production on utilise PostgreSQL.
|
En production on utilise PostgreSQL.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
@ -120,17 +111,17 @@ production néccessite **une installation de Debian Bullseye ou plus récent**.
|
||||||
postgres=# CREATE DATABASE photo21 OWNER photo21;
|
postgres=# CREATE DATABASE photo21 OWNER photo21;
|
||||||
```
|
```
|
||||||
|
|
||||||
6. **Migrations et collecte des fichiers statiques**,
|
5. **Migrations et collecte des fichiers statiques**,
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo -u www-data ./venv/bin/python ./manage.py collectstatic
|
$ sudo -u www-data ./manage.py collectstatic
|
||||||
$ sudo -u www-data ./venv/bin/python ./manage.py check
|
$ sudo -u www-data ./manage.py check
|
||||||
$ sudo -u www-data ./venv/bin/python ./manage.py migrate
|
$ sudo -u www-data ./manage.py migrate
|
||||||
$ sudo -u www-data ./venv/bin/python ./manage.py loaddata initial
|
$ sudo -u www-data ./manage.py loaddata initial
|
||||||
$ sudo ./venv/bin/python ./manage.py compilemessages
|
$ sudo ./manage.py compilemessages
|
||||||
```
|
```
|
||||||
|
|
||||||
7. *Enjoy \o/*
|
6. *Enjoy \o/*
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
|
|
|
||||||
3
allauth_note_kfet/__init__.py
Normal file
3
allauth_note_kfet/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# This file is part of photo21
|
||||||
|
# Copyright (C) 2022 Amicale des élèves de l'ENS Paris-Saclay
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
42
allauth_note_kfet/provider.py
Normal file
42
allauth_note_kfet/provider.py
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
# From https://gitlab.crans.org/bde/allauth-note-kfet
|
||||||
|
# Copyright (C) 2022 Amicale des élèves de l'ENS Paris-Saclay
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from allauth.account.models import EmailAddress
|
||||||
|
from allauth.socialaccount.providers.base import ProviderAccount
|
||||||
|
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
|
||||||
|
|
||||||
|
|
||||||
|
class NoteKfetAccount(ProviderAccount):
|
||||||
|
def to_str(self):
|
||||||
|
return self.account.extra_data.get("username")
|
||||||
|
|
||||||
|
|
||||||
|
class NoteKfetProvider(OAuth2Provider):
|
||||||
|
id = "notekfet"
|
||||||
|
name = "Note Kfet"
|
||||||
|
account_class = NoteKfetAccount
|
||||||
|
|
||||||
|
def extract_uid(self, data):
|
||||||
|
return str(data["username"])
|
||||||
|
|
||||||
|
def extract_common_fields(self, data):
|
||||||
|
return dict(
|
||||||
|
email=data.get("email"),
|
||||||
|
username=data.get("username"),
|
||||||
|
last_name=data.get("last_name"),
|
||||||
|
first_name=data.get("first_name"),
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_default_scope(self):
|
||||||
|
return ["read"]
|
||||||
|
|
||||||
|
def extract_email_addresses(self, data):
|
||||||
|
ret = []
|
||||||
|
email = data.get("email")
|
||||||
|
if email:
|
||||||
|
ret.append(EmailAddress(email=email, verified=True, primary=True))
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
provider_classes = [NoteKfetProvider]
|
||||||
9
allauth_note_kfet/urls.py
Normal file
9
allauth_note_kfet/urls.py
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
# This file is part of photo21
|
||||||
|
# Copyright (C) 2022 Amicale des élèves de l'ENS Paris-Saclay
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns
|
||||||
|
|
||||||
|
from .provider import NoteKfetProvider
|
||||||
|
|
||||||
|
urlpatterns = default_urlpatterns(NoteKfetProvider)
|
||||||
50
allauth_note_kfet/views.py
Normal file
50
allauth_note_kfet/views.py
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
# From https://gitlab.crans.org/bde/allauth-note-kfet
|
||||||
|
# Copyright (C) 2022 Amicale des élèves de l'ENS Paris-Saclay
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from allauth.socialaccount import app_settings
|
||||||
|
from allauth.socialaccount.providers.oauth2.views import (
|
||||||
|
OAuth2Adapter,
|
||||||
|
OAuth2CallbackView,
|
||||||
|
OAuth2LoginView,
|
||||||
|
)
|
||||||
|
|
||||||
|
from .provider import NoteKfetProvider
|
||||||
|
|
||||||
|
|
||||||
|
class NoteKfetOAuth2Adapter(OAuth2Adapter):
|
||||||
|
provider_id = NoteKfetProvider.id
|
||||||
|
|
||||||
|
def complete_login(self, request, app, token, **kwargs):
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"Bearer {token.token}",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
}
|
||||||
|
extra_data = requests.get(self.profile_url, headers=headers)
|
||||||
|
|
||||||
|
return self.get_provider().sociallogin_from_response(request, extra_data.json())
|
||||||
|
|
||||||
|
@property
|
||||||
|
def settings(self):
|
||||||
|
return app_settings.PROVIDERS.get(self.provider_id, {})
|
||||||
|
|
||||||
|
@property
|
||||||
|
def domain(self):
|
||||||
|
return self.settings.get("DOMAIN", "note.crans.org")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def access_token_url(self):
|
||||||
|
return f"https://{self.domain}/o/token/"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def authorize_url(self):
|
||||||
|
return f"https://{self.domain}/o/authorize/"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def profile_url(self):
|
||||||
|
return f"https://{self.domain}/api/me/"
|
||||||
|
|
||||||
|
|
||||||
|
oauth2_login = OAuth2LoginView.adapter_view(NoteKfetOAuth2Adapter)
|
||||||
|
oauth2_callback = OAuth2CallbackView.adapter_view(NoteKfetOAuth2Adapter)
|
||||||
|
|
@ -9,8 +9,6 @@ gid = www-data
|
||||||
# Django-related settings
|
# Django-related settings
|
||||||
# the base directory (full path)
|
# the base directory (full path)
|
||||||
chdir = /var/www/photos/photo21
|
chdir = /var/www/photos/photo21
|
||||||
# the virtualenv (full path)
|
|
||||||
home = /var/www/photos/photo21/venv
|
|
||||||
wsgi-file = /var/www/photos/photo21/photo21/wsgi.py
|
wsgi-file = /var/www/photos/photo21/photo21/wsgi.py
|
||||||
plugin = python3
|
plugin = python3
|
||||||
# process-related settings
|
# process-related settings
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,4 @@ django-allauth>=0.44
|
||||||
django-crispy-forms~=1.7
|
django-crispy-forms~=1.7
|
||||||
Django>=2.2.20
|
Django>=2.2.20
|
||||||
ExifRead>=2.1.2
|
ExifRead>=2.1.2
|
||||||
git+https://gitlab.crans.org/bde/allauth-note-kfet.git
|
|
||||||
Pillow>=6.0.0
|
Pillow>=6.0.0
|
||||||
2
tox.ini
2
tox.ini
|
|
@ -26,7 +26,7 @@ deps =
|
||||||
pep8-naming
|
pep8-naming
|
||||||
pyflakes
|
pyflakes
|
||||||
commands =
|
commands =
|
||||||
flake8 photo21 photologue
|
flake8 allauth_note_kfet photo21 photologue
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
ignore = W503, I100, I101
|
ignore = W503, I100, I101
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue