Skip to content

Commit

Permalink
adding docker changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TransformerOptimus committed May 28, 2023
1 parent cba9c59 commit 41e051f
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 7 deletions.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.9

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .
COPY config.yaml .

CMD ["uvicorn", "main:app", "--host", "0.0.0.0","--port", "8001","--reload"]
11 changes: 11 additions & 0 deletions DockerfileCelery
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.9

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .
COPY config.yaml .

CMD ["celery", "-A", "superagi.worker", "worker", "--loglevel=info"]
14 changes: 14 additions & 0 deletions alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from alembic import context

from superagi.config.config import get_config

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
Expand All @@ -26,6 +28,10 @@
# my_important_option = config.get_main_option("my_important_option")
# ... etc.

database_url = get_config('POSTGRES_URL')
db_username = get_config('DB_USERNAME')
db_password = get_config('DB_PASSWORD')
db_name = get_config('DB_NAME')

def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
Expand All @@ -39,6 +45,14 @@ def run_migrations_offline() -> None:
script output.
"""

if db_username is None:
db_url = f'postgresql://{database_url}/{db_name}'
else:
db_url = f'postgresql://{db_username}:{db_password}@{database_url}/{db_name}'

config.set_main_option("sqlalchemy.url", db_url)

url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
Expand Down
2 changes: 1 addition & 1 deletion config_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ DB_PASSWORD:
MAX_TOOL_TOKEN_LIMIT: 600

# redis details
REDIS_URL: "localhost:6379"
REDIS_URL: "super__redis:6379"
58 changes: 58 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: '3.8'

services:
backend:
volumes:
- "./:/app"
build: .
ports:
- "8001:8001"
depends_on:
- super__redis
- super__postgres
networks:
- super_network

celery:
volumes:
- "./:/app"
build:
context: .
dockerfile: DockerfileCelery
depends_on:
- super__redis
- super__postgres
networks:
- super_network

gui:
build: ./gui
ports:
- "3000:3000"
environment:
- NEXT_PUBLIC_API_BASE_URL=http://localhost:8001
networks:
- super_network

super__redis:
image: "redis:latest"
networks:
- super_network

super__postgres:
image: "postgres:latest"
environment:
- POSTGRES_USER=superagi
- POSTGRES_PASSWORD=password
- POSTGRES_DB=super_agi_main
volumes:
- postgres_data:/var/lib/postgresql/data/
networks:
- super_network

networks:
super_network:
driver: bridge

volumes:
postgres_data:
10 changes: 10 additions & 0 deletions gui/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:lts

WORKDIR /app

COPY package.json .
RUN npm install

COPY . .

CMD ["npm", "run", "dev"]
3 changes: 2 additions & 1 deletion gui/app/DashboardService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from 'axios';
const API_BASE_URL = 'http://localhost:8000'; //for testing

const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:8000'; //for testing
// const API_BASE_URL = 'http://localhost:8001';

export const getOrganization = () => {
Expand Down
5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@

app = FastAPI()

database_url = get_config('POSTGRES_URL')
db_username = get_config('DB_USERNAME')
db_password = get_config('DB_PASSWORD')
db_name = get_config('DB_NAME')

if db_username is None:
db_url = f'postgresql://localhost/{db_name}'
db_url = f'postgresql://{database_url}/{db_name}'
else:
db_url = f'postgresql://{db_username}:{db_password}@localhost/{db_name}'
db_url = f'postgresql://{db_username}:{db_password}@{database_url}/{db_name}'

engine = create_engine(db_url)
# SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Expand Down
8 changes: 5 additions & 3 deletions superagi/models/db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from sqlalchemy import create_engine
from superagi.config.config import get_config

database_url = get_config('POSTGRES_URL')
db_username = get_config('DB_USERNAME')
db_password = get_config('DB_PASSWORD')
db_name = get_config('DB_NAME')
Expand All @@ -14,11 +15,12 @@ def connectDB():
print("Engine returned")
return engine

# Create the connection URL

# Create the connection URL
if db_username is None:
db_url = f'postgresql://localhost/{db_name}'
db_url = f'postgresql://{database_url}/{db_name}'
else:
db_url = f'postgresql://{db_username}:{db_password}@localhost/{db_name}'
db_url = f'postgresql://{db_username}:{db_password}@{database_url}/{db_name}'

# Create the SQLAlchemy engine
engine = create_engine(db_url)
Expand Down

0 comments on commit 41e051f

Please sign in to comment.