Skip to content

Working dockerized django project #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env.db
.env.web
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.7.7

WORKDIR /app

COPY requirements.txt /app/

RUN pip install -r requirements.txt

COPY . .

RUN chmod +x script.sh


3 changes: 3 additions & 0 deletions db/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM mysql:latest

COPY ./world.sql /docker-entrypoint-initdb.d/
File renamed without changes.
44 changes: 44 additions & 0 deletions docker-compose-pull.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: '3.8'
services:

db:
image: maneav78/mysqldb:latest
env_file:
- .env.db
ports:
- "$PORT:3306"
environment:
MYSQL_ROOT_PASSWORD: $PASSWORD
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10
volumes:
- db_data:/var/lib/mysql
networks:
- my_network

djangoapp:
image: maneav78/djangoapp:latest
command: /bin/bash -c "./script.sh"
depends_on:
db:
condition: service_healthy
networks:
- my_network
ports:
- "8001:8001"
env_file:
- .env.db
environment:
DATABASE_NAME: "world"
DATABASE_USER: $USER
DATABASE_PASSWORD: $PASSWORD
DATABASE_HOST: $HOST
DATABASE_PORT: $PORT

networks:
my_network:

volumes:
db_data:
45 changes: 45 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: '3.8'
services:

db:
build: ./db
container_name: mysqldbcont
env_file:
- .env.db
ports:
- "$PORT:3306"
environment:
MYSQL_ROOT_PASSWORD: $PASSWORD
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10
volumes:
- db_data:/var/lib/mysql
networks:
- my_network

djangoapp:
build: .
command: /bin/bash -c "./script.sh"
depends_on:
db:
condition: service_healthy
networks:
- my_network
ports:
- "8001:8001"
env_file:
- .env.db
environment:
DATABASE_NAME: "world"
DATABASE_USER: $USER
DATABASE_PASSWORD: $PASSWORD
DATABASE_HOST: $HOST
DATABASE_PORT: $PORT

networks:
my_network:

volumes:
db_data:
23 changes: 13 additions & 10 deletions panorbit/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

import os
from dotenv import load_dotenv

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand All @@ -25,7 +26,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["c9ae666b.ngrok.io", "localhost"]
ALLOWED_HOSTS = ["c9ae666b.ngrok.io", "localhost", "0.0.0.0"]


# Application definition
Expand Down Expand Up @@ -83,14 +84,16 @@
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

load_dotenv(dotenv_path='.env.web')

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'world',
'USER': 'root',
'PASSWORD': 'xxxx',
'HOST': 'localhost',
'PORT': '3306',
'USER': os.getenv('USER'),
'PASSWORD': os.getenv('PASSWORD'),
'HOST': os.getenv('HOST'),
'PORT': os.getenv('PORT'),
}
}

Expand Down Expand Up @@ -142,9 +145,9 @@
LOGIN_URL = 'signup'

# email configurations
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'xxxx'
EMAIL_HOST_PASSWORD = 'xxxx'
EMAIL_PORT = 587
EMAIL_USE_TLS = os.getenv('EMAIL_USE_TLS')
EMAIL_HOST = os.getenv('EMAIL_HOST')
EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD')
EMAIL_PORT = os.getenv('EMAIL_PORT')

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ six==1.11.0
urllib3==1.24.2
Whoosh==2.7.4
xlrd==1.2.0
python-dotenv==0.19.1
6 changes: 6 additions & 0 deletions script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

python manage.py makemigrations --noinput
python manage.py migrate --noinput

python manage.py runserver 0.0.0.0:8001
2 changes: 1 addition & 1 deletion world/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Meta:
unique_together = (('countrycode', 'language'),)

def __unicode__(self):
return ("country-code: %s language: %s") %(self.countrycode.name, self.language)
return ("country-code: %s language: %s") %(self.countrycode.name, self.language)

class DjangoMigrations(models.Model):
app = models.CharField(max_length=255)
Expand Down