Skip to content

Commit

Permalink
more fixes to config
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaeltm committed Jan 22, 2025
1 parent 40d20a8 commit 9df6771
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
22 changes: 19 additions & 3 deletions samples/django-postgres/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

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!

> [!NOTE]
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.

## Prerequisites

1. Download [Defang CLI](https://github.com/DefangLabs/defang)
Expand All @@ -28,10 +25,29 @@ For this sample, you will need to provide the following [configuration](https://
> 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.
### `POSTGRES_PASSWORD`

The password for the PostgreSQL database.

```bash
defang config set POSTGRES_PASSWORD
```

### `SECRET_KEY`

The secret key is used to secure the Django application.

```bash
defang config set SECRET_KEY
```

### `ALLOWED_HOSTS`

The allowed hosts for the Django application. (i.e. the domain your app runs on)

```bash
defang config set ALLOWED_HOSTS
```

## Deployment

> [!NOTE]
Expand Down
14 changes: 6 additions & 8 deletions samples/django-postgres/app/crm_platform/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-^0jq%7b(%aj$j@n0_$gk@#73&z#t%4o#klquddg1e1hdal^9!s'
SECRET_KEY = os.getenv('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
if not SECRET_KEY:
raise ValueError("No SECRET_KEY environment variable set!")

ALLOWED_HOSTS = ['*']
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv('DEBUG', 'False').lower() == 'true'

CSRF_TRUSTED_ORIGINS = [
'https://*.defang.dev',
'http://localhost:8000',
]
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', 'localhost').split(',')

# Application definition

Expand Down
2 changes: 2 additions & 0 deletions samples/django-postgres/compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ services:
- POSTGRES_USER=django
- POSTGRES_DB=django
- POSTGRES_PASSWORD=password
- SECRET_KEY=django-insecure-^0jq%7b(%aj$j@n0_$gk@#73&z#t%4o#klquddg1e1hdal^9!s
- ALLOWED_HOSTS=*
volumes:
- "./app:/code"
command: python manage.py migrate
Expand Down
2 changes: 2 additions & 0 deletions samples/django-postgres/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ services:
- POSTGRES_USER=django
- POSTGRES_DB=django
- POSTGRES_PASSWORD
- SECRET_KEY
- ALLOWED_HOSTS
depends_on:
- db

0 comments on commit 9df6771

Please sign in to comment.