diff --git a/.changeset/olive-comics-grab.md b/.changeset/olive-comics-grab.md new file mode 100644 index 0000000000000000000000000000000000000000..0706749d6467eb8fd4f686de3642abdee2439c80 --- /dev/null +++ b/.changeset/olive-comics-grab.md @@ -0,0 +1,5 @@ +--- +"create-llama": patch +--- + +Add fly.io deployment diff --git a/helpers/python.ts b/helpers/python.ts index f57f6e97016bc0f1cffe24cb3d6333f262a64d1e..0e5ac7c70aec20eb18cc301bcf35a358ec324aef 100644 --- a/helpers/python.ts +++ b/helpers/python.ts @@ -548,9 +548,4 @@ export const installPythonTemplate = async ({ if (postInstallAction === "runApp" || postInstallAction === "dependencies") { installPythonDependencies(); } - - // Copy deployment files for python - await copy("**", root, { - cwd: path.join(compPath, "deployments", "python"), - }); }; diff --git a/helpers/typescript.ts b/helpers/typescript.ts index d0064bfd23c364c6ecd1cb37c3a75ee609459322..3c57ba3bb27745acdb0f60912d35fd9b5fbb4389 100644 --- a/helpers/typescript.ts +++ b/helpers/typescript.ts @@ -247,11 +247,6 @@ export const installTSTemplate = async ({ ) { await installTSDependencies(packageJson, packageManager, isOnline); } - - // Copy deployment files for typescript - await copy("**", root, { - cwd: path.join(compPath, "deployments", "typescript"), - }); }; async function updatePackageJson({ diff --git a/templates/components/agents/python/blog/README-template.md b/templates/components/agents/python/blog/README-template.md index f6d928e2535a447ebed6d8a34221ad22a34d5c08..730b20d8cac6a15f221627a827464aac33ca1f50 100644 --- a/templates/components/agents/python/blog/README-template.md +++ b/templates/components/agents/python/blog/README-template.md @@ -55,6 +55,10 @@ To start the app optimized for **production**, run: poetry run prod ``` +## Deployments + +For production deployments, check the [DEPLOY.md](DEPLOY.md) file. + ## Learn More To learn more about LlamaIndex, take a look at the following resources: diff --git a/templates/components/agents/python/financial_report/README-template.md b/templates/components/agents/python/financial_report/README-template.md index 12754422596240224b92513f69104ad3a7b53cda..5359c81df56250f325a323eedc08273a87076719 100644 --- a/templates/components/agents/python/financial_report/README-template.md +++ b/templates/components/agents/python/financial_report/README-template.md @@ -43,6 +43,10 @@ To start the app optimized for **production**, run: poetry run prod ``` +## Deployments + +For production deployments, check the [DEPLOY.md](DEPLOY.md) file. + ## Learn More To learn more about LlamaIndex, take a look at the following resources: diff --git a/templates/components/agents/python/form_filling/README-template.md b/templates/components/agents/python/form_filling/README-template.md index 5a8af48d189f07631599995888b5f0e255cef7a6..d1ab8e56bb4d38ea7a46b2ff5be4232c86e24fe2 100644 --- a/templates/components/agents/python/form_filling/README-template.md +++ b/templates/components/agents/python/form_filling/README-template.md @@ -49,6 +49,10 @@ To start the app optimized for **production**, run: poetry run prod ``` +## Deployments + +For production deployments, check the [DEPLOY.md](DEPLOY.md) file. + ## Learn More To learn more about LlamaIndex, take a look at the following resources: diff --git a/templates/components/deployments/typescript/Dockerfile b/templates/types/streaming/express/Dockerfile similarity index 100% rename from templates/components/deployments/typescript/Dockerfile rename to templates/types/streaming/express/Dockerfile diff --git a/templates/types/streaming/fastapi/DEPLOY.md b/templates/types/streaming/fastapi/DEPLOY.md new file mode 100644 index 0000000000000000000000000000000000000000..59881f7bb2bd803d0576bf823a07c1b3edb335e3 --- /dev/null +++ b/templates/types/streaming/fastapi/DEPLOY.md @@ -0,0 +1,73 @@ +## Deployments + +### Using [Fly.io](https://fly.io/): + +First, install [flyctl](https://fly.io/docs/flyctl/install/) and then authenticate with your Fly.io account: + +```shell +fly auth login +``` + +Then, run this command and follow the prompts to deploy the app.: + +```shell +fly launch +``` + +And to open the app in your browser: + +```shell +fly apps open +``` + +> **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. + +#### Documents + +If you're having documents in the `./data` folder, run the following command to generate vector embeddings of the documents: + +``` +fly console --machine <machine_id> --command "poetry run generate" +``` + +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. + +> **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. + +### Using Docker + +First, build an image for the app: + +``` +docker build -t <your_image_name> . +``` + +Then, start the app by running the image: + +``` +docker run \ + -v $(pwd)/.env:/app/.env \ # Use ENV variables and configuration from your file-system + -v $(pwd)/config:/app/config \ + -v $(pwd)/storage:/app/storage \ # Use your file system to store vector embeddings + -p 8000:8000 \ + <your_image_name> +``` + +Open [http://localhost:8000](http://localhost:8000) with your browser to start the app. + +#### Documents + +If you're having documents in the `./data` folder, run the following command to generate vector embeddings of the documents: + +``` +docker run \ + --rm \ + -v $(pwd)/.env:/app/.env \ # Use ENV variables and configuration from your file-system + -v $(pwd)/config:/app/config \ + -v $(pwd)/data:/app/data \ # Use your local folder to read the data + -v $(pwd)/storage:/app/storage \ # Use your file system to store the vector database + <your_image_name> \ + poetry run generate +``` + +The app will then be able to answer questions about the documents in the `./data` folder. diff --git a/templates/components/deployments/python/Dockerfile b/templates/types/streaming/fastapi/Dockerfile similarity index 52% rename from templates/components/deployments/python/Dockerfile rename to templates/types/streaming/fastapi/Dockerfile index 624364b6597c33d5199460968f170b30c665611e..7e3a0143a79ac3734602f8235bf49242c355ed21 100644 --- a/templates/components/deployments/python/Dockerfile +++ b/templates/types/streaming/fastapi/Dockerfile @@ -1,4 +1,19 @@ -FROM python:3.11 as build +# ==================================== +# Build the frontend +# ==================================== +FROM node:20 AS frontend + +WORKDIR /app/frontend + +COPY .frontend /app/frontend + +RUN npm install && npm run build + + +# ==================================== +# Backend +# ==================================== +FROM python:3.11 AS build WORKDIR /app @@ -19,8 +34,17 @@ COPY ./pyproject.toml ./poetry.lock* /app/ RUN poetry install --no-root --no-cache --only main # ==================================== -FROM build as release +# Release +# ==================================== +FROM build AS release + +COPY --from=frontend /app/frontend/out /app/static COPY . . -CMD ["python", "main.py"] \ No newline at end of file +# Remove frontend code +RUN rm -rf .frontend + +EXPOSE 8000 + +CMD ["poetry", "run", "prod"] \ No newline at end of file diff --git a/templates/types/streaming/fastapi/README-template.md b/templates/types/streaming/fastapi/README-template.md index ceb6804b3f6779d556ab445d88e98335f30c2245..00a522e7efd4a98f33df63793e95d39db7097a98 100644 --- a/templates/types/streaming/fastapi/README-template.md +++ b/templates/types/streaming/fastapi/README-template.md @@ -58,39 +58,9 @@ To start the app optimized for **production**, run: poetry run prod ``` -## Using Docker +## Deployments -1. Build an image for the FastAPI app: - -``` -docker build -t <your_backend_image_name> . -``` - -2. Generate embeddings: - -Parse the data and generate the vector embeddings if the `./data` folder exists - otherwise, skip this step: - -``` -docker run \ - --rm \ - -v $(pwd)/.env:/app/.env \ # Use ENV variables and configuration from your file-system - -v $(pwd)/config:/app/config \ - -v $(pwd)/data:/app/data \ # Use your local folder to read the data - -v $(pwd)/storage:/app/storage \ # Use your file system to store the vector database - <your_backend_image_name> \ - poetry run generate -``` - -3. Start the API: - -``` -docker run \ - -v $(pwd)/.env:/app/.env \ # Use ENV variables and configuration from your file-system - -v $(pwd)/config:/app/config \ - -v $(pwd)/storage:/app/storage \ # Use your file system to store gea vector database - -p 8000:8000 \ - <your_backend_image_name> -``` +For production deployments, check the [DEPLOY.md](DEPLOY.md) file. ## Learn More diff --git a/templates/types/streaming/nextjs/Dockerfile b/templates/types/streaming/nextjs/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..5c738ab4a016cd2fa2732af779191ff4f53d203e --- /dev/null +++ b/templates/types/streaming/nextjs/Dockerfile @@ -0,0 +1,16 @@ +FROM node:20-alpine as build + +WORKDIR /app + +# Install dependencies +COPY package.json package-lock.* ./ +RUN npm install + +# Build the application +COPY . . +RUN npm run build + +# ==================================== +FROM build as release + +CMD ["npm", "run", "start"] \ No newline at end of file