diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..32252dd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env.db +.env.web \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..276112f --- /dev/null +++ b/Dockerfile @@ -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 + + diff --git a/db/Dockerfile b/db/Dockerfile new file mode 100644 index 0000000..b5db17d --- /dev/null +++ b/db/Dockerfile @@ -0,0 +1,3 @@ +FROM mysql:latest + +COPY ./world.sql /docker-entrypoint-initdb.d/ diff --git a/world.sql b/db/world.sql similarity index 100% rename from world.sql rename to db/world.sql diff --git a/docker-compose-pull.yaml b/docker-compose-pull.yaml new file mode 100644 index 0000000..f9883b4 --- /dev/null +++ b/docker-compose-pull.yaml @@ -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: \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..b999a14 --- /dev/null +++ b/docker-compose.yaml @@ -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: \ No newline at end of file diff --git a/panorbit/settings.py b/panorbit/settings.py index b28da5a..e943e09 100644 --- a/panorbit/settings.py +++ b/panorbit/settings.py @@ -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__))) @@ -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 @@ -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'), } } @@ -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') diff --git a/requirements.txt b/requirements.txt index 5919144..f5d4690 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file diff --git a/script.sh b/script.sh new file mode 100644 index 0000000..dcbde2d --- /dev/null +++ b/script.sh @@ -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 diff --git a/world/models.py b/world/models.py index 7b14e39..311d8e6 100644 --- a/world/models.py +++ b/world/models.py @@ -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)