Skip to content

Commit 0d5d09e

Browse files
committed
feat: Update Dockerfile and docker-compose for Daphne, add presigned URL generation for profile photos, and enhance serializers for profile data
1 parent cc47d86 commit 0d5d09e

19 files changed

Lines changed: 540 additions & 72 deletions

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ COPY . .
1616

1717
RUN python manage.py collectstatic --noinput
1818

19-
CMD ["gunicorn", "mysite.wsgi:application", "--bind", "0.0.0.0:8000"]
19+
CMD ["daphne", "-b", "0.0.0.0", "-p", "8000", "mysite.asgi:application"]

accounts/views/login_view.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,27 @@
44
from rest_framework_simplejwt.tokens import RefreshToken
55
from accounts.throttle.login_throttle import LoginThrottle
66
from accounts.serializers import LoginSerializer
7+
from uploads.services import generate_presigned_view
78

89
class LoginView(APIView):
910
permission_classes = [permissions.AllowAny]
1011
serializer_class = LoginSerializer
1112
throttle_classes = [LoginThrottle]
1213

1314
def post(self, request):
14-
print("Login attempt", request.data)
1515
serializer = LoginSerializer(data=request.data)
16-
print("Validating serializer")
1716
serializer.is_valid(raise_exception=True)
18-
print("Serializer valid")
1917

2018
user = serializer.validated_data["user"]
2119

2220
# Generate JWT tokens
2321
refresh = RefreshToken.for_user(user)
2422

23+
# Get profile photo presigned URL
24+
profile_photo = None
25+
if hasattr(user, 'profile') and user.profile.avatar:
26+
profile_photo = generate_presigned_view(user.profile.avatar)
27+
2528
return Response({
2629
"access": str(refresh.access_token),
2730
"refresh": str(refresh),
@@ -31,5 +34,6 @@ def post(self, request):
3134
"email": user.email,
3235
"first_name": user.first_name,
3336
"last_name": user.last_name,
37+
"profile_photo": profile_photo,
3438
}
3539
}, status=status.HTTP_200_OK)

accounts/views/token_validate_view.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from rest_framework.response import Response
33
from rest_framework import permissions, status
44
from accounts.serializers import TokenValidateSerializer
5+
from uploads.services import generate_presigned_view
56

67

78
class TokenValidateView(APIView):
@@ -22,6 +23,11 @@ def post(self, request):
2223

2324
user = serializer.validated_data["user"]
2425

26+
# Get profile photo presigned URL
27+
profile_photo = None
28+
if hasattr(user, 'profile') and user.profile.avatar:
29+
profile_photo = generate_presigned_view(user.profile.avatar)
30+
2531
return Response(
2632
{
2733
"valid": True,
@@ -31,6 +37,7 @@ def post(self, request):
3137
"email": user.email,
3238
"first_name": user.first_name,
3339
"last_name": user.last_name,
40+
"profile_photo": profile_photo,
3441
},
3542
},
3643
status=status.HTTP_200_OK,

docker-compose.yml

Lines changed: 81 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
sh -c "
88
python manage.py migrate &&
99
python manage.py collectstatic --noinput &&
10-
gunicorn mysite.wsgi:application --bind 0.0.0.0:8000
10+
daphne -b 0.0.0.0 -p 8000 --access-log - --verbosity 1 mysite.asgi:application
1111
"
1212
ports:
1313
- "8000:8000" # ✅ only required exposed port
@@ -26,9 +26,9 @@ services:
2626
- REDIS_HOST=redis
2727

2828
# S3 (MinIO)
29-
- AWS_ACCESS_KEY_ID=minioadmin
30-
- AWS_SECRET_ACCESS_KEY=minioadmin
31-
- AWS_S3_ENDPOINT_URL=http://minio:9000
29+
- AWS_ACCESS_KEY_ID=bizbuch_admin
30+
- AWS_SECRET_ACCESS_KEY=bizbuch_secret_key
31+
- AWS_S3_ENDPOINT_URL=http://172.28.0.13:9000
3232
- AWS_S3_BUCKET=bizbuch
3333
- AWS_DEFAULT_REGION=us-east-1
3434
- AWS_S3_USE_SSL=False
@@ -42,6 +42,9 @@ services:
4242
condition: service_started
4343
minio_init:
4444
condition: service_completed_successfully
45+
networks:
46+
bizbuch_network:
47+
ipv4_address: 172.28.0.10
4548

4649
db:
4750
image: postgres:15
@@ -50,33 +53,60 @@ services:
5053
POSTGRES_DB: bizbuch
5154
POSTGRES_USER: postgres
5255
POSTGRES_PASSWORD: postgres
56+
# Optional: expose Postgres port only if needed for external access
57+
ports:
58+
- "5432:5432"
5359
volumes:
5460
- postgres_data:/var/lib/postgresql/data
5561
healthcheck:
5662
test: ["CMD-SHELL", "pg_isready -U postgres -d bizbuch"]
5763
interval: 5s
5864
timeout: 3s
5965
retries: 20
66+
networks:
67+
bizbuch_network:
68+
ipv4_address: 172.28.0.11
6069

6170
redis:
6271
image: redis:7-alpine
6372
restart: always
73+
# Optional: expose Redis port only if needed for external access
74+
# ports:
75+
# - "6379:6379"
76+
networks:
77+
bizbuch_network:
78+
ipv4_address: 172.28.0.12
79+
80+
redisinsight:
81+
image: redis/redisinsight:latest
82+
container_name: redisinsight
83+
restart: always
84+
ports:
85+
- "5540:5540"
86+
depends_on:
87+
- redis
88+
networks:
89+
bizbuch_network:
90+
ipv4_address: 172.28.0.17
6491

6592
minio:
6693
image: minio/minio:latest
6794
container_name: minio
6895
restart: always
6996
environment:
70-
MINIO_ROOT_USER: minioadmin
71-
MINIO_ROOT_PASSWORD: minioadmin
97+
MINIO_ROOT_USER: bizbuch_admin
98+
MINIO_ROOT_PASSWORD: bizbuch_secret_key
7299
command: server /data --console-address ":9001"
73100
volumes:
74101
- minio_data:/data
75102

76103
# Optional: expose MinIO ports only if needed for UI/debugging
77-
# ports:
78-
# - "9000:9000"
79-
# - "9001:9001"
104+
ports:
105+
- "9000:9000"
106+
- "9001:9001"
107+
networks:
108+
bizbuch_network:
109+
ipv4_address: 172.28.0.13
80110

81111
minio_init:
82112
image: minio/mc:latest
@@ -85,12 +115,53 @@ services:
85115
restart: "no"
86116
entrypoint: >
87117
/bin/sh -c "
88-
until (/usr/bin/mc alias set myminio http://minio:9000 minioadmin minioadmin) do sleep 2; done;
118+
until (/usr/bin/mc alias set myminio http://minio:9000 bizbuch_admin bizbuch_secret_key) do sleep 2; done;
89119
/usr/bin/mc mb -p myminio/bizbuch || true;
90120
/usr/bin/mc anonymous set download myminio/bizbuch || true;
91121
exit 0;
92122
"
123+
networks:
124+
bizbuch_network:
125+
ipv4_address: 172.28.0.14
126+
127+
pgadmin:
128+
image: dpage/pgadmin4:latest
129+
container_name: pgadmin
130+
restart: always
131+
environment:
132+
PGADMIN_DEFAULT_EMAIL: admin@admin.com
133+
PGADMIN_DEFAULT_PASSWORD: admin
134+
PGADMIN_CONFIG_SERVER_MODE: "False"
135+
PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: "False"
136+
ports:
137+
- "5050:80"
138+
volumes:
139+
- ./pgadmin/servers.json:/pgadmin4/servers.json:ro
140+
depends_on:
141+
- db
142+
networks:
143+
bizbuch_network:
144+
ipv4_address: 172.28.0.16
145+
146+
# Uncomment the following section to enable Cloudflare Tunnel
147+
# tunnel:
148+
# image: cloudflare/cloudflared:latest
149+
# command: tunnel --no-autoupdate --url http://web:8000
150+
# restart: always
151+
# depends_on:
152+
# - web
153+
# networks:
154+
# bizbuch_network:
155+
# ipv4_address: 172.28.0.15
93156

94157
volumes:
95158
postgres_data:
96159
minio_data:
160+
161+
networks:
162+
bizbuch_network:
163+
driver: bridge
164+
ipam:
165+
config:
166+
- subnet: 172.28.0.0/16
167+
gateway: 172.28.0.1

0 commit comments

Comments
 (0)