Skip to content

Commit

Permalink
Fix Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
sl.ars committed Feb 27, 2025
1 parent 8cce164 commit e29b7de
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 26 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ ENV PYTHONUNBUFFERED 1
# Run entrypoint script
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"]
ENTRYPOINT ["/app/entrypoint.sh"]

31 changes: 19 additions & 12 deletions Dockerfile.frontend
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
# Use Node.js base image
FROM node:20

# Set working directory
FROM node:22 AS builder

WORKDIR /app

# Copy package files

COPY frontend/package.json frontend/package-lock.json ./
RUN npm install --frozen-lockfile

# Install dependencies
RUN npm install

# Copy app source
COPY frontend ./

# Build frontend
RUN npm run build

# Expose port
EXPOSE 5173

# Start server
CMD ["npm", "run", "preview"]
FROM nginx:latest AS production

WORKDIR /app


RUN rm -rf /usr/share/nginx/html/*
RUN rm -rf /app/frontend/*

COPY --from=builder /app/dist /app/frontend


COPY nginx/nginx.conf /etc/nginx/nginx.conf

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ services:
dockerfile: Dockerfile.frontend
container_name: trading_frontend
restart: always
volumes:
- .:/app
depends_on:
- backend
ports:
Expand Down Expand Up @@ -75,6 +77,9 @@ services:
- frontend
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./frontend/dist:/app/frontend/
- ./staticfiles:/app/staticfiles/
- ./media:/app/media
ports:
- "80:80"

Expand Down
19 changes: 14 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
#!/bin/sh

echo "Waiting for PostgreSQL to start..."
while ! nc -z db 5432; do
while ! timeout 1 bash -c 'cat < /dev/null > /dev/tcp/db/5432'; do
sleep 1
done
echo "PostgreSQL started."

# Collect static files
poetry run python manage.py collectstatic --noinput

# Run migrations
poetry run python manage.py migrate --noinput

# Collect static files
poetry run python manage.py collectstatic --noinput

# Start Gunicorn server
exec poetry run gunicorn trading_app.wsgi:application --bind 0.0.0.0:8000

# Start Daphne in the background
echo "Starting Daphne..."
poetry run daphne -b 0.0.0.0 -p 8001 trading_app.asgi:application &

# Start Gunicorn in the foreground
echo "Starting Gunicorn..."
exec poetry run gunicorn trading_app.wsgi:application --bind 0.0.0.0:8000


58 changes: 53 additions & 5 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,21 +1,69 @@
events {}

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

server {
listen 80;
server_name _;


location / {
root /app/frontend;
index index.html;
try_files $uri /index.html;
}


location /api/ {
proxy_pass http://backend:8000/;
proxy_pass http://backend:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location / {
root /app/frontend/build;
index index.html;
try_files $uri /index.html;
location /admin/ {
proxy_pass http://backend:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /static/ {
alias /app/staticfiles/;
autoindex on;
}

location /media/ {
alias /app/media;
autoindex on;
}


# WebSocket support (Django Channels)
location /ws/ {
proxy_pass http://backend:8001/ws/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}


location /swagger/ {
proxy_pass http://backend:8000/swagger/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ dependencies = [
"celery (>=5.4.0,<6.0.0)",
"redis (>=5.2.1,<6.0.0)",
"sentry-sdk (>=2.22.0,<3.0.0)",
"reportlab (>=4.3.1,<5.0.0)"
"reportlab (>=4.3.1,<5.0.0)",
"djangorestframework-simplejwt (>=5.5.0,<6.0.0)",
"gunicorn (>=23.0.0,<24.0.0)",
"pdfkit (>=1.0.0,<2.0.0)",
"requests (>=2.32.3,<3.0.0)",
"python-dotenv (>=1.0.1,<2.0.0)",
"django-filter (>=25.1,<26.0)"
]


Expand Down
4 changes: 2 additions & 2 deletions trading_app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [("127.0.0.1", 6379)],
"hosts": [("redis", 6379)],
},
},
}

# === CELERY === #
CELERY_BROKER_URL = "redis://localhost:6379/0"
CELERY_BROKER_URL = "redis://redis:6379/0"
CELERY_ACCEPT_CONTENT = ["json"]
CELERY_TASK_SERIALIZER = "json"

Expand Down

0 comments on commit e29b7de

Please sign in to comment.