Skip to content

Commit 04c2c03

Browse files
committed
Initial commit
0 parents  commit 04c2c03

File tree

230 files changed

+69416
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+69416
-0
lines changed

.env

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
SECRET_KEY=a38d5044-e78a-416e-9bde-8aeabc598286
2+
3+
DEBUG=0
4+
5+
ALLOWED_HOSTS=*
6+
#CSRF_TRUSTED_ORIGINS="http://127.0.0.1"
7+
8+
POSTGRES_ENGINE=django.db.backends.postgresql
9+
POSTGRES_DB=django_db
10+
POSTGRES_USER=admin
11+
POSTGRES_PASSWORD=password
12+
POSTGRES_HOST=postgres
13+
POSTGRES_PORT=5432
14+
DATABASE=postgres
15+
16+
RMQ_HOST=rmq
17+
RMQ_PORT=5672
18+
RMQ_USER=admin
19+
RMQ_PASS=admin

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Misc
2+
venv
3+
nohup.out
4+
*.log
5+
.DS_Store
6+
7+
# Django
8+
db.sqlite3
9+
__pycache__

Dockerfile.django

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM python:3.11-alpine
2+
3+
WORKDIR /usr/src/app
4+
RUN mkdir -p $WORKDIR/static
5+
RUN mkdir -p $WORKDIR/media
6+
7+
ENV PYTHONDONTWRITEBYTECODE 1
8+
ENV PYTHONUNBUFFERED 1
9+
10+
RUN apk update \
11+
&& apk add postgresql-dev gcc python3-dev musl-dev
12+
13+
RUN pip install --upgrade pip
14+
15+
COPY ./django_project/requirements.txt .
16+
RUN pip install -r requirements.txt
17+
18+
COPY ./django_project .
19+
20+
ENTRYPOINT ["/usr/src/app/entrypoint.sh" ]

Dockerfile.nginx

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM node:13.12.0-alpine as build
2+
3+
WORKDIR /app/frontend
4+
COPY ./reactapp/package.json ./
5+
COPY ./reactapp/package-lock.json ./
6+
RUN npm ci --silent
7+
COPY ./reactapp/ ./
8+
RUN npm run build
9+
10+
FROM nginx:stable-alpine
11+
COPY --from=build /app/frontend/build /usr/share/nginx/html
12+
CMD ["nginx", "-g", "daemon off;"]

Dockerfile.socket

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM node:18-alpine
2+
WORKDIR /usr/src/app
3+
ADD ./reactapp/*.json ./
4+
ADD ./reactapp/socket.js ./
5+
RUN npm install
6+
CMD node socket.js

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Web app demo
2+
3+
This repository contains web demo based on:
4+
- Django
5+
- React
6+
- RabbitMQ
7+
- Websockets

dev.docker-compose.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
version: '2'
2+
3+
services:
4+
nginx:
5+
restart: unless-stopped
6+
container_name: demo_nginx
7+
build:
8+
context: .
9+
dockerfile: ./Dockerfile.nginx
10+
ports:
11+
- 80:80
12+
volumes:
13+
- static_volume:/app/backend/server/django_static
14+
- ./django_project/media:/app/backend/server/media
15+
- ./nginx/development:/etc/nginx/conf.d
16+
17+
rmq:
18+
image: rabbitmq:3.10-management
19+
restart: always
20+
container_name: demo_rmq
21+
environment:
22+
- RABBITMQ_DEFAULT_USER=${RMQ_USER}
23+
- RABBITMQ_DEFAULT_PASS=${RMQ_PASS}
24+
volumes:
25+
- rabbitmq_data_volume:/var/lib/rabbitmq/
26+
ports:
27+
- 1234:15672
28+
- 5671-5672:5671-5672
29+
env_file:
30+
- ./.env
31+
32+
volumes:
33+
static_volume: {}
34+
rabbitmq_data_volume: {}

django_project/django_project/__init__.py

Whitespace-only changes.

django_project/django_project/asgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for django_project 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/4.2/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', 'django_project.settings')
15+
16+
application = get_asgi_application()
+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import os
2+
from pathlib import Path
3+
from os import environ
4+
5+
BASE_DIR = Path(__file__).resolve().parent.parent
6+
7+
SECRET_KEY = environ.get('SECRET_KEY', "82c1e306-2cdc-412c-9f0e-1ae9fae14126")
8+
9+
DEBUG = int(environ.get('DEBUG', default = 1))
10+
11+
ALLOWED_HOSTS = environ.get('ALLOWED_HOSTS', '*').split(' ')
12+
13+
if "CSRF_TRUSTED_ORIGINS" in environ:
14+
CSRF_TRUSTED_ORIGINS = environ.get('CSRF_TRUSTED_ORIGINS').split(' ')
15+
16+
RMQ_HOST = environ.get('RMQ_HOST', '127.0.0.1')
17+
RMQ_PORT = environ.get('RMQ_PORT', 5672)
18+
RMQ_USER = environ.get('RMQ_USER', 'admin')
19+
RMQ_PASS = environ.get('RMQ_PASS', 'admin')
20+
21+
INSTALLED_APPS = [
22+
'django.contrib.admin',
23+
'django.contrib.auth',
24+
'django.contrib.contenttypes',
25+
'django.contrib.sessions',
26+
'django.contrib.messages',
27+
'django.contrib.staticfiles',
28+
'rest_framework',
29+
'students'
30+
]
31+
32+
MIDDLEWARE = [
33+
'django.middleware.security.SecurityMiddleware',
34+
'django.contrib.sessions.middleware.SessionMiddleware',
35+
'django.middleware.common.CommonMiddleware',
36+
'django.middleware.csrf.CsrfViewMiddleware',
37+
'django.contrib.auth.middleware.AuthenticationMiddleware',
38+
'django.contrib.messages.middleware.MessageMiddleware',
39+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
40+
]
41+
42+
43+
ROOT_URLCONF = 'django_project.urls'
44+
45+
TEMPLATES = [
46+
{
47+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
48+
'DIRS': [],
49+
'APP_DIRS': True,
50+
'OPTIONS': {
51+
'context_processors': [
52+
'django.template.context_processors.debug',
53+
'django.template.context_processors.request',
54+
'django.contrib.auth.context_processors.auth',
55+
'django.contrib.messages.context_processors.messages',
56+
],
57+
},
58+
},
59+
]
60+
61+
WSGI_APPLICATION = 'django_project.wsgi.application'
62+
63+
64+
# Database
65+
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
66+
67+
DATABASES = {
68+
'default': {
69+
'ENGINE': environ.get('POSTGRES_ENGINE', 'django.db.backends.sqlite3'),
70+
'NAME': environ.get('POSTGRES_DB', BASE_DIR / 'db.sqlite3'),
71+
'USER': environ.get('POSTGRES_USER', 'user'),
72+
'PASSWORD': environ.get('POSTGRES_PASSWORD', 'password'),
73+
'HOST': environ.get('POSTGRES_HOST', 'localhost'),
74+
'PORT': environ.get('POSTGRES_PORT', '5432'),
75+
}
76+
}
77+
78+
79+
# Password validation
80+
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
81+
82+
AUTH_PASSWORD_VALIDATORS = [
83+
{
84+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
85+
},
86+
{
87+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
88+
},
89+
{
90+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
91+
},
92+
{
93+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
94+
},
95+
]
96+
97+
98+
# Internationalization
99+
# https://docs.djangoproject.com/en/4.2/topics/i18n/
100+
101+
LANGUAGE_CODE = 'en-us'
102+
103+
TIME_ZONE = 'UTC'
104+
105+
USE_I18N = True
106+
107+
USE_TZ = True
108+
109+
110+
# Static files (CSS, JavaScript, Images)
111+
# https://docs.djangoproject.com/en/4.2/howto/static-files/
112+
113+
STATIC_URL = 'django_static/'
114+
STATIC_ROOT = os.path.join(BASE_DIR, 'django_static')
115+
116+
MEDIA_URL = 'media/'
117+
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
118+
119+
# Default primary key field type
120+
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
121+
122+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
123+
124+
REST_FRAMEWORK = {
125+
'DEFAULT_AUTHENTICATION_CLASSES': [
126+
'rest_framework.authentication.SessionAuthentication',
127+
],
128+
'DEFAULT_PERMISSION_CLASSES': [
129+
'rest_framework.permissions.IsAuthenticated',
130+
],
131+
}
132+
133+
LOGGING = {
134+
'version': 1,
135+
'disable_existing_loggers': False,
136+
'filters': {
137+
'require_debug_true': {
138+
'()': 'django.utils.log.RequireDebugTrue',
139+
}
140+
},
141+
'handlers': {
142+
'console': {
143+
'level': 'INFO',
144+
'filters': ['require_debug_true'],
145+
'class': 'logging.StreamHandler',
146+
}
147+
},
148+
'loggers': {
149+
'': {
150+
'level': 'INFO',
151+
'handlers': ['console'],
152+
}
153+
}
154+
}

django_project/django_project/urls.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from django.contrib import admin
2+
from django.urls import path, re_path
3+
from students import views
4+
from django.conf import settings
5+
from django.conf.urls.static import static
6+
from django.contrib.auth.views import LogoutView
7+
8+
urlpatterns = [
9+
path('admin/', admin.site.urls),
10+
path('api/login', views.login_view, name='login'),
11+
path('api/logout', LogoutView.as_view(next_page='/'), name='logout'),
12+
re_path(r'^api/students/$', views.students_list),
13+
re_path(r'^api/students/(\d+)$', views.students_detail),
14+
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

django_project/django_project/wsgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for django_project 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/4.2/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', 'django_project.settings')
15+
16+
application = get_wsgi_application()

0 commit comments

Comments
 (0)