Commit a2597dec authored by ynerant's avatar ynerant
Browse files

🎉 Init Django project

parents
Pipeline #4752 passed with stages
in 2 minutes and 3 seconds
# Byte-compiled / optimized / DLL files
dist
build
__pycache__
*.py[cod]
*$py.class
*.swp
*.egg-info
_build
.tox
.coverage
coverage
# Translations
*.mo
*.pot
# Jupyter Notebook
.ipynb_checkpoints
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# PyCharm project settings
.idea
# VSCode project settings
.vscode
# Local data
secrets.py
*.log
media/
# Virtualenv
env/
venv/
db.sqlite3
stages:
- test
- quality-assurance
py38:
stage: test
image: python:3.8-alpine
before_script:
- apk add --no-cache libmagic
- pip install tox --no-cache-dir
script: tox -e py3
py39:
stage: test
image: python:3.9-alpine
before_script:
- apk add --no-cache libmagic
- pip install tox --no-cache-dir
script: tox -e py3
linters:
stage: quality-assurance
image: python:3-alpine
before_script:
- pip install tox --no-cache-dir
script: tox -e linters
allow_failure: true
FROM python:3-alpine
ENV PYTHONUNBUFFERED 1
ENV DJANGO_ALLOW_ASYNC_UNSAFE 1
# Install LaTeX requirements
RUN apk add --no-cache gcc gettext libc-dev nginx postgresql-dev
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/requirements.txt
RUN pip install -r requirements.txt --no-cache-dir
COPY . /code/
RUN python manage.py collectstatic --noinput && \
python manage.py compilemessages
# Configure nginx
RUN mkdir /run/nginx
RUN ln -sf /dev/stdout /var/log/nginx/access.log && ln -sf /dev/stderr /var/log/nginx/error.log
RUN ln -sf /code/nginx.conf /etc/nginx/conf.d/django.conf
RUN rm /etc/nginx/conf.d/default.conf
ENTRYPOINT ["/code/entrypoint.sh"]
EXPOSE 80
CMD ["./manage.py", "shell"]
This diff is collapsed.
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0.txt)
[![pipeline status](https://gitlab.crans.org/ynerant/lglog/badges/master/pipeline.svg)](https://gitlab.crans.org/ynerant/lglog/-/commits/master)
[![coverage report](https://gitlab.crans.org/ynerant/lglog/badges/master/coverage.svg)](https://gitlab.crans.org/ynerant/lglog/-/commits/master)
# Historique de partie de loup-garou
Petit site pour pouvoir consulter l'historique d'une partie de loup-garou
## Création d'un environnement de développement
1. **Installation des dépendances de la distribution.**
Vous devez déjà installer Python et le module qui permet de créer des environnements virtuels.
On donne ci-dessous l'exemple pour une distribution basée sur Debian, mais vous pouvez facilement adapter pour ArchLinux ou autre.
```bash
$ sudo apt update
$ sudo apt install --no-install-recommends -y python3-setuptools python3-venv python3-dev git
```
2. **Clonage du dépot** là où vous voulez :
```bash
$ git clone git@gitlab.crans.org:ynerant/lglog.git && cd lglog
```
3. **Création d'un environment de travail Python décorrélé du système.**
On n'utilise pas `--system-site-packages` ici pour ne pas avoir des clashs de versions de modules avec le système.
```bash
$ python3 -m venv env
$ source env/bin/activate # entrer dans l'environnement
(env)$ pip3 install -r requirements.txt
(env)$ deactivate # sortir de l'environnement
```
4. **Migrations et chargement des données initiales.**
Pour initialiser la base de données avec de quoi travailler.
```bash
(env)$ ./manage.py collectstatic --noinput
(env)$ ./manage.py compilemessages
(env)$ ./manage.py makemigrations
(env)$ ./manage.py migrate
(env)$ ./manage.py loaddata initial
(env)$ ./manage.py createsuperuser # Création d'un utilisateur initial
```
5. Enjoy :
```bash
(env)$ ./manage.py runserver 0.0.0.0:8000
```
## Installation avec Docker
Il est possible de travailler sur une instance Docker.
Pour construire l'image Docker `lglog`,
```
git clone https://gitlab.crans.org/ynerant/lglog/ && cd lglog
docker build . -t lglog
```
Ensuite pour lancer le site en tant que vous (option `-u`),
l'exposer sur son port 80 (option `-p`) et monter le code en écriture (option `-v`),
```
docker run -it --rm -u $(id -u):$(id -g) -v "$(pwd):/code" -p 80:80 lglog
```
Si vous souhaitez lancer une commande spéciale, vous pouvez l'ajouter à la fin, par exemple,
```
docker run -it --rm -u $(id -u):$(id -g) -v "$(pwd):/code/" -p 80:80 lglog python3 ./manage.py createsuperuser
#!/bin/sh
python manage.py migrate
nginx
if [ "$DJANGO_STAGE" = "prod" ]; then
gunicorn -b 0.0.0.0:8000 --workers=2 --threads=4 --worker-class=gthread lglog.wsgi --access-logfile '-' --error-logfile '-';
else
python manage.py runserver 0.0.0.0:8000;
fi
"""
ASGI config for lglog project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'lglog.settings')
application = get_asgi_application()
"""
Django settings for lglog project.
Generated by 'django-admin startproject' using Django 3.1.3.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '9f3y(!rnf7+h@_g06#4^=7gvv2)+&jw3c_x#vvnl-pw@-%l+e)'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'lglog.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'lglog.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'fr'
TIME_ZONE = 'Europe/Paris'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'static'
from django.test import TestCase
class LGLogTests(TestCase):
def test_wsgi_asgi(self):
"""
Only for coverage.
"""
from lglog import asgi, wsgi
self.assertIsNotNone(asgi.application)
self.assertIsNotNone(wsgi.application)
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
"""
WSGI config for lglog project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'lglog.settings')
application = get_wsgi_application()
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'lglog.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
upstream django {
server 127.0.0.1:8000;
}
server {
listen 80;
server_name django;
location / {
proxy_pass http://django;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /static {
alias /code/static/;
}
}
[tox]
envlist =
py3
linters
skipsdist = True
[testenv]
sitepackages = False
deps =
coverage
Django~=3.1
django-polymorphic~=3.0
django-tables2~=2.3
commands =
coverage run --source=lglog ./manage.py test lglog/
coverage report -m
[testenv:linters]
deps =
flake8
flake8-colors
flake8-django
flake8-import-order
flake8-typing-imports
pep8-naming
pyflakes
commands =
flake8 lglog/
[flake8]
exclude =
.tox,
.git,
__pycache__,
build,
dist,
*.pyc,
*.egg-info,
.cache,
.eggs,
*migrations*
max-complexity = 10
max-line-length = 160
import-order-style = google
application-import-names = flake8
format = ${cyan}%(path)s${reset}:${yellow_bold}%(row)d${reset}:${green_bold}%(col)d${reset}: ${red_bold}%(code)s${reset} %(text)s
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment