Skip to content

Commit e0d509c

Browse files
feat: improve Docker Compose setup and fix Django app loading issues
- Docker Compose: - Ensure Nginx waits for the web service to be ready using wait-for-it.sh. - Update PostgreSQL and Redis images to Alpine versions (postgres:17-alpine, edis:8.0-alpine). - Django Fixes: - Resolve AppRegistryNotReady error by lazy-loading Product model in chat/consumers.py. - Use string literal for TaggableManager in shop/models.py to avoid app registry issues. - API Documentation: - Expose staff_check endpoint in �ccount/urls.py for Swagger UI visibility.
1 parent 92b0d07 commit e0d509c

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

account/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,6 @@
5656
UserViewSet.as_view({'get': 'me', 'put': 'me', 'patch': 'me', 'delete': 'me'}),
5757
name='current_user'
5858
),
59+
path('staff-check/', UserViewSet.as_view({'get': 'staff_check'}), name='staff_check'),
5960
]
61+

chat/consumers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.contrib.auth import get_user_model
66
from django.utils import timezone
77

8-
from shop.models import Product
8+
99
from .models import Message
1010

1111

@@ -40,6 +40,8 @@ async def connect(self):
4040

4141
self.product_id = self.scope['url_route']['kwargs']['product_id']
4242

43+
from shop.models import Product # Import Product here
44+
4345
try:
4446
self.product = await Product.objects.aget(product_id=self.product_id)
4547
except Product.DoesNotExist:

docker-compose.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
database:
3-
image: postgres:17.4
3+
image: postgres:17-alpine
44
container_name: database
55
restart: always
66
ports:
@@ -18,7 +18,7 @@ services:
1818
retries: 5
1919

2020
cache:
21-
image: redis:7.4.2
21+
image: redis:8.0-alpine
2222
container_name: cache
2323
restart: always
2424
ports:
@@ -65,6 +65,9 @@ services:
6565
- .:/code
6666
ports:
6767
- "80:80"
68+
command: [ "/code/wait-for-it.sh", "web:8000", "--", "nginx", "-g", "daemon off;" ]
69+
depends_on:
70+
- web
6871

6972
volumes:
7073
database:

ecommerce_api/asgi.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
from channels.routing import ProtocolTypeRouter, URLRouter
1414
from django.core.asgi import get_asgi_application
1515

16-
from chat.routing import websocket_urlpatterns as chat_ws
17-
from shop.routing import websocket_urlpatterns as search_ws
18-
1916
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ecommerce_api.settings')
2017

2118
django_asgi_application = get_asgi_application()
2219

20+
# Import websocket patterns after Django is initialized
21+
from chat.routing import websocket_urlpatterns as chat_ws
22+
from shop.routing import websocket_urlpatterns as search_ws
23+
2324
websocket_urlpatterns = chat_ws + search_ws
2425

2526
application = ProtocolTypeRouter({

0 commit comments

Comments
 (0)