Skip to content

Commit 61f701f

Browse files
commit111jordanstephens
authored andcommitted
fastapi changes
1 parent dc5376b commit 61f701f

File tree

5 files changed

+94
-23
lines changed

5 files changed

+94
-23
lines changed

samples/fastapi-postgres/README.md

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,52 @@ This sample project demonstrates how to deploy FastAPI with PostgreSQL with Defa
99
1. Download <a href="https://github.com/defang-io/defang">Defang CLI</a>
1010
2. (optional) If you are using <a href="https://docs.defang.io/docs/concepts/defang-byoc">Defang BYOC</a>, make sure you have properly <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html">authenticated your AWS account</a>.
1111

12-
## Deploying
12+
## Development
1313

14-
1. Open the terminal and type `defang login`
15-
2. Type `defang compose up` in the CLI.
16-
3. Your app will be running within a few minutes.
14+
To run the development container(s) locally, do:
1715

18-
## Local Development
16+
```bash
17+
docker compose -f compose.dev.yaml up --build
18+
```
1919

20-
1. Run `docker compose -f compose.dev.yaml up --build`
20+
Or to run the production container(s) locally, do:
21+
22+
```bash
23+
POSTGRES_PASSWORD=postgres docker compose up --build
24+
```
25+
26+
## Configuration
27+
28+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):
29+
30+
> 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.
31+
32+
### `POSTGRES_PASSWORD`
33+
``` bash
34+
defang config set POSTGRES_PASSWORD
35+
```
36+
37+
## Deployment
38+
39+
> [!NOTE]
40+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
41+
42+
### Defang Playground
43+
44+
Deploy your application to the Defang Playground by opening up your terminal and typing:
45+
```bash
46+
defang compose up
47+
```
48+
49+
### BYOC (AWS)
50+
51+
If you want to deploy to your own cloud account, you can use Defang BYOC:
52+
53+
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`.
54+
2. Run in a terminal that has access to your AWS environment variables:
55+
```bash
56+
defang --provider=aws compose up
57+
```
2158

2259
---
2360

samples/fastapi-postgres/compose.dev.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ services:
33
extends:
44
file: compose.yaml
55
service: fastapi
6-
restart: unless-stopped
7-
ports:
8-
- "8000:8000"
96
environment:
107
- DATABASE_URL=postgres://postgres:postgres@db:5432/postgres
118
volumes:
@@ -15,8 +12,9 @@ services:
1512
command: fastapi dev main.py --host 0.0.0.0
1613

1714
db:
18-
image: postgres:15
19-
restart: unless-stopped
15+
extends:
16+
file: compose.yaml
17+
service: db
2018
environment:
2119
- POSTGRES_USER=postgres
2220
- POSTGRES_PASSWORD=postgres

samples/fastapi-postgres/compose.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@ services:
77
ports:
88
- mode: ingress
99
target: 8000
10+
published: 8000
1011
environment:
11-
- DATABASE_URL
12+
- DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@db:5432/postgres
1213
#deploy:
1314
# resources:
1415
# reservations:
1516
# memory: 256M
17+
18+
db:
19+
image: postgres:15
20+
restart: unless-stopped
21+
environment:
22+
- POSTGRES_USER=postgres
23+
- POSTGRES_PASSWORD
24+
- POSTGRES_DB=postgres
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
uwsgi
2-
fastapi
2+
fastapi[standard]
33
uvicorn
44
asyncpg
55
databases
66
python-dotenv
7+
jinja2
8+
python-multipart

samples/fastapi/README.md

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,49 @@ This sample project demonstrates how to deploy FastAPI with Defang.
66

77
## Prerequisites
88

9-
1. Download <a href="https://github.com/defang-io/defang">Defang CLI</a>
10-
2. (optional) If you are using <a href="https://docs.defang.io/docs/concepts/defang-byoc">Defang BYOC</a>, make sure you have properly <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html">authenticated your AWS account</a>.
11-
12-
## Deploying
13-
14-
1. Open the terminal and type `defang login`
15-
2. Type `defang compose up` in the CLI.
16-
3. Your app will be running within a few minutes.
9+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
10+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
11+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
1712

1813
## Development
1914

20-
To run your FastAPI app locally, you'll need to have Docker installed on your machine. You can then run:
15+
To run the application locally, you can use the following command:
2116

2217
```bash
2318
docker compose -f compose.yaml -f compose.dev.yaml up --build
2419
```
2520

26-
That will start your FastAPI app on `http://localhost:8000` with hot reloading enabled.
21+
## Configuration
22+
23+
For this sample, you will not need to provide [configuration](https://docs.defang.io/docs/concepts/configuration).
24+
25+
If you wish to provide configuration, see below for an example of setting a configuration for a value named `API_KEY`.
26+
27+
```bash
28+
defang config set API_KEY
29+
```
30+
31+
## Deployment
32+
33+
> [!NOTE]
34+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
35+
36+
### Defang Playground
37+
38+
Deploy your application to the Defang Playground by opening up your terminal and typing:
39+
```bash
40+
defang compose up
41+
```
42+
43+
### BYOC (AWS)
44+
45+
If you want to deploy to your own cloud account, you can use Defang BYOC:
46+
47+
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`.
48+
2. Run in a terminal that has access to your AWS environment variables:
49+
```bash
50+
defang --provider=aws compose up
51+
```
2752

2853
---
2954

0 commit comments

Comments
 (0)