Skip to content

Commit 28c8808

Browse files
feat: Add fly.io deployment (#443)
--------- Co-authored-by: Marcus Schiesser <[email protected]>
1 parent 0a7dfcf commit 28c8808

File tree

11 files changed

+135
-45
lines changed

11 files changed

+135
-45
lines changed

.changeset/olive-comics-grab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-llama": patch
3+
---
4+
5+
Add fly.io deployment

helpers/python.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,4 @@ export const installPythonTemplate = async ({
548548
if (postInstallAction === "runApp" || postInstallAction === "dependencies") {
549549
installPythonDependencies();
550550
}
551-
552-
// Copy deployment files for python
553-
await copy("**", root, {
554-
cwd: path.join(compPath, "deployments", "python"),
555-
});
556551
};

helpers/typescript.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,6 @@ export const installTSTemplate = async ({
247247
) {
248248
await installTSDependencies(packageJson, packageManager, isOnline);
249249
}
250-
251-
// Copy deployment files for typescript
252-
await copy("**", root, {
253-
cwd: path.join(compPath, "deployments", "typescript"),
254-
});
255250
};
256251

257252
async function updatePackageJson({

templates/components/agents/python/blog/README-template.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ To start the app optimized for **production**, run:
5555
poetry run prod
5656
```
5757

58+
## Deployments
59+
60+
For production deployments, check the [DEPLOY.md](DEPLOY.md) file.
61+
5862
## Learn More
5963

6064
To learn more about LlamaIndex, take a look at the following resources:

templates/components/agents/python/financial_report/README-template.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ To start the app optimized for **production**, run:
4343
poetry run prod
4444
```
4545

46+
## Deployments
47+
48+
For production deployments, check the [DEPLOY.md](DEPLOY.md) file.
49+
4650
## Learn More
4751

4852
To learn more about LlamaIndex, take a look at the following resources:

templates/components/agents/python/form_filling/README-template.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ To start the app optimized for **production**, run:
4949
poetry run prod
5050
```
5151

52+
## Deployments
53+
54+
For production deployments, check the [DEPLOY.md](DEPLOY.md) file.
55+
5256
## Learn More
5357

5458
To learn more about LlamaIndex, take a look at the following resources:
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
## Deployments
2+
3+
### Using [Fly.io](https://fly.io/):
4+
5+
First, install [flyctl](https://fly.io/docs/flyctl/install/) and then authenticate with your Fly.io account:
6+
7+
```shell
8+
fly auth login
9+
```
10+
11+
Then, run this command and follow the prompts to deploy the app.:
12+
13+
```shell
14+
fly launch
15+
```
16+
17+
And to open the app in your browser:
18+
19+
```shell
20+
fly apps open
21+
```
22+
23+
> **Note**: The app will use the values from the `.env` file by default to simplify the deployment. Make sure all the needed environment variables in the [.env](.env) file are set. For production environments, you should not use the `.env` file, but [set the variables in Fly.io](https://fly.io/docs/rails/the-basics/configuration/) instead.
24+
25+
#### Documents
26+
27+
If you're having documents in the `./data` folder, run the following command to generate vector embeddings of the documents:
28+
29+
```
30+
fly console --machine <machine_id> --command "poetry run generate"
31+
```
32+
33+
Where `machine_id` is the ID of the machine where the app is running. You can show the running machines with the `fly machines` command.
34+
35+
> **Note**: Using documents will make the app stateful. As Fly.io is a stateless app, you should use [LlamaCloud](https://docs.cloud.llamaindex.ai/llamacloud/getting_started) or a vector database to store the embeddings of the documents. This applies also for document uploads by the user.
36+
37+
### Using Docker
38+
39+
First, build an image for the app:
40+
41+
```
42+
docker build -t <your_image_name> .
43+
```
44+
45+
Then, start the app by running the image:
46+
47+
```
48+
docker run \
49+
-v $(pwd)/.env:/app/.env \ # Use ENV variables and configuration from your file-system
50+
-v $(pwd)/config:/app/config \
51+
-v $(pwd)/storage:/app/storage \ # Use your file system to store vector embeddings
52+
-p 8000:8000 \
53+
<your_image_name>
54+
```
55+
56+
Open [http://localhost:8000](http://localhost:8000) with your browser to start the app.
57+
58+
#### Documents
59+
60+
If you're having documents in the `./data` folder, run the following command to generate vector embeddings of the documents:
61+
62+
```
63+
docker run \
64+
--rm \
65+
-v $(pwd)/.env:/app/.env \ # Use ENV variables and configuration from your file-system
66+
-v $(pwd)/config:/app/config \
67+
-v $(pwd)/data:/app/data \ # Use your local folder to read the data
68+
-v $(pwd)/storage:/app/storage \ # Use your file system to store the vector database
69+
<your_image_name> \
70+
poetry run generate
71+
```
72+
73+
The app will then be able to answer questions about the documents in the `./data` folder.

templates/components/deployments/python/Dockerfile renamed to templates/types/streaming/fastapi/Dockerfile

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
FROM python:3.11 as build
1+
# ====================================
2+
# Build the frontend
3+
# ====================================
4+
FROM node:20 AS frontend
5+
6+
WORKDIR /app/frontend
7+
8+
COPY .frontend /app/frontend
9+
10+
RUN npm install && npm run build
11+
12+
13+
# ====================================
14+
# Backend
15+
# ====================================
16+
FROM python:3.11 AS build
217

318
WORKDIR /app
419

@@ -19,8 +34,17 @@ COPY ./pyproject.toml ./poetry.lock* /app/
1934
RUN poetry install --no-root --no-cache --only main
2035

2136
# ====================================
22-
FROM build as release
37+
# Release
38+
# ====================================
39+
FROM build AS release
40+
41+
COPY --from=frontend /app/frontend/out /app/static
2342

2443
COPY . .
2544

26-
CMD ["python", "main.py"]
45+
# Remove frontend code
46+
RUN rm -rf .frontend
47+
48+
EXPOSE 8000
49+
50+
CMD ["poetry", "run", "prod"]

templates/types/streaming/fastapi/README-template.md

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -58,39 +58,9 @@ To start the app optimized for **production**, run:
5858
poetry run prod
5959
```
6060

61-
## Using Docker
61+
## Deployments
6262

63-
1. Build an image for the FastAPI app:
64-
65-
```
66-
docker build -t <your_backend_image_name> .
67-
```
68-
69-
2. Generate embeddings:
70-
71-
Parse the data and generate the vector embeddings if the `./data` folder exists - otherwise, skip this step:
72-
73-
```
74-
docker run \
75-
--rm \
76-
-v $(pwd)/.env:/app/.env \ # Use ENV variables and configuration from your file-system
77-
-v $(pwd)/config:/app/config \
78-
-v $(pwd)/data:/app/data \ # Use your local folder to read the data
79-
-v $(pwd)/storage:/app/storage \ # Use your file system to store the vector database
80-
<your_backend_image_name> \
81-
poetry run generate
82-
```
83-
84-
3. Start the API:
85-
86-
```
87-
docker run \
88-
-v $(pwd)/.env:/app/.env \ # Use ENV variables and configuration from your file-system
89-
-v $(pwd)/config:/app/config \
90-
-v $(pwd)/storage:/app/storage \ # Use your file system to store gea vector database
91-
-p 8000:8000 \
92-
<your_backend_image_name>
93-
```
63+
For production deployments, check the [DEPLOY.md](DEPLOY.md) file.
9464

9565
## Learn More
9666

0 commit comments

Comments
 (0)