Skip to content

Commit 7873981

Browse files
committed
starting point for django
1 parent 833caea commit 7873981

File tree

12 files changed

+361
-16
lines changed

12 files changed

+361
-16
lines changed
Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1-
#REMOVE_ME_AFTER_EDITING - This Dockerignore is for a basic node app. Modify as needed.
2-
node_modules
3-
npm-debug.log
1+
# Ignore development files and directories
2+
*.pyc
3+
*.pyo
4+
*.pyd
5+
__pycache__/
6+
.env
7+
8+
# Ignore static files
9+
/static/
10+
/media/
11+
12+
# Ignore database files
13+
/db.sqlite3
14+
15+
# Ignore log files
16+
/logs/
17+
18+
# Ignore Docker-related files
19+
Dockerfile
20+
docker-compose.yml
21+
22+
# Ignore any other unnecessary files or directories
23+
node_modules/
24+
*.log
Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,58 @@
1-
#REMOVE_ME_AFTER_EDITING - This Dockerignore is for a basic node app. Modify as needed.
2-
node_modules
1+
# Ignore compiled Python files
2+
*.pyc
3+
__pycache__/
4+
5+
# Ignore the virtual environment
6+
venv/
7+
env/
8+
9+
# Ignore the Django secret key
10+
*.secret_key
11+
12+
# Ignore database files
13+
*.db
14+
*.sqlite3
15+
16+
# Ignore static files
17+
staticfiles/
18+
19+
# Ignore media files
20+
media/
21+
22+
# Ignore log files
23+
*.log
24+
25+
# Ignore IDE and editor files
26+
.vscode/
27+
.idea/
28+
*.code-workspace
29+
30+
# Ignore local development settings
31+
local_settings.py
32+
33+
# Ignore deployment files
34+
deploy/
35+
36+
# Ignore sensitive information
37+
*.env
38+
*.env.*
39+
*.key
40+
41+
# Ignore compiled JavaScript files
42+
*.js
43+
44+
# Ignore compiled CSS files
45+
*.css
46+
47+
# Ignore compiled HTML files
48+
*.html
49+
50+
# Ignore compiled binary files
51+
*.exe
52+
*.dll
53+
*.so
54+
*.dylib
55+
56+
# Ignore package manager files
57+
node_modules/
58+
yarn-error.log

samples/django-channels-redis/app/Dockerfile

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use an official Python runtime as a parent image
2-
FROM python:3.10.4-slim-buster
2+
FROM python:3.10.4-slim-buster AS builder
33

44
# Set environment variables
55
ENV PYTHONDONTWRITEBYTECODE 1
@@ -18,5 +18,26 @@ COPY . /code/
1818
# Collect static files
1919
RUN python manage.py collectstatic --noinput
2020

21+
22+
# Use a smaller base image for the final stage
23+
FROM python:3.10.4-slim-buster
24+
25+
# Set environment variables
26+
ENV PYTHONDONTWRITEBYTECODE 1
27+
ENV PYTHONUNBUFFERED 1
28+
29+
# Set work directory
30+
WORKDIR /code
31+
32+
# Copy the dependencies from the builder stage
33+
COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
34+
COPY --from=builder /code /code
35+
36+
# Create a non-root user
37+
RUN adduser --disabled-password --gecos '' django
38+
39+
# Set the user to the non-root user
40+
USER django
41+
2142
# Start server
22-
CMD python manage.py migrate && gunicorn defang_sample.wsgi:application --bind 0.0.0.0:8000
43+
CMD ["sh", "-c", "python manage.py migrate && gunicorn defang_sample.wsgi:application --bind 0.0.0.0:8000"]

samples/django-channels-redis/app/django_defang/__init__.py

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for django_defang 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/5.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", "django_defang.settings")
15+
16+
application = get_asgi_application()
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
"""
2+
Django settings for django_defang project.
3+
4+
Generated by 'django-admin startproject' using Django 5.1.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/5.1/ref/settings/
11+
"""
12+
13+
import os
14+
from pathlib import Path
15+
import dj_database_url
16+
17+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
18+
BASE_DIR = Path(__file__).resolve().parent.parent
19+
20+
21+
# Quick-start development settings - unsuitable for production
22+
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
23+
24+
# SECURITY WARNING: keep the secret key used in production secret!
25+
SECRET_KEY = "django-insecure-c!3+-wtsf@&6+p-z88$fyqr!zrnd@uvi=hi&u00n+ku9&_04rk"
26+
27+
# SECURITY WARNING: don't run with debug turned on in production!
28+
DEBUG = True
29+
30+
ALLOWED_HOSTS = []
31+
32+
if DEBUG:
33+
ALLOWED_HOSTS = ["*"]
34+
35+
36+
# Application definition
37+
38+
INSTALLED_APPS = [
39+
"django.contrib.admin",
40+
"django.contrib.auth",
41+
"django.contrib.contenttypes",
42+
"django.contrib.sessions",
43+
"django.contrib.messages",
44+
"django.contrib.staticfiles",
45+
]
46+
47+
MIDDLEWARE = [
48+
"django.middleware.security.SecurityMiddleware",
49+
"whitenoise.middleware.WhiteNoiseMiddleware",
50+
"django.contrib.sessions.middleware.SessionMiddleware",
51+
"django.middleware.common.CommonMiddleware",
52+
"django.middleware.csrf.CsrfViewMiddleware",
53+
"django.contrib.auth.middleware.AuthenticationMiddleware",
54+
"django.contrib.messages.middleware.MessageMiddleware",
55+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
56+
]
57+
58+
ROOT_URLCONF = "django_defang.urls"
59+
60+
TEMPLATES = [
61+
{
62+
"BACKEND": "django.template.backends.django.DjangoTemplates",
63+
"DIRS": [],
64+
"APP_DIRS": True,
65+
"OPTIONS": {
66+
"context_processors": [
67+
"django.template.context_processors.debug",
68+
"django.template.context_processors.request",
69+
"django.contrib.auth.context_processors.auth",
70+
"django.contrib.messages.context_processors.messages",
71+
],
72+
},
73+
},
74+
]
75+
76+
WSGI_APPLICATION = "django_defang.wsgi.application"
77+
78+
79+
# Database
80+
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
81+
82+
DATABASES = {
83+
# default is a postrgres database load from environment variable POSTGRES_URL
84+
"default": dj_database_url.config(
85+
default=os.environ.get('POSTGRES_URL')
86+
)
87+
}
88+
89+
# Password validation
90+
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
91+
92+
AUTH_PASSWORD_VALIDATORS = [
93+
{
94+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
95+
},
96+
{
97+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
98+
},
99+
{
100+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
101+
},
102+
{
103+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
104+
},
105+
]
106+
107+
108+
# Internationalization
109+
# https://docs.djangoproject.com/en/5.1/topics/i18n/
110+
111+
LANGUAGE_CODE = "en-us"
112+
113+
TIME_ZONE = "UTC"
114+
115+
USE_I18N = True
116+
117+
USE_TZ = True
118+
119+
120+
# Static files (CSS, JavaScript, Images)
121+
# https://docs.djangoproject.com/en/5.1/howto/static-files/
122+
123+
STATIC_URL = "static/"
124+
125+
STATIC_ROOT = BASE_DIR / "staticfiles"
126+
127+
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
128+
129+
# Default primary key field type
130+
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
131+
132+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
133+
134+
135+
CSRF_TRUSTED_ORIGINS = [
136+
'https://*.prod1.defang.dev'
137+
]
138+
139+
if DEBUG:
140+
CSRF_TRUSTED_ORIGINS = [
141+
'http://localhost:8000',
142+
]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
URL configuration for django_defang project.
3+
4+
The `urlpatterns` list routes URLs to views. For more information please see:
5+
https://docs.djangoproject.com/en/5.1/topics/http/urls/
6+
Examples:
7+
Function views
8+
1. Add an import: from my_app import views
9+
2. Add a URL to urlpatterns: path('', views.home, name='home')
10+
Class-based views
11+
1. Add an import: from other_app.views import Home
12+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13+
Including another URLconf
14+
1. Import the include() function: from django.urls import include, path
15+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16+
"""
17+
18+
from django.contrib import admin
19+
from django.urls import path
20+
21+
urlpatterns = [
22+
path("admin/", admin.site.urls),
23+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for django_defang 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/5.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", "django_defang.settings")
15+
16+
application = get_wsgi_application()
Lines changed: 22 additions & 0 deletions
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", "django_defang.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()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
asgiref==3.8.1
2+
dj-database-url==2.2.0
3+
Django==5.1
4+
gitdb==4.0.11
5+
GitPython==3.1.41
6+
setuptools==69.0.3
7+
smmap==5.0.1
8+
sqlparse==0.5.1
9+
typing_extensions==4.12.2
10+
wheel==0.44.0
11+
whitenoise==6.7.0

0 commit comments

Comments
 (0)