Skip to content

Commit de4528e

Browse files
committed
http deployment using docker done
1 parent 8699970 commit de4528e

10 files changed

+75
-2
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.github
22
venv
33
logs
4+
celerybeat-schedule

.env

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ EMAIL_PORT=2525
1010
EMAIL_USER='6961971ab353c6'
1111
EMAIL_PASSWORD='0b78caeeae6e9c'
1212
REDIS_LOCATION='redis://localhost:6379'
13+
ALLOWED_HOSTS='http://localhost.com, https://django.tejasureddy.com'
1314

1415
# docker
1516
POSTGRES_HOST='postgres'

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ __pycache__
44
assets/*
55
!assets/public/
66
logs
7+
celerybeat-schedule

Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ RUN pip install --no-cache-dir -r requirements.txt
1313

1414
# Copy the rest of the application code
1515
COPY . /app/
16+
17+
RUN mkdir /app/logs
18+
RUN touch /app/logs/django.log

docker-compose.prod.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
version: '3'
2+
3+
services:
4+
postgres:
5+
image: postgres
6+
restart: always
7+
env_file:
8+
- .env
9+
10+
redis:
11+
image: redis
12+
ports:
13+
- "6379:6379"
14+
restart: always
15+
16+
django:
17+
build:
18+
context: .
19+
dockerfile: Dockerfile
20+
command: >
21+
sh -c "python manage.py migrate && gunicorn my_project.wsgi:application --bind 0.0.0.0:8000 && celery -A my_project worker -l info -P gevent && celery -A my_project beat -l info"
22+
expose:
23+
- 8000
24+
volumes:
25+
- static_volume:/app/static/
26+
env_file:
27+
- .env
28+
depends_on:
29+
- postgres
30+
- redis
31+
32+
nginx:
33+
build: ./nginx
34+
ports:
35+
- 80:80
36+
volumes:
37+
- static_volume:/app/static/
38+
depends_on:
39+
- django
40+
41+
volumes:
42+
static_volume:

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ services:
1818
context: .
1919
dockerfile: Dockerfile
2020
command: >
21-
sh -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000 & celery -A my_project worker -l info -P gevent & celery -A my_project beat -l info"
21+
sh -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000 && celery -A my_project worker -l info -P gevent && celery -A my_project beat -l info"
2222
ports:
2323
- "8000:8000"
2424
volumes:

my_project/settings.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
# SECURITY WARNING: don't run with debug turned on in production!
3232
DEBUG = env.bool("DEBUG", False)
3333

34-
ALLOWED_HOSTS = []
34+
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS")
35+
36+
CSRF_TRUSTED_ORIGINS = env.list("ALLOWED_HOSTS")
3537

3638
INTERNAL_IPS = ["127.0.0.1"]
3739

nginx/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM nginx:1.25
2+
RUN rm /etc/nginx/conf.d/default.conf
3+
COPY nginx.conf /etc/nginx/conf.d

nginx/nginx.conf

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
upstream my_project {
2+
server django:8000;
3+
}
4+
5+
server {
6+
listen 80;
7+
8+
location / {
9+
proxy_pass http://my_project;
10+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
11+
proxy_set_header Host $host;
12+
proxy_redirect off;
13+
}
14+
15+
location /static/ {
16+
alias /app/static/;
17+
}
18+
}

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ ruff==0.3.5 # linter and code formatter
2929
coverage==7.4.4 # code coverage testing
3030
djlint==1.34.1 # html template linter and formatter
3131
django-csp==3.8 # security - which resources can be loaded on a web page
32+
gunicorn==21.2.0 # for deployment
33+
psycopg2-binary==2.9.6 # for postgres

0 commit comments

Comments
 (0)