Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More fixes for Django Postgres sample #307

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/deploy-changed-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ jobs:
TEST_SESSION_SECRET: ${{ secrets.TEST_SESSION_SECRET }}
TEST_SLACK_CHANNEL_ID: ${{ secrets.TEST_SLACK_CHANNEL_ID }}
TEST_SLACK_TOKEN: ${{ secrets.TEST_SLACK_TOKEN }}
TEST_ALLOWED_HOSTS: ${{ secrets.TEST_ALLOWED_HOSTS }}
run: |
SAMPLES=$(sed 's|^samples/||' changed_samples.txt | paste -s -d ',' -)
echo "Running tests for samples: $SAMPLES"
Expand Down
8 changes: 7 additions & 1 deletion samples/django-postgres/.github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ jobs:
uses: actions/checkout@v4

- name: Deploy
uses: DefangLabs/[email protected]
uses: DefangLabs/[email protected]
with:
config-env-vars: POSTGRES_PASSWORD SECRET_KEY ALLOWED_HOSTS
env:
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
ALLOWED_HOSTS: ${{ secrets.ALLOWED_HOSTS }}
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
Empty file.
16 changes: 0 additions & 16 deletions samples/django-postgres/app/crm_platform/asgi.py

This file was deleted.

139 changes: 0 additions & 139 deletions samples/django-postgres/app/crm_platform/settings.py

This file was deleted.

23 changes: 0 additions & 23 deletions samples/django-postgres/app/crm_platform/urls.py

This file was deleted.

16 changes: 0 additions & 16 deletions samples/django-postgres/app/crm_platform/wsgi.py

This file was deleted.

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
Loading