Skip to content

Commit

Permalink
fix docker builds (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
emrgnt-cmplxty authored Aug 23, 2024
1 parent 8ad54be commit d603a6b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
7 changes: 6 additions & 1 deletion py/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ COPY . /app

# Ensure that the working directory is set to /app/py
WORKDIR /app/py
COPY scripts /app/py/scripts

# Install dependencies
RUN poetry config virtualenvs.create false \
&& poetry install --extras "core" --no-dev --no-root \
&& pip install --no-cache-dir gunicorn uvicorn
&& pip install --no-cache-dir gunicorn uvicorn \
&& poetry run python scripts/download_nltk_data.py



# Final stage to keep the image small
FROM python:3.10-slim
Expand All @@ -36,6 +40,7 @@ WORKDIR /app
# Copy the installed packages from the builder
COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
COPY --from=builder /root/nltk_data /root/nltk_data

# Copy the necessary application files
COPY core /app/core
Expand Down
5 changes: 4 additions & 1 deletion py/Dockerfile.unstructured
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
ENV PATH="/root/.cargo/bin:${PATH}"

WORKDIR /app
COPY scripts /app/py/scripts

RUN pip install --no-cache-dir poetry

Expand All @@ -23,7 +24,8 @@ RUN poetry config virtualenvs.create false \
&& poetry install --extras "core" --no-dev --no-root \
&& poetry add "unstructured[all-docs]" \
&& poetry add "unstructured_client" \
&& pip install --no-cache-dir gunicorn uvicorn
&& pip install --no-cache-dir gunicorn uvicorn \
&& poetry run python scripts/download_nltk_data.py

# Create the final image
FROM python:3.10-slim
Expand All @@ -40,6 +42,7 @@ WORKDIR /app/py
# Copy the installed packages from the builder
COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
COPY --from=builder /root/nltk_data /root/nltk_data

# Copy the application and config
COPY py/core /app/py/core
Expand Down
2 changes: 1 addition & 1 deletion py/core/providers/database/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GroupMixin(DatabaseMixin):
def create_table(self) -> None:
query = f"""
CREATE TABLE IF NOT EXISTS {self._get_table_name('groups')} (
group_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
group_id UUID PRIMARY KEY DEFAULT public.uuid_generate_v4(),
name TEXT NOT NULL,
description TEXT,
created_at TIMESTAMPTZ DEFAULT NOW(),
Expand Down
12 changes: 5 additions & 7 deletions py/core/providers/database/relational.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ def execute_query(self, query, params=None):
def _initialize_relational_db(self):
with self.vx.Session() as sess:
with sess.begin():
try:
sess.execute(
text('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";')
)
except exc.ProgrammingError as e:
logger.error(f"Error enabling uuid-ossp extension: {e}")
raise
sess.execute(
text('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";')
)
sess.commit()

with sess.begin():
# Call create_table for each mixin
for base_class in self.__class__.__bases__:
if issubclass(base_class, DatabaseMixin):
Expand Down
2 changes: 1 addition & 1 deletion py/core/providers/database/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BlacklistedTokensMixin(DatabaseMixin):
def create_table(self):
query = f"""
CREATE TABLE IF NOT EXISTS {self._get_table_name('blacklisted_tokens')} (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
id UUID PRIMARY KEY DEFAULT public.uuid_generate_v4(),
token TEXT NOT NULL,
blacklisted_at TIMESTAMPTZ DEFAULT NOW()
);
Expand Down
2 changes: 1 addition & 1 deletion py/core/providers/database/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UserMixin(DatabaseMixin):
def create_table(self):
query = f"""
CREATE TABLE IF NOT EXISTS {self._get_table_name('users')} (
user_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
user_id UUID PRIMARY KEY DEFAULT public.uuid_generate_v4(),
email TEXT UNIQUE NOT NULL,
hashed_password TEXT NOT NULL,
is_superuser BOOLEAN DEFAULT FALSE,
Expand Down
2 changes: 1 addition & 1 deletion py/r2r/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
__all__ += core.__all__
except ImportError:
# Core dependencies not installed
pass
pass

0 comments on commit d603a6b

Please sign in to comment.