Skip to content

Commit 89b0575

Browse files
Merge branch 'main' into jordan/use-the-latest-github-action
2 parents 20a570a + fca1ecb commit 89b0575

File tree

17 files changed

+276
-137
lines changed

17 files changed

+276
-137
lines changed

.github/workflows/check-sample.yml

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,50 +42,12 @@ jobs:
4242
uses: actions/github-script@v5
4343
with:
4444
script: |
45-
const fs = require('fs');
46-
const pr_number = context.issue.number;
47-
const marker = '## Samples Checklist';
48-
49-
// Read the checklist from the file
50-
let checklist = fs.readFileSync('checklist.txt', 'utf8').trim();
51-
let error = false;
52-
53-
if(!checklist) {
54-
checklist = "✅ All good!"
55-
}
56-
else {
57-
error = true;
58-
}
59-
60-
// Get the current PR
61-
const { data: pullRequest } = await github.rest.pulls.get({
62-
owner: context.repo.owner,
63-
repo: context.repo.repo,
64-
pull_number: pr_number
65-
});
66-
67-
let newBody;
68-
const body = pullRequest.body || "";
69-
const markerIndex = body.indexOf(marker);
70-
71-
if (markerIndex !== -1) {
72-
// Replace the content below the marker
73-
newBody = body.substring(0, markerIndex + marker.length) + "\n" + checklist;
74-
} else {
75-
// Append the checklist if the marker doesn't exist
76-
newBody = body + "\n" + marker + "\n" + checklist;
77-
}
78-
79-
// Update the PR description
80-
await github.rest.pulls.update({
81-
owner: context.repo.owner,
82-
repo: context.repo.repo,
83-
pull_number: pr_number,
84-
body: newBody
85-
});
86-
87-
if(error) {
88-
throw new Error("Incomplete samples checklist. Please fix the issues and try again.");
45+
const script = require('./scripts/add-checklist-to-pr.js');
46+
try {
47+
await script({github, context});
48+
core.info(`Checklist successfully added to PR description`);
49+
} catch (error) {
50+
core.setFailed(`Script execution failed: ${error.message}`);
8951
}
9052
9153
- name: Create / Update Template Repo

.github/workflows/deploy-changed-samples.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ jobs:
9292
TEST_OPENAI_KEY: ${{ secrets.TEST_OPENAI_KEY }}
9393
TEST_POSTGRES_PASSWORD: ${{ secrets.TEST_POSTGRES_PASSWORD }}
9494
TEST_QUEUE: ${{ secrets.TEST_QUEUE }}
95+
TEST_SECRET_KEY: ${{ secrets.TEST_SECRET_KEY }}
9596
TEST_SECRET_KEY_BASE: ${{ secrets.TEST_SECRET_KEY_BASE }}
9697
TEST_SESSION_SECRET: ${{ secrets.TEST_SESSION_SECRET }}
9798
TEST_SLACK_CHANNEL_ID: ${{ secrets.TEST_SLACK_CHANNEL_ID }}

.github/workflows/publish-sample-template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- main
77

88
jobs:
9-
check_samples:
9+
publish_samples:
1010
runs-on: ubuntu-latest
1111
permissions:
1212
contents: write

samples/django-channels-redis-postgres/.github/workflows/deploy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Deploy
2020
uses: DefangLabs/[email protected]
2121
with:
22-
config-env-vars: SECRET_KEY POSTGRES_PASSWORD POSTGRES_PARAMS
22+
config-env-vars: SECRET_KEY POSTGRES_PASSWORD
2323
env:
2424
SECRET_KEY: ${{ secrets.SECRET_KEY }}
2525
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}

samples/django-channels-redis-postgres/compose.dev.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ services:
77
- ./app:/app
88
healthcheck: {}
99
environment:
10-
REDIS_URL: redis://redis-service:6379
11-
POSTGRES_URL: postgres://djangouser:djangopassword@postgres-service:5432/djangodatabase
12-
DEBUG: "True"
10+
- REDIS_URL=redis://redis-service:6379
11+
- POSTGRES_URL=postgres://djangouser:djangopassword@postgres-service:5432/djangodatabase
12+
- DEBUG="True"
1313
depends_on:
1414
- redis-service
1515
- postgres-service
@@ -25,9 +25,9 @@ services:
2525
file: compose.yaml
2626
service: postgres-service
2727
environment:
28-
POSTGRES_DB: djangodatabase
29-
POSTGRES_USER: djangouser
30-
POSTGRES_PASSWORD: djangopassword
28+
- POSTGRES_DB=djangodatabase
29+
- POSTGRES_USER=djangouser
30+
- POSTGRES_PASSWORD=djangopassword
3131
volumes:
3232
- postgres_data:/var/lib/postgresql/data
3333

samples/django-channels-redis-postgres/compose.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ services:
1010
published: 8000
1111
mode: ingress
1212
environment:
13-
REDIS_URL: redis://redis-service:6379
14-
# if using BYOC set POSTGRES_PARAMS to ?sslmode=require in playground, set to ?
15-
POSTGRES_URL: "postgres://djangouser:${POSTGRES_PASSWORD}@postgres-service:5432/djangodatabase${POSTGRES_PARAMS}"
16-
SECRET_KEY:
13+
- REDIS_URL=redis://redis-service:6379
14+
# if using BYOC add sslmode=require to the POSTGRES_URL query params
15+
- POSTGRES_URL=postgres://djangouser:${POSTGRES_PASSWORD}@postgres-service:5432/djangodatabase?
16+
- SECRET_KEY
1717
healthcheck:
1818
# wget or curl required for healthchecks on services with a published port
1919
# this gets parsed by Defang and provided to the load balancers as well
@@ -35,6 +35,6 @@ services:
3535
- mode: host
3636
target: 5432
3737
environment:
38-
POSTGRES_PASSWORD:
39-
POSTGRES_DB: djangodatabase
40-
POSTGRES_USER: djangouser
38+
- POSTGRES_PASSWORD
39+
- POSTGRES_DB=djangodatabase
40+
- POSTGRES_USER=djangouser

samples/django-postgres/README.md

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,55 @@
44

55
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!
66

7-
## NOTE
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.
89

9-
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 Rail'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.
10+
## Prerequisites
1011

11-
## Essential Setup Files
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/)
1215

13-
1. A [Dockerfile](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/) to describe the basic image of your applications.
14-
2. A [docker-compose file](https://docs.defang.io/docs/concepts/compose) to define and run multi-container Docker applications.
15-
3. A [.dockerignore](https://docs.docker.com/build/building/context/#dockerignore-files) file to comply with the size limit (10MB).
16+
## Development
1617

17-
## Prerequisite
18+
To run the application locally, you can use the following command:
1819

19-
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
20-
2. If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc), make sure you have properly [authenticated your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
21-
Plus, make sure that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
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)
2248

23-
## A Step-by-Step Guide for Deployment
49+
If you want to deploy to your own cloud account, you can use Defang BYOC:
2450

25-
1. Open the terminal and type `defang login`
26-
2. Type `defang compose up` in the CLI
27-
3. Now your application will be launched
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+
```
2856

2957
---
3058

samples/django-postgres/app/crm_platform/settings.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
'django.contrib.auth.middleware.AuthenticationMiddleware',
5454
'django.contrib.messages.middleware.MessageMiddleware',
5555
'django.middleware.clickjacking.XFrameOptionsMiddleware',
56-
'whitenoise.middleware.WhiteNoiseMiddleware',
56+
'whitenoise.middleware.WhiteNoiseMiddleware',
5757
]
5858

5959
ROOT_URLCONF = 'crm_platform.urls'
@@ -83,13 +83,13 @@
8383
DATABASES = {
8484
"default": {
8585
"ENGINE": "django.db.backends.postgresql",
86-
"HOST": os.environ.get('DB_HOST', 'db'),
87-
# We put the host in an environment variable because Defang
86+
"HOST": os.environ.get('DB_HOST', 'db'),
87+
# We put the host in an environment variable because Defang
8888
# detects hostnames that match service names and makes sure they
8989
# are properly configured to communicate when deployed
90-
"NAME": 'mydatabase',
91-
"USER": 'myuser',
92-
"PASSWORD": 'mypassword',
90+
"NAME": os.environ.get("POSTGRES_DB"),
91+
"USER": os.environ.get("POSTGRES_USER"),
92+
"PASSWORD": os.environ.get("POSTGRES_PASSWORD"),
9393
}
9494
}
9595

samples/django-postgres/compose.yaml

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
services:
22
db:
33
restart: unless-stopped
4-
image: postgres:14
4+
image: postgres:16
55
volumes: ["./tmp/postgres:/var/lib/postgresql/data/"]
66
environment:
77
- POSTGRES_DB=mydatabase
88
- POSTGRES_USER=myuser
9-
- POSTGRES_PASSWORD=mypassword
9+
- POSTGRES_PASSWORD
1010
ports:
1111
- mode: host
1212
target: 5432
13-
healthcheck:
14-
test:
15-
[
16-
"CMD-SHELL",
17-
"PGUSER=myuser PGPASSWORD=mypassword pg_isready -q -d mydatabase",
18-
]
19-
interval: 1m30s
20-
timeout: 30s
21-
retries: 5
2213
#deploy:
2314
# resources:
2415
# reservations:
@@ -35,10 +26,13 @@ services:
3526
environment:
3627
- DB_HOST=db
3728
- DEBUG=False
38-
deploy:
39-
resources:
40-
reservations:
41-
memory: 2GB
29+
- POSTGRES_USER=myuser
30+
- POSTGRES_DB=mydatabase
31+
- POSTGRES_PASSWORD
32+
# deploy:
33+
# resources:
34+
# reservations:
35+
# memory: 2GB
4236
# volumes: [".:/code"]
4337
depends_on:
4438
- db

samples/django/README.md

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,58 @@
22

33
[![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-template%26template_owner%3DDefangSamples)
44

5-
This is a simple example of how to run Django on Defang. It is a simple Todo app that uses SQLite as the database.
6-
7-
### NOTE
8-
9-
This sample is a simple Django 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.
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.
106

117
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.
128

139
The Dockerfile and compose files are already set up for you and are ready to be deployed. 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.
1410

15-
## Essential Setup Files
11+
## Prerequisites
1612

17-
1. A [Dockerfile](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/) to describe the basic image of your applications.
18-
2. A [docker-compose file](https://docs.defang.io/docs/concepts/compose) to define and run multi-container Docker applications.
19-
3. A [.dockerignore](https://docs.docker.com/build/building/context/#dockerignore-files) file to comply with the size limit (10MB).
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+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
2016

21-
## Prerequisite
17+
## Development
2218

23-
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
24-
2. If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc), make sure you have properly [authenticated your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
25-
Plus, make sure that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
19+
To run the application locally, you can use the following command:
20+
21+
```bash
22+
docker compose up --build
23+
```
24+
25+
## Configuration
26+
27+
For this sample, you will not need to provide [configuration](https://docs.defang.io/docs/concepts/configuration).
28+
29+
If you wish to provide configuration, see below for an example of setting a configuration for a value named `API_KEY`.
30+
31+
```bash
32+
defang config set API_KEY
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)
2648

27-
## A Step-by-Step Guide
49+
If you want to deploy to your own cloud account, you can use Defang BYOC:
2850

29-
1. (optional) If you are using Defang BYOC, make sure to update the `CSRF_TRUSTED_ORIGINS` setting in the `settings.py` file to include an appropriate domain.
30-
2. Open the terminal and type `defang login`
31-
3. Type `defang compose up` in the CLI
32-
4. Now your application will be launched
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. Make sure to update the `CSRF_TRUSTED_ORIGINS` setting in the `settings.py` file to include an appropriate domain.
53+
3. Run in a terminal that has access to your AWS environment variables:
54+
```bash
55+
defang --provider=aws compose up
56+
```
3357

3458
---
3559

0 commit comments

Comments
 (0)