Skip to content

Commit

Permalink
Merge pull request #44 from Satyam0204/master
Browse files Browse the repository at this point in the history
[UPDATE] Deploy Using Docker
  • Loading branch information
mayankt18 authored Jun 11, 2023
2 parents 4576770 + 61fdc96 commit 65093c3
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 13 deletions.
27 changes: 15 additions & 12 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
SECRET_KEY=djangosecretkey
CLIENT_ID=407408718192.apps.googleusercontent.com
APP_ID=facebookoauthid
APP_SECRET=facebookoauthsecret
DOWNLOAD=passwordtodownloadleaderboard
DB_NAME=df
DB_USER=blahaja
DB_PASSWORD=notmypass
DB_HOST=localhost
DB_PORT=5432
DEBUG=True
GOOGLE_MAPS_API_KEY=
SECRET_KEY=
CLIENT_ID=
APP_ID=
APP_SECRET=
DOWNLOAD=
DB_NAME=
DB_USER=
DB_PASSWORD=
DB_HOST=
DB_PORT=
DEBUG=
GOOGLE_MAPS_API_KEY=
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_DB=
2 changes: 1 addition & 1 deletion Digital_Fortress_Backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
'NAME': config('DB_NAME'),
'USER': config('DB_USER'),
'PASSWORD': config('DB_PASSWORD'),
'HOST': 'localhost',
'HOST': config('DB_HOST'),
'PORT': '',
}
}
Expand Down
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.7-slim-buster

RUN pip install --upgrade pip

COPY ./requirements.txt .
RUN pip install -r requirements.txt

COPY . .

# WORKDIR /app

ENTRYPOINT [ "sh", "entrypoint.sh" ]
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,49 @@ This is the backend repository built on Django framework and utilises Django Res
2. Then, apply the migrations using `python manange.py migrate`
3. Run the server using `python manage.py runserver --settings=Digital_Fortress_Backend.dev_settings`


## How to deploy

### Build the docker containers

1. Clone the project

```bash
git clone https://github.com/lugnitdgp/Digital_Fortress_Backend.git
```

2. Install docker



3. Set-up environment variables

```bash
cp .env.example .env
```

4. Spin-up the docker conatainers

```bash
sudo docker-compose up -d --build
```
5. Create admin

```bash
sudo docker exec -it [django_container_name] python manage.py createsuperuser
```

### Stopping the conatainers

```bash
sudo docker-compose stop
```

### Removing the volumes and the container
```bash
sudo docker-compose down -v
```

### Status Codes:

200 : Success
Expand Down
35 changes: 35 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3.8'

services:
django_gunicorn:
volumes:
- static:/static
env_file:
- .env
build:
context: .
ports:
- "8000:8000"
depends_on:
- db

db:
image: postgres:13.0-alpine
volumes:
- db_data:/var/lib/postgresql/data/
env_file:
- .env

nginx:
build: ./nginx
volumes:
- static:/static
ports:
- "80:80"
depends_on:
- db
- django_gunicorn

volumes:
db_data:
static:
7 changes: 7 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

python manage.py makemigrations --no-input
python manage.py migrate --no-input
python manage.py collectstatic --no-input

gunicorn Digital_Fortress_Backend.wsgi:application --bind 0.0.0.0:8000
3 changes: 3 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM nginx:1.19.0-alpine

COPY ./default.conf /etc/nginx/conf.d/default.conf
20 changes: 20 additions & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
upstream django_gunicorn {
server django_gunicorn:8000;
}

server {
listen 80;
server_name dfapi.nitdgplug.org;

location /static/ {
alias /static/;
}
location / {
proxy_set_header Host $http_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;
proxy_pass http://django_gunicorn;
}

}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ six==1.12.0
sqlparse==0.3.0
toml==0.10.0
urllib3==1.25.3
gunicorn==20.0.4

0 comments on commit 65093c3

Please sign in to comment.