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

Fix/docker setup #68

Merged
merged 13 commits into from
Dec 7, 2023
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
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
OPENAI_API_KEY=placeholder
ANTHROPIC_API_KEY=placeholder
YDC_API_KEY=placeholder
TAVILY_API_KEY=placeholder
AZURE_OPENAI_DEPLOYMENT_NAME=placeholder
AZURE_OPENAI_API_KEY=placeholder
AZURE_OPENAI_API_BASE=placeholder
AZURE_OPENAI_API_VERSION=placeholder
13 changes: 0 additions & 13 deletions Dockerfile

This file was deleted.

36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,42 @@ yarn dev

Navigate to [http://localhost:5173/](http://localhost:5173/) and enjoy!

## Installation and Running with Docker

This project supports a Docker-based setup, streamlining installation and execution. It automatically builds images for the frontend and backend and sets up Redis using docker-compose.

### Quick Start

1. **Clone the Repository:**
Obtain the project files by cloning the repository.
```
git clone https://github.com/langchain-ai/opengpts.git
cd opengpts
```

2. **Run with Docker Compose:**
In the root directory of the project, execute:
```
docker compose up
```
This command builds the Docker images for the frontend and backend from their respective Dockerfiles and starts all necessary services, including Redis.

3. **Access the Application:**
With the services running, access the frontend at [http://localhost:5173](http://localhost:5173), substituting `5173` with the designated port number.

4. **Rebuilding After Changes:**
If you make changes to either the frontend or backend, rebuild the Docker images to reflect these changes. Run:
```
docker-compose up --build
```
This command rebuilds the images with your latest changes and restarts the services.

### Note
- Ensure Docker and docker-compose are installed on your system.
- Adjust the `.env` file as required for specific environment configurations.

---

## Features

As much as possible, we are striving for feature parity with OpenAI.
Expand Down
16 changes: 16 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Backend Dockerfile
FROM python:3.11

# Install system dependencies
RUN apt-get update && apt-get install -y libmagic1 && rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /backend

COPY ./backend .

RUN rm poetry.lock

RUN pip install .

CMD exec uvicorn app.server:app --host 0.0.0.0 --port $PORT
16 changes: 3 additions & 13 deletions backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tiktoken = "^0.5.1"
langchain = ">=0.0.338"
permchain = ">=0.0.8"
pydantic = "<2.0"
python-magic = "^0.4.27"

[tool.poetry.group.dev.dependencies]
uvicorn = "^0.23.2"
Expand Down
24 changes: 16 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@ version: '3'

services:
redis:
image: redislabs/redisearch:latest
container_name: redis
# Export the port that the service is listening on.
expose:
- "6379"
image: redislabs/redisearch:latest
ports:
- "6379:6379"
volumes:
- ./redis-volume:/data
backend:
build:
context: . # Use the current directory as the build context
dockerfile: Dockerfile # Specify the custom Dockerfile
context: .
dockerfile: backend/Dockerfile
ports:
- "8100:8100"
- "8100:8100" # Backend is accessible on localhost:8100
depends_on:
- redis
env_file:
- .env # Use the .env file to load environment variables
- .env
environment:
PORT: 8100
REDIS_URL: "redis://redis:6379"

frontend:
build:
context: .
dockerfile: frontend/Dockerfile
ports:
- "5173:5173" # Frontend is accessible on localhost:5173
environment:
VITE_BACKEND_URL: "http://backend:8100"
21 changes: 21 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Frontend Dockerfile
FROM node:16

# Set the working directory
WORKDIR /frontend

# Copy the package.json and yarn.lock
COPY ./frontend/package.json ./
COPY ./frontend/yarn.lock ./

# Install Yarn and dependencies
RUN yarn install

# Copy the rest of the frontend code
COPY ./frontend .

# Expose the port the frontend runs on
EXPOSE 5173

# Command to start the frontend
CMD ["yarn", "dev"]
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite --host",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --host option allows the server to be accessed over the network, not just localhost. it's necessary when running via docker.
When running without --host and exposing the port from the container to the local machine we weren't able to see the output. With that argument, the Frontend was exposed.

"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
Expand Down
2 changes: 1 addition & 1 deletion frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({
server: {
proxy: {
"^/(assistants|threads|ingest|runs)": {
target: "http://127.0.0.1:8100",
target: process.env.VITE_BACKEND_URL || "http://127.0.0.1:8100",
changeOrigin: true,
rewrite: (path) => path.replace("/____LANGSERVE_BASE_URL", ""),
},
Expand Down