Skip to content

Commit

Permalink
Merge pull request #16 from SmartWasteSegregatorAndRoutePlanner/docke…
Browse files Browse the repository at this point in the history
…rize-project

Dockerize project
  • Loading branch information
dmdhrumilmistry committed Feb 4, 2023
2 parents f1809a2 + 2f0beb6 commit 2a8ae4d
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 8 deletions.
216 changes: 216 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
### Django ###
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
db.sqlite3-journal
media

# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
# <django-project-name>/staticfiles/
*staticfiles*
### Django.Python Stack ###
# Byte-compiled / optimized / DLL files
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo

# Django stuff:

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

### Python ###
# Byte-compiled / optimized / DLL files

# C extensions

# Distribution / packaging

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.

# Installer logs

# Unit test / coverage reports

# Translations

# Django stuff:

# Flask stuff:

# Scrapy stuff:

# Sphinx documentation

# PyBuilder

# Jupyter Notebook

# IPython

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.

# PEP 582; used by e.g. github.com/David-OConnor/pyflow

# Celery stuff

# SageMath parsed files

# Environments

# Spyder project settings

# Rope project settings

# mkdocs documentation

# mypy

# Pyre type checker

# pytype static type analyzer

# Cython debug symbols

# custom files
*.sqlite3
.git
.vscode
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,4 @@ poetry.toml
*migrations*
*temp*
*cache*
staticfiles
71 changes: 71 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# DESCRIPTION: Deploys Backend-APIs repo in Container
# AUTHOR: Dhrumil Mistry <contact@dmdhrumilmistry.tech>
# COMMENTS:
# This file describes how to deploy Backend-APIs
# in a container with all dependencies installed.
# USAGE:
# # Download googlephish Dockerfile
# wget [link]
#
# # Build image
# docker build -t swsrp-backend-api .
#
# # run docker container
# docker run -d -p 8000:8000 swsrp-backend-api
#

# choose baseimage
FROM python:3.10

# set initial Working Directory
WORKDIR /

# create project directory and set as workding directory
ENV PROJ_DIR="/Backend-APIs"
RUN [ -d ${PROJ_DIR} ] || mkdir -p ${PROJ_DIR}
WORKDIR ${PROJ_DIR}

# copy project files
COPY . .

# add current directory to python path
ENV PYTHONPATH=${PYTHONPATH}:${PWD}

# install requirements
RUN python -m pip install gunicorn
RUN python -m pip install poetry
RUN poetry config virtualenvs.create false
RUN poetry install --no-root --only main

# check for errors in application
RUN python manage.py check

# migrate database
RUN python manage.py makemigrations
RUN python manage.py migrate
# --run-syncdb creates table without migrations
RUN python manage.py migrate --run-syncdb

# collect static images
RUN python manage.py collectstatic

# get build arguments (credentials)
ARG dj_email=admin@localhost
ARG dj_username=admin
ARG dj_password=admin
ARG dj_allowed_host=*
ARG dj_debug=false

# create superuser
ENV DJANGO_SUPERUSER_EMAIL=${dj_email}
ENV DJANGO_SUPERUSER_USERNAME=${dj_username}
ENV DJANGO_SUPERUSER_PASSWORD=${dj_password}
ENV ALLOWED_HOSTS=${dj_allowed_host}
ENV DEBUG=${dj_debug}
RUN python manage.py createsuperuser --noinput

# expose ports
EXPOSE 8000

# start application
CMD [ "gunicorn", "backend_api.wsgi", "-b", "0.0.0.0:8000" ]
13 changes: 7 additions & 6 deletions backend_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""

from pathlib import Path
from django.core.management.utils import get_random_secret_key
from dotenv import load_dotenv, find_dotenv
from pathlib import Path
from os import environ
from os.path import join as path_join

Expand All @@ -26,13 +26,12 @@
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = environ.get('DJANGO_SECRET_KEY', None)
SECRET_KEY = environ.get('DJANGO_SECRET_KEY', get_random_secret_key())

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
DEBUG = environ.get('DEBUG', False)

ALLOWED_HOSTS = environ.get('ALLOWED_HOSTS', 'localhost 127.0.0.1').split(' ')

# Application definition

Expand All @@ -51,6 +50,7 @@

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand Down Expand Up @@ -125,6 +125,7 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/

STATIC_ROOT = BASE_DIR / "staticfiles"
STATIC_URL = 'static/'

# Default primary key field type
Expand Down
6 changes: 6 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
swsrp-backend:
image: dmdhrumilmistry/swsrp-backend-api
ports:
- 8000:8000

24 changes: 23 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ osmnx = "^1.3.0"
scikit-learn = "^1.2.1"
dj-rest-auth = "^2.2.7"
djangorestframework-simplejwt = "^5.2.2"
whitenoise = "^6.3.0"


[build-system]
Expand Down
Loading

0 comments on commit 2a8ae4d

Please sign in to comment.