Skip to content

Commit

Permalink
fix: minio invalid bucket issue
Browse files Browse the repository at this point in the history
  • Loading branch information
brucechou1983 committed Oct 20, 2024
1 parent 0eeb149 commit 7e88791
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ POSTGRES_DB=chainlit_langgraph
POSTGRES_VOLUME_PATH=

# MinIO
MINIO_BUCKET=chainlit_langraph
MINIO_BUCKET=chainlit_langgraph
MINIO_ENDPOINT_URL=http://minio:9000
MINIO_ACCESS_KEY=chainlit_langraph
MINIO_SECRET_KEY=7fccf63fa5ee99e5f5af2ca4ab1725ea
MINIO_ROOT_USER=chainlit_langgraph
MINIO_ROOT_PASSWORD=chainlit_langgraph
MINIO_VOLUME_PATH=

# LangSmith for LLM Ops
Expand Down
9 changes: 5 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@

pg_url = f"postgresql+asyncpg://{os.getenv('POSTGRES_USER', 'postgres')}:{os.getenv('POSTGRES_PASSWORD', 'postgres')}@{os.getenv('POSTGRES_HOST', 'localhost')}:{os.getenv('POSTGRES_PORT', '5432')}/{os.getenv('POSTGRES_DB', 'postgres')}"


# Persistance Layer
storage_client = MinIOStorageClient(
bucket=os.getenv("MINIO_BUCKET", "chainlit_langgraph"),
endpoint_url=os.getenv("MINIO_ENDPOINT_URL", "http://localhost:9000"),
access_key=os.getenv("MINIO_ACCESS_KEY", "chainlit_langgraph"),
secret_key=os.getenv("MINIO_SECRET_KEY", "chainlit_langgraph"),
bucket=os.getenv("MINIO_BUCKET", "mybucket"),
endpoint_url=os.getenv("MINIO_ENDPOINT_URL", "http://minio:9000"),
access_key=os.getenv("MINIO_ROOT_USER", "chainlit_langgraph"),
secret_key=os.getenv("MINIO_ROOT_PASSWORD", "chainlit_langgraph"),
)
cl_data._data_layer = SQLAlchemyDataLayer(
conninfo=pg_url,
Expand Down
15 changes: 14 additions & 1 deletion chat_workflow/storage_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ def __init__(self, bucket: str, endpoint_url: str, access_key: str, secret_key:
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
)
response = self.client.list_buckets()
existing_buckets = [bucket['Name']
for bucket in response['Buckets']]
logger.info(
f"Successfully connected. Available buckets: {existing_buckets}")

if self.bucket not in existing_buckets:
logger.info(
f"Bucket '{self.bucket}' does not exist. Creating it now.")
self.client.create_bucket(Bucket=self.bucket)
logger.info(f"Bucket '{self.bucket}' created successfully.")
else:
logger.info(f"Bucket '{self.bucket}' already exists.")

logger.info("MinIOStorageClient initialized")
except Exception as e:
logger.warning(f"MinIOStorageClient initialization error: {e}")
Expand All @@ -44,7 +58,6 @@ async def upload_file(
md5_hash = hashlib.md5(data if isinstance(
data, bytes) else data.encode('utf-8')).digest()
extra_args["ContentMD5"] = md5_hash

self.client.put_object(
Bucket=self.bucket, Key=object_key, Body=data, **extra_args
)
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ services:
- .env
environment:
- MINIO_VOLUME_PATH=${MINIO_VOLUME_PATH}
- MINIO_ROOT_USER=${MINIO_ROOT_USER}
- MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD}
command: server /data --console-address ":9001"
ports:
- '9000:9000'
Expand Down

0 comments on commit 7e88791

Please sign in to comment.