Sign inSign up

citywiretech/django-svelte-stack

By citywiretech

•Updated over 2 years ago

Django Rest Framework, Node, NJINX and Supervisor

Image
Web servers
1

247

citywiretech/django-svelte-stack repository overview

⁠Django Restframework API with A Sveltekit Frontend

⁠Using NGINX as a reverse proxy orchestrated with Supervisord

Example script docker script:

FROM citywiretech/django-svelte-stack:latest 

# Required for building the frontend or else it will run out of memory
ENV NODE_OPTIONS=--max_old_space_size=4096

# ========================================
# SETUP 
# ========================================
RUN mkdir -p /app/frontend
RUN mkdir -p /app/backend

# ========================================
# FRONTEND
# ========================================
WORKDIR /app/frontend
COPY frontend/package.json /app/frontend/package.json
RUN npm install 
COPY frontend/ /app/frontend
RUN npm run build

# ========================================
# BACKEND 
# ========================================
WORKDIR /app/backend
COPY backend/ /app/backend
RUN python manage.py collectstatic --noinput --clear

# ========================================
# NGINX & SUPERVISORD
# ========================================
RUN rm /etc/nginx/sites-enabled/default || true
COPY ./server_configs/nginx/default.conf /etc/nginx/conf.d/default.conf
COPY server_configs/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# ========================================
# POST SETUP 
# ========================================
EXPOSE 80
WORKDIR /app

# ========================================
# STARTUP
# ========================================
CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

Here is an example of the nginx config:

server {
    listen 80;

    location / {
        proxy_pass http://127.0.0.1:5000; 
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /api/ {
        proxy_pass http://127.0.0.1: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;
    }

    location /static/ {
        alias /app/backend/static_files/;
    }
}

and an example of the supervisord.conf

[supervisord]
nodaemon=true

[program:migrate]
priority=1
user=root
command=python manage.py migrate --noinput
directory=/app/backend
autostart=true
autorestart=false
redirect_stderr=true
stdout_logfile=/var/log/migrate_stdout.log
stderr_logfile=/var/log/migrate_stderr.log

[program:gunicorn]
priority=2
user=root
command=gunicorn api.wsgi:application --bind 127.0.0.1:8000 --workers 3 
directory=/app/backend
autostart=true
autorestart=true
redirect_stderr=true

[program:pm2]
priority=3
user=root
command=pm2-runtime start --name SonnetCMS npm -- run production
directory=/app/frontend
autostart=true
autorestart=true
redirect_stderr=true

[program:nginx]
priority=4
command=nginx -g "daemon off;"
user=root
autorestart=true
stdout_logfile=/var/log/nginx/nginx_stdout.log
stderr_logfile=/var/log/nginx/nginx_stderr.log
redirect_stderr=true

Tag summary

Content type

Image

Digest

sha256:683020701…

Size

351.1 MB

Last updated

over 2 years ago

docker pull citywiretech/django-svelte-stack