Skip to content

Commit

Permalink
allow redis and postgres to run in docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
imperosol committed Dec 1, 2024
1 parent b3eb769 commit 795d0f2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
22 changes: 13 additions & 9 deletions core/management/commands/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def reset_index(self, *args):
# sqlite doesn't support this operation
return
sqlcmd = StringIO()
call_command("sqlsequencereset", *args, stdout=sqlcmd)
call_command("sqlsequencereset", "--no-color", *args, stdout=sqlcmd)
cursor = connection.cursor()
cursor.execute(sqlcmd.getvalue())

Expand Down Expand Up @@ -137,16 +137,20 @@ def handle(self, *args, **options):
)

self.reset_index("club")
counters = [
*[
Counter.objects.bulk_create(
[
Counter(id=bar_id, name=bar_name, club=bar_club, type="BAR")
for bar_id, bar_name in settings.SITH_COUNTER_BARS
],
Counter(name="Eboutic", club=main_club, type="EBOUTIC"),
Counter(name="AE", club=main_club, type="OFFICE"),
Counter(name="Vidage comptes AE", club=main_club, type="OFFICE"),
]
Counter.objects.bulk_create(counters)
]
)
self.reset_index("counter")
Counter.objects.bulk_create(
[
Counter(name="Eboutic", club=main_club, type="EBOUTIC"),
Counter(name="AE", club=main_club, type="OFFICE"),
Counter(name="Vidage comptes AE", club=main_club, type="OFFICE"),
]
)
bar_groups = []
for bar_id, bar_name in settings.SITH_COUNTER_BARS:
group = RealGroup.objects.create(name=f"{bar_name} admin")
Expand Down
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

0 comments on commit 795d0f2

Please sign in to comment.