Skip to content

Commit f199bf0

Browse files
committed
Update readme
0 parents  commit f199bf0

File tree

25 files changed

+582
-0
lines changed

25 files changed

+582
-0
lines changed

.github/workflows/deploy.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
environment: playground
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
steps:
17+
- name: Checkout Repo
18+
uses: actions/checkout@v4
19+
20+
- name: Deploy
21+
uses: DefangLabs/[email protected]

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Django-Railpack
2+
3+
[![1-click-deploy](https://raw.githubusercontent.com/DefangLabs/defang-assets/main/Logos/Buttons/SVG/deploy-with-defang.svg)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-django-template%26template_owner%3DDefangSamples)
4+
5+
This sample is a simple Django to-do app that uses SQLite as the database, which will be reset every time you deploy. **It is not production-ready**. For production use cases, you should check out the Django + Postgres sample.
6+
7+
The app includes a management command which is run on startup to create a superuser with the username `admin` and password `admin`. This means you can login to the admin interface at `/admin/` and see the Django admin interface without any additional steps. The `example_app` is already registered and the `Todo` model is already set up to be managed in the admin interface.
8+
9+
The compose files are already set up for you and are ready to be deployed and the image is built by [Railpack](https://railpack.com/). Serving is done using [Gunicorn](https://gunicorn.org/) and uses [WhiteNoise](https://whitenoise.readthedocs.io/en/latest/) for static files. The `CSRF_TRUSTED_ORIGINS` setting is configured to allow the app to run on a `defang.dev` subdomain.
10+
11+
## Prerequisites
12+
13+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
14+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
15+
16+
## Configuration
17+
18+
For this sample, you will not need to provide [configuration](https://docs.defang.io/docs/concepts/configuration).
19+
20+
If you wish to provide configuration, see below for an example of setting a configuration for a value named `API_KEY`.
21+
22+
```bash
23+
defang config set API_KEY
24+
```
25+
26+
## Deployment
27+
28+
> [!NOTE]
29+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
30+
31+
### Defang Playground
32+
33+
Deploy your application to the Defang Playground by opening up your terminal and typing:
34+
35+
```bash
36+
defang compose up
37+
```
38+
39+
### BYOC (AWS)
40+
41+
If you want to deploy to your own cloud account, you can use Defang BYOC:
42+
43+
1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and check that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
44+
2. Make sure to update the `CSRF_TRUSTED_ORIGINS` setting in the `settings.py` file to include an appropriate domain.
45+
3. Run in a terminal that has access to your AWS environment variables:
46+
```bash
47+
defang --provider=aws compose up
48+
```
49+
50+
---
51+
52+
Title: Django
53+
54+
Short Description: A simple Django app that uses SQLite as the database.
55+
56+
Tags: Django, SQLite, Python, Railpack
57+
58+
Languages: python

app/.dockerignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Ignore Python bytecode files
2+
__pycache__
3+
*.pyc
4+
*.pyo
5+
*.pyd
6+
*.pyc.so
7+
8+
# Ignore all log files
9+
*.log
10+
11+
# Ignore local configuration files
12+
local_settings.py
13+
14+
# Ignore test and coverage directories
15+
htmlcov/
16+
.coverage
17+
.tox/
18+
19+
# Ignore database files
20+
*.sqlite3
21+
22+
# Ignore media files
23+
media/
24+
25+
# Ignore all .env files
26+
*.env
27+
28+
# Ignore all .DS_Store files (Mac OS)
29+
.DS_Store
30+
31+
.venv/

app/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
*.log
2+
*.pyc
3+
__pycache__
4+
db.sqlite3
5+
media
6+
7+
# Environments
8+
.env
9+
.venv
10+
env/
11+
venv/
12+
ENV/
13+
env.bak/
14+
venv.bak/

app/defang_sample/__init__.py

Whitespace-only changes.

app/defang_sample/asgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for defang_sample 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.0/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', 'defang_sample.settings')
15+
16+
application = get_asgi_application()

app/defang_sample/settings.py

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
"""
2+
Django settings for defang_sample project.
3+
4+
Generated by 'django-admin startproject' using Django 5.0.4.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.0/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/5.0/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
import os
15+
16+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
17+
BASE_DIR = Path(__file__).resolve().parent.parent
18+
19+
20+
# Quick-start development settings - unsuitable for production
21+
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
22+
23+
# SECURITY WARNING: keep the secret key used in production secret!
24+
SECRET_KEY = 'django-insecure-r(z^n29_r&ax*%(!la2i*cy@*$2q1h(ulie!%@qy)5j-i9kepw'
25+
26+
# SECURITY WARNING: don't run with debug turned on in production!
27+
DEBUG = os.environ.get('DEBUG', 'False') == 'True'
28+
29+
ALLOWED_HOSTS = [
30+
'*'
31+
]
32+
33+
34+
# Application definition
35+
36+
INSTALLED_APPS = [
37+
'django.contrib.admin',
38+
'django.contrib.auth',
39+
'django.contrib.contenttypes',
40+
'django.contrib.sessions',
41+
'django.contrib.messages',
42+
'django.contrib.staticfiles',
43+
'example_app',
44+
]
45+
46+
MIDDLEWARE = [
47+
'django.middleware.security.SecurityMiddleware',
48+
'django.contrib.sessions.middleware.SessionMiddleware',
49+
'django.middleware.common.CommonMiddleware',
50+
'django.middleware.csrf.CsrfViewMiddleware',
51+
'django.contrib.auth.middleware.AuthenticationMiddleware',
52+
'django.contrib.messages.middleware.MessageMiddleware',
53+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
54+
'whitenoise.middleware.WhiteNoiseMiddleware',
55+
]
56+
57+
ROOT_URLCONF = 'defang_sample.urls'
58+
59+
TEMPLATES = [
60+
{
61+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
62+
'DIRS': [],
63+
'APP_DIRS': True,
64+
'OPTIONS': {
65+
'context_processors': [
66+
'django.template.context_processors.debug',
67+
'django.template.context_processors.request',
68+
'django.contrib.auth.context_processors.auth',
69+
'django.contrib.messages.context_processors.messages',
70+
],
71+
},
72+
},
73+
]
74+
75+
WSGI_APPLICATION = 'defang_sample.wsgi.application'
76+
77+
78+
# Database
79+
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
80+
81+
DATABASES = {
82+
'default': {
83+
'ENGINE': 'django.db.backends.sqlite3',
84+
'NAME': BASE_DIR / 'db.sqlite3',
85+
}
86+
}
87+
88+
89+
# Password validation
90+
# https://docs.djangoproject.com/en/5.0/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.0/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.0/howto/static-files/
122+
123+
STATIC_URL = 'static/'
124+
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
125+
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
126+
127+
# Default primary key field type
128+
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
129+
130+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
131+
132+
# CSRF
133+
CSRF_TRUSTED_ORIGINS = [
134+
'https://*.defang.dev'
135+
]
136+
137+
if DEBUG:
138+
CSRF_TRUSTED_ORIGINS = [
139+
'http://localhost:8000',
140+
]

app/defang_sample/urls.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
URL configuration for defang_sample project.
3+
4+
The `urlpatterns` list routes URLs to views. For more information please see:
5+
https://docs.djangoproject.com/en/5.0/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+
from django.contrib import admin
18+
from django.urls import path, include
19+
from django.views.generic import RedirectView
20+
21+
urlpatterns = [
22+
path('admin/', admin.site.urls),
23+
path('todos/', include('example_app.urls', namespace='example_app')),
24+
path('', RedirectView.as_view(url='/todos/')),
25+
]

app/defang_sample/wsgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for defang_sample 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.0/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', 'defang_sample.settings')
15+
16+
application = get_wsgi_application()

app/example_app/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)