Skip to content

Commit e8b4dd0

Browse files
committed
setup project with docker
1 parent 254cbb3 commit e8b4dd0

11 files changed

+387
-0
lines changed

.gitignore

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
62+
# Flask stuff:
63+
instance/
64+
.webassets-cache
65+
66+
# Scrapy stuff:
67+
.scrapy
68+
69+
# Sphinx documentation
70+
docs/_build/
71+
72+
# PyBuilder
73+
target/
74+
75+
# Jupyter Notebook
76+
.ipynb_checkpoints
77+
78+
# IPython
79+
profile_default/
80+
ipython_config.py
81+
82+
# pyenv
83+
.python-version
84+
85+
# pipenv
86+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
87+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
88+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
89+
# install all needed dependencies.
90+
#Pipfile.lock
91+
92+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
93+
__pypackages__/
94+
/__pypackages__
95+
# Celery stuff
96+
celerybeat-schedule
97+
celerybeat.pid
98+
99+
# SageMath parsed files
100+
*.sage.py
101+
102+
# Environments
103+
.venv
104+
env/
105+
venv/
106+
ENV/
107+
env.bak/
108+
venv.bak/
109+
110+
# Spyder project settings
111+
.spyderproject
112+
.spyproject
113+
114+
# Rope project settings
115+
.ropeproject
116+
117+
# mkdocs documentation
118+
/site
119+
120+
# mypy
121+
.mypy_cache/
122+
.dmypy.json
123+
dmypy.json
124+
125+
# Pyre type checker
126+
.pyre/
127+
db.sqlite3

Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM python:3
2+
ENV PYTHONUNBUFFERED TRUE
3+
COPY . .
4+
RUN pip3 install -r requirements.txt

docker-compose.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: '3'
2+
3+
services:
4+
django:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
image: django_img
9+
container_name: django_img
10+
volumes:
11+
- .:/app
12+
command: python3 manage.py runserver 0.0.0.0:8000
13+
ports:
14+
- "8000:8000"

docker_practice/__init__.py

Whitespace-only changes.

docker_practice/asgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for docker_practice project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'docker_practice.settings')
15+
16+
application = get_asgi_application()

docker_practice/home.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from rest_framework import views, status
2+
from rest_framework.response import Response
3+
4+
5+
class HomePage(views.APIView):
6+
7+
def get(self, request, *args, **kwargs):
8+
return Response(data={"Home":"Hello world"}, status=status.HTTP_200_OK)

docker_practice/settings.py

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
"""
2+
Django settings for docker_practice project.
3+
4+
Generated by 'django-admin startproject' using Django 3.1.4.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/3.1/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
15+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16+
BASE_DIR = Path(__file__).resolve().parent.parent
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = 't8p$t&zx*x4zx!k_lqk-l)aihfq2qnm8%=dq)srhwnrjpi437r'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
'django.contrib.admin',
35+
'django.contrib.auth',
36+
'django.contrib.contenttypes',
37+
'django.contrib.sessions',
38+
'django.contrib.messages',
39+
'django.contrib.staticfiles',
40+
41+
"rest_framework",
42+
"rest_framework.authtoken",
43+
"django_filters",
44+
"rest_framework_simplejwt",
45+
'rest_framework_simplejwt.token_blacklist',
46+
"corsheaders",
47+
]
48+
49+
REST_FRAMEWORK = {
50+
"DEFAULT_AUTHENTICATION_CLASSES": [
51+
# "rest_framework.authentication.SessionAuthentication",
52+
'rest_framework_simplejwt.authentication.JWTAuthentication'
53+
],
54+
"DEFAULT_PERMISSION_CLASSES": [
55+
"rest_framework.permissions.AllowAny",
56+
],
57+
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
58+
'PAGE_SIZE': 100
59+
}
60+
61+
MIDDLEWARE = [
62+
'django.middleware.security.SecurityMiddleware',
63+
'django.contrib.sessions.middleware.SessionMiddleware',
64+
"corsheaders.middleware.CorsMiddleware",
65+
'django.middleware.common.CommonMiddleware',
66+
'django.middleware.csrf.CsrfViewMiddleware',
67+
'django.contrib.auth.middleware.AuthenticationMiddleware',
68+
'django.contrib.messages.middleware.MessageMiddleware',
69+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
70+
]
71+
72+
ROOT_URLCONF = 'docker_practice.urls'
73+
74+
TEMPLATES = [
75+
{
76+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
77+
'DIRS': [],
78+
'APP_DIRS': True,
79+
'OPTIONS': {
80+
'context_processors': [
81+
'django.template.context_processors.debug',
82+
'django.template.context_processors.request',
83+
'django.contrib.auth.context_processors.auth',
84+
'django.contrib.messages.context_processors.messages',
85+
],
86+
},
87+
},
88+
]
89+
90+
WSGI_APPLICATION = 'docker_practice.wsgi.application'
91+
92+
93+
# Database
94+
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
95+
96+
DATABASES = {
97+
'default': {
98+
'ENGINE': 'django.db.backends.sqlite3',
99+
'NAME': BASE_DIR / 'db.sqlite3',
100+
}
101+
}
102+
103+
104+
# Password validation
105+
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
106+
107+
AUTH_PASSWORD_VALIDATORS = [
108+
{
109+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
110+
},
111+
{
112+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
113+
},
114+
{
115+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
116+
},
117+
{
118+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
119+
},
120+
]
121+
122+
123+
# Internationalization
124+
# https://docs.djangoproject.com/en/3.1/topics/i18n/
125+
126+
LANGUAGE_CODE = 'en-us'
127+
128+
TIME_ZONE = 'Asia/Kolkata'
129+
130+
USE_I18N = True
131+
132+
USE_L10N = True
133+
134+
USE_TZ = True
135+
136+
137+
# Static files (CSS, JavaScript, Images)
138+
# https://docs.djangoproject.com/en/3.1/howto/static-files/
139+
140+
STATIC_URL = '/static/'
141+
142+
CORS_ORIGIN_ALLOW_ALL = True #Nullify CORS headers issue

docker_practice/urls.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""docker_practice URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/3.1/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: path('', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.urls import include, path
14+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15+
"""
16+
from django.contrib import admin
17+
from django.urls import path
18+
19+
from docker_practice.home import HomePage
20+
21+
urlpatterns = [
22+
path('admin/', admin.site.urls),
23+
path('', HomePage.as_view(), name="home"),
24+
]

docker_practice/wsgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for docker_practice project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'docker_practice.settings')
15+
16+
application = get_wsgi_application()

manage.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'docker_practice.settings')
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == '__main__':
22+
main()

0 commit comments

Comments
 (0)