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

allow redis and postgres to run in docker compose #936

Draft
wants to merge 3 commits into
base: taiste
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
HTTPS=off
DEBUG=true

# This is not the real key used in prod
SECRET_KEY=(4sjxvhz@m5$0a$j0_pqicnc$s!vbve)z+&++m%g%bjhlz4+g2

DATABASE_URL=sqlite:///db.sqlite3
# uncomment the next line if you want to use a postgres database
#DATABASE_URL=postgres://user:[email protected]:5432/sith
CACHE_URL=redis://127.0.0.1:6379/0

MEDIA_ROOT=data
STATIC_ROOT=static

[email protected]
[email protected]

HONEYPOT_VALUE=content
HONEYPOT_FIELD_NAME=body2
HONEYPOT_FIELD_NAME_FORUM=message2

EMAIL_BACKEND=django.core.mail.backends.console.EmailBackend
EMAIL_HOST=localhost
EMAIL_PORT=25

SITH_URL=127.0.0.1:8000
SITH_NAME="AE UTBM"

SITH_MAIN_CLUB_ID=1

SITH_GROUP_ROOT_ID=1
SITH_GROUP_PUBLIC_ID=2
SITH_GROUP_SUBSCRIBERS_ID=3
SITH_GROUP_OLD_SUBSCRIBERS_ID=4
SITH_GROUP_ACCOUNTING_ADMIN_ID=5
SITH_GROUP_COM_ADMIN_ID=6
SITH_GROUP_COUNTER_ADMIN_ID=7
SITH_GROUP_SAS_ADMIN_ID=8
SITH_GROUP_FORUM_ADMIN_ID=9
SITH_GROUP_PEDAGOGY_ADMIN_ID=10

SITH_GROUP_BANNED_ALCOHOL_ID=11
SITH_GROUP_BANNED_COUNTER_ID=12
SITH_GROUP_BANNED_SUBSCRIPTION_ID=13

SITH_CLUB_REFOUND_ID=89
SITH_COUNTER_REFOUND_ID=38
SITH_PRODUCT_REFOUND_ID=5

# Counter

SITH_COUNTER_ACCOUNT_DUMP_ID=39

# Defines which product type is the refilling type, and thus increases the account amount
SITH_COUNTER_PRODUCTTYPE_REFILLING=3

SITH_ECOCUP_CONS=1152
SITH_ECOCUP_DECO=1151

# Defines which product is the one year subscription and which one is the six month subscription
SITH_PRODUCT_SUBSCRIPTION_ONE_SEMESTER=1
SITH_PRODUCT_SUBSCRIPTION_TWO_SEMESTERS=2
SITH_PRODUCTTYPE_SUBSCRIPTION=2

# Defines which clubs let its members the ability to see users subscription history
SITH_CAN_CREATE_SUBSCRIPTION_HISTORY=1
SITH_CAN_READ_SUBSCRIPTION_HISTORY=1

# SAS variables
SITH_SAS_ROOT_DIR_ID=4

# ET variables
SITH_EBOUTIC_CB_ENABLED=true
SITH_EBOUTIC_ET_URL="https://preprod-tpeweb.e-transactions.fr/cgi/MYchoix_pagepaiement.cgi"
SITH_EBOUTIC_PBX_SITE=1999888
SITH_EBOUTIC_PBX_RANG=32
SITH_EBOUTIC_PBX_IDENTIFIANT=2
SITH_EBOUTIC_HMAC_KEY=0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
SITH_EBOUTIC_PUB_KEY_PATH=sith/et_keys/pubkey.pem

SITH_MAILING_FETCH_KEY=IloveMails
SENTRY_DSN=
SENTRY_ENV=production
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
branches: [master, taiste]
workflow_dispatch:

env:
SECRET_KEY: notTheRealOne
DATABASE_URL: sqlite:///db.sqlite3

jobs:
pre-commit:
name: Launch pre-commits checks (ruff)
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ node_modules/

# compiled documentation
site/
.env
3 changes: 2 additions & 1 deletion core/management/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.conf import settings
from django.core.management import call_command
from django.core.management.base import BaseCommand
from django.db import connection


class Command(BaseCommand):
Expand All @@ -29,7 +30,7 @@ def handle(self, *args, **options):
if not data_dir.is_dir():
data_dir.mkdir()
db_path = settings.BASE_DIR / "db.sqlite3"
if db_path.exists():
if db_path.exists() or connection.vendor != "sqlite":
call_command("flush", "--noinput")
self.stdout.write("Existing database reset")
call_command("migrate")
Expand Down
36 changes: 36 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
services:
db:
image: postgres:16.6
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
ports:
- "5431:5432"
environment:
POSTGRES_USER: sith
POSTGRES_PASSWORD: sith
POSTGRES_DB: sith

redis:
image: redis:latest
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
ports:
- "6378:6379"
command: redis-server
volumes:
- redis_data:/var/lib/redis/data/

volumes:
postgres_data:
driver: local
redis_data:
driver: local

4 changes: 2 additions & 2 deletions docs/howto/prod.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

Pour connecter l'application à une instance de sentry (ex: https://sentry.io),
il est nécessaire de configurer la variable `SENTRY_DSN`
dans le fichier `settings_custom.py`.
dans le fichier `.env`.
Cette variable est composée d'un lien complet vers votre projet sentry.

## Récupérer les statiques

Nous utilisons du SCSS dans le projet.
En environnement de développement (`DEBUG=True`),
En environnement de développement (`DEBUG=true`),
le SCSS est compilé à chaque fois que le fichier est demandé.
Pour la production, le projet considère
que chacun des fichiers est déjà compilé.
Expand Down
59 changes: 12 additions & 47 deletions docs/tutorial/install-advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ Commencez par installer les dépendances système :
=== "Debian/Ubuntu"

```bash
sudo apt install postgresql redis libq-dev nginx
sudo apt install postgresql libq-dev nginx
```

=== "Arch Linux"

```bash
sudo pacman -S postgresql redis nginx
sudo pacman -S postgresql nginx
```

=== "macOS"

```bash
brew install postgresql redis lipbq nginx
brew install postgresql lipbq nginx
export PATH="/usr/local/opt/libpq/bin:$PATH"
source ~/.zshrc
```
Expand All @@ -77,34 +77,6 @@ uv sync --group prod
C'est parce que ces dépendances compilent certains modules
à l'installation.

## Configurer Redis

Redis est utilisé comme cache.
Assurez-vous qu'il tourne :

```bash
sudo systemctl redis status
```

Et s'il ne tourne pas, démarrez-le :

```bash
sudo systemctl start redis
sudo systemctl enable redis # si vous voulez que redis démarre automatiquement au boot
```

Puis ajoutez le code suivant à la fin de votre fichier
`settings_custom.py` :

```python
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": "redis://127.0.0.1:6379",
}
}
```

## Configurer PostgreSQL

PostgreSQL est utilisé comme base de données.
Expand Down Expand Up @@ -139,26 +111,19 @@ en étant connecté en tant que postgres :
psql -d sith -c "GRANT ALL PRIVILEGES ON SCHEMA public to sith";
```

Puis ajoutez le code suivant à la fin de votre
`settings_custom.py` :

```python
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "sith",
"USER": "sith",
"PASSWORD": "password",
"HOST": "localhost",
"PORT": "", # laissez ce champ vide pour que le choix du port soit automatique
}
}
Puis modifiez votre `.env`.
Dedans, décommentez l'url de la base de données
de postgres et commentez l'url de sqlite :

```dotenv
#DATABASE_URL=sqlite:///db.sqlite3
DATABASE_URL=postgres://sith:password@localhost:5432/sith
```

Enfin, créez vos données :

```bash
uv run ./manage.py populate
uv run ./manage.py setup
```

!!! note
Expand Down Expand Up @@ -247,7 +212,7 @@ Puis lancez ou relancez nginx :
sudo systemctl restart nginx
```

Dans votre `settings_custom.py`, remplacez `DEBUG=True` par `DEBUG=False`.
Dans votre `.env`, remplacez `DEBUG=true` par `DEBUG=false`.

Enfin, démarrez le serveur Django :

Expand Down
Loading
Loading