Skip to content

Commit 9134e69

Browse files
authored
Merge pull request #327 from DefangLabs/linda-nextjs-cv
Add Nextjs CV (from market.dev) sample
0 parents  commit 9134e69

31 files changed

+998
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM mcr.microsoft.com/devcontainers/python:3.12-bookworm
2+
3+
# Install django cli
4+
RUN pip install django

.devcontainer/devcontainer.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile",
4+
"context": ".."
5+
},
6+
"features": {
7+
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
8+
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
9+
}
10+
}

.github/workflows/deploy.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
14+
15+
steps:
16+
- name: Checkout Repo
17+
uses: actions/checkout@v4
18+
19+
- name: Deploy
20+
uses: DefangLabs/[email protected]
21+
with:
22+
config-env-vars: SECRET_KEY POSTGRES_PASSWORD
23+
env:
24+
SECRET_KEY: ${{ secrets.SECRET_KEY }}
25+
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Django Channels & Redis & 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-channels-redis-template%26template_owner%3DDefangSamples)
4+
5+
This sample demonstrates how to get Django Channels up and running with Redis and Postgres both managed by Defang. It demonstrates how to do this with a simple chat application.
6+
7+
## Prerequisites
8+
9+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
10+
2. (Optional) If you are using [Defang BYOC](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) authenticated with your AWS account
11+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
12+
13+
## Development
14+
15+
To run the application locally, you can use the following command:
16+
17+
```bash
18+
docker compose -f compose.dev.yaml up
19+
```
20+
21+
This will start the Django server, Redis, and Postgres and mounts your Django app so you get live reloading. You can access the Django server at `http://localhost:8000`.
22+
23+
## Configuration
24+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration). 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.
25+
26+
### `SECRET_KEY`
27+
The secret key for your Django application. You can generate a new one by running `python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'`. A default, insecure key is used if this is not set, but you should set it for a production deployment.
28+
29+
### `POSTGRES_PASSWORD`
30+
The password for your Postgres database. You need to set this before deploying for the first time.
31+
32+
## Deploying
33+
34+
1. Open the terminal and type `defang login`
35+
2. Use the [`defang config`](https://docs.defang.io/docs/concepts/compose#configuration) command to setup environment variables.
36+
3. Type `defang compose up` in the CLI.
37+
4. Your app will be running within a few minutes.
38+
39+
---
40+
41+
Title: Django Channels & Redis & Postgres
42+
43+
Short Description: A basic configuration of Django Channels with Redis and Postgres demonstrating a simple chat application.
44+
45+
Tags: Django, Channels, Redis, Postgres, Chat, Application
46+
47+
Languages: Python

app/.dockerignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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

app/.gitignore

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# PyInstaller
28+
# Usually these files are written by a python script from a template
29+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
30+
*.manifest
31+
*.spec
32+
33+
# Installer logs
34+
pip-log.txt
35+
pip-delete-this-directory.txt
36+
37+
# Unit test / coverage reports
38+
htmlcov/
39+
.tox/
40+
.nox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
*.py,cover
48+
.hypothesis/
49+
.pytest_cache/
50+
cover/
51+
52+
# Translations
53+
*.mo
54+
*.pot
55+
56+
# Django stuff:
57+
*.log
58+
local_settings.py
59+
db.sqlite3
60+
db.sqlite3-journal
61+
62+
# Flask stuff:
63+
instance/
64+
.webassets-cache
65+
66+
# Scrapy stuff:
67+
.scrapy
68+
69+
# Sphinx documentation
70+
docs/_build/
71+
docs/_build/doctrees
72+
docs/_build/html
73+
docs/_build/latex
74+
docs/_build/man
75+
docs/_build/rst
76+
docs/_build/texinfo
77+
docs/_build/xml
78+
79+
# PyBuilder
80+
target/
81+
82+
# Jupyter Notebook
83+
.ipynb_checkpoints
84+
85+
# IPython
86+
profile_default/
87+
ipython_config.py
88+
89+
# pyenv
90+
.python-version
91+
92+
# celery beat schedule file
93+
celerybeat-schedule
94+
95+
# dotenv
96+
.env
97+
.env.*
98+
99+
# virtualenv
100+
venv/
101+
ENV/
102+
env/
103+
env.bak/
104+
venv.bak/
105+
106+
# Spyder project settings
107+
.spyderproject
108+
.spyproject
109+
110+
# Rope project settings
111+
.ropeproject
112+
113+
# mkdocs documentation
114+
/site
115+
116+
# mypy
117+
.mypy_cache/
118+
.dmypy.json
119+
dmypy.json
120+
121+
# Pyre type checker
122+
.pyre/
123+
124+
# VS Code
125+
.vscode/
126+
127+
# macOS
128+
.DS_Store

app/Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Use a smaller base image
2+
FROM python:3.10.4-slim-buster
3+
4+
# Set environment variables
5+
ENV PYTHONDONTWRITEBYTECODE 1
6+
ENV PYTHONUNBUFFERED 1
7+
8+
# Set work directory
9+
WORKDIR /app
10+
11+
RUN apt-get update && apt-get install -y \
12+
gcc \
13+
python3-dev \
14+
libpq-dev
15+
16+
# Install dependencies
17+
COPY requirements.txt /app/
18+
RUN pip install --upgrade pip
19+
RUN pip install --no-cache-dir -r requirements.txt
20+
21+
# Copy project files
22+
COPY . /app/
23+
24+
# Collect static files
25+
RUN python manage.py collectstatic --noinput
26+
27+
# Create a non-root user
28+
RUN adduser --disabled-password --gecos '' django
29+
30+
# Set the user to the non-root user
31+
USER django
32+
33+
# Start server
34+
CMD ["sh", "-c", "python manage.py migrate && daphne -b 0.0.0.0 -p 8000 django_defang.asgi:application"]

app/chat/__init__.py

Whitespace-only changes.

app/chat/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

app/chat/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class ChatConfig(AppConfig):
5+
default_auto_field = "django.db.models.BigAutoField"
6+
name = "chat"

0 commit comments

Comments
 (0)