Skip to content

Commit 2e4078c

Browse files
fix django credentials
0 parents  commit 2e4078c

30 files changed

+1040
-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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Django & Postgres
2+
3+
[![1-click-deploy](https://defang.io/deploy-with-defang.png)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-django-postgres-template%26template_owner%3DDefangSamples)
4+
5+
This template is a customer relationship management list project developed using Python Django framework, offering a starting point to help you quickly build your customer management system. We use PostgreSQL as the database. We have prepared all the essential files for deployment. By spending less than 10 minutes setting up the environment, as detailed in the prerequisites, and executing the commands in our step-by-step guide, your website will be ready to go live to the world!
6+
7+
> [!NOTE]
8+
This sample showcases how you could deploy a full-stack application with Defang and Django. However, it deploys Postgres as a Defang service. Defang [services](https://12factor.net/processes) are ephemeral and should not be used to run stateful workloads in production as they will be reset on every deployment. For production use cases you should use a managed database like RDS, Aiven, or others. If you stick to Django's default SQLite database, your stored data will be lost on every deployment, and in some other situations. In the future, Defang will help you provision and connect to managed databases.
9+
10+
## Prerequisites
11+
12+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
13+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
14+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
15+
16+
## Development
17+
18+
To run the application locally, you can use the following command:
19+
20+
```bash
21+
docker compose up --build
22+
```
23+
24+
## Configuration
25+
26+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):
27+
28+
> Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
29+
30+
### `POSTGRES_PASSWORD`
31+
```bash
32+
defang config set POSTGRES_PASSWORD
33+
```
34+
35+
## Deployment
36+
37+
> [!NOTE]
38+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
39+
40+
### Defang Playground
41+
42+
Deploy your application to the Defang Playground by opening up your terminal and typing:
43+
```bash
44+
defang compose up
45+
```
46+
47+
### BYOC (AWS)
48+
49+
If you want to deploy to your own cloud account, you can use Defang BYOC:
50+
51+
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`.
52+
2. Run in a terminal that has access to your AWS environment variables:
53+
```bash
54+
defang --provider=aws compose up
55+
```
56+
57+
---
58+
59+
Title: Django & PostgreSQL
60+
61+
Short Description: A customer relationship management list project developed using the Python Django framework, offering a starting point to help you quickly build your customer management system.
62+
63+
Tags: Django, PostgreSQL, Python, SQL
64+
65+
Languages: python

app/.dockerignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Ignore version control directories
2+
.git
3+
.gitignore
4+
5+
# Ignore all bytecode
6+
*.pyc
7+
__pycache__/
8+
9+
# Ignore various log and data directories that are created while running locally
10+
logs/
11+
data/
12+
13+
# Ignore virtual environment directories
14+
virt/
15+
16+
# Ignore test, documentation, and CI configuration
17+
tests/
18+
docs/
19+
*.md
20+
.circleci/
21+
.travis.yml
22+
.gitlab-ci.yml
23+
24+
# Ignore PostgreSQL specific files
25+
*.sql
26+
*.dump
27+
28+
# Ignore other unnecessary files
29+
*.log
30+
*.tar.gz
31+
*.zip
32+
tmp/

app/.gitignore

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
tmp
2+
3+
# Django #
4+
*.log
5+
*.pot
6+
*.pyc
7+
__pycache__
8+
db.sqlite3
9+
media
10+
11+
# Backup files #
12+
*.bak
13+
14+
# If using celery-beat with pickle as serializer #
15+
celerybeat-schedule.bak
16+
17+
# PyCharm #
18+
.idea/
19+
20+
# VS Code #
21+
.vscode/
22+
23+
# Python #
24+
*.py[cod]
25+
*$py.class
26+
27+
# Distribution / packaging #
28+
.Python
29+
env/
30+
build/
31+
develop-eggs/
32+
dist/
33+
downloads/
34+
eggs/
35+
.eggs/
36+
lib/
37+
lib64/
38+
parts/
39+
sdist/
40+
var/
41+
wheels/
42+
*.egg-info/
43+
.installed.cfg
44+
*.egg
45+
46+
# Installer logs #
47+
pip-log.txt
48+
pip-delete-this-directory.txt
49+
50+
# Unit test / coverage reports #
51+
htmlcov/
52+
.tox/
53+
.coverage
54+
.coverage.*
55+
.cache
56+
nosetests.xml
57+
coverage.xml
58+
*.cover
59+
.hypothesis/
60+
61+
# Translations #
62+
*.mo
63+
*.pot
64+
65+
# Django stuff #
66+
*.log
67+
local_settings.py
68+
db.sqlite3
69+
db.sqlite3-journal
70+
71+
# Flask stuff #
72+
instance/
73+
.webassets-cache
74+
75+
# Scrapy stuff #
76+
.scrapy
77+
78+
# Sphinx documentation #
79+
docs/_build/
80+
81+
# PyBuilder #
82+
target/
83+
84+
# Jupyter Notebook #
85+
.ipynb_checkpoints
86+
87+
# IPython #
88+
profile_default/
89+
ipython_config.py
90+
91+
# pyenv #
92+
.python-version
93+
94+
# celery beat schedule file #
95+
celerybeat-schedule
96+
97+
# SageMath parsed files #
98+
*.sage.py
99+
100+
# dotenv #
101+
.env
102+
103+
# virtualenv #
104+
venv/
105+
ENV/
106+
107+
# Spyder project settings #
108+
.spyderproject
109+
.spyproject
110+
111+
# Rope project settings #
112+
.ropeproject
113+
114+
# mkdocs documentation #
115+
/site
116+
117+
# mypy #
118+
.mypy_cache/
119+
.dmypy.json
120+
dmypy.json
121+
122+
# Pyre type checker #
123+
.pyre/
124+
125+
# pytype static type analyzer #
126+
.pytype/
127+
128+
# Cython debug symbols #
129+
cython_debug/
130+
131+
# Profiling data #
132+
.prof
133+
134+
# Ignore the static files
135+
staticfiles/

app/Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use an official Python runtime as a parent image
2+
FROM python:3.11-slim
3+
4+
RUN apt-get update -qq \
5+
&& apt-get install -y curl \
6+
&& apt-get clean \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
# Set environment variables
10+
ENV PYTHONDONTWRITEBYTECODE 1
11+
ENV PYTHONUNBUFFERED 1
12+
13+
# Set work directory
14+
WORKDIR /code
15+
16+
# Install dependencies
17+
COPY ./requirements.txt .
18+
RUN pip install -r requirements.txt
19+
20+
# Copy project
21+
COPY . /code/
22+
23+
# Collect static files
24+
RUN python manage.py collectstatic --noinput
25+
26+
# Start server
27+
CMD python manage.py migrate && python manage.py createsuperuser && gunicorn crm_platform.wsgi:application --bind 0.0.0.0:8000

app/crm_platform/__init__.py

Whitespace-only changes.

app/crm_platform/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 crm_platform 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', 'crm_platform.settings')
15+
16+
application = get_asgi_application()

0 commit comments

Comments
 (0)