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

feat: 🎸 docker reduced size by 2 #1653

Merged
merged 1 commit into from
Nov 18, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ backend/bin/*
backend/lib/*
backend/pyvenv.cfg
backend/share/*
backend/slim.report.json
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ test:
pytest -s backend/tests

dev:
docker compose -f docker-compose.dev.yml build backend-core
docker compose -f docker-compose.dev.yml up --build

prod:
Expand Down
10 changes: 10 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**/__pycache__
*/.pytest_cache
**/__pycache__
**/.benchmarks/
**/.cache/
**/.pytest_cache/
**/.next/
**/build/
**/.docusaurus/
**/node_modules/
11 changes: 6 additions & 5 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# Using a slim version for a smaller base image
FROM python:3.11-slim-bullseye
FROM python:3.11.6-slim-bullseye

ARG DEV_MODE
ENV DEV_MODE=$DEV_MODE

# Install GEOS library, Rust, and other dependencies, then clean up
RUN apt-get update && apt-get install -y \
RUN apt-get clean && apt-get update && apt-get install -y \
libgeos-dev \
libcurl4-openssl-dev \
libssl-dev \
pandoc \
binutils \
pandoc \
curl \
git \
build-essential && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
rm -rf /var/lib/apt/lists/* && apt-get clean

# Add Rust binaries to the PATH
Expand All @@ -36,4 +35,6 @@ RUN if [ "$DEV_MODE" = "true" ]; then pip install --no-cache debugpy --timeout 2
# Copy the rest of the application
COPY . .

CMD ["uvicorn", "main:app", "--reload", "--host", "0.0.0.0", "--port", "5050", "--workers", "6"]
EXPOSE 5050

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5050", "--workers", "6"]
40 changes: 40 additions & 0 deletions backend/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Using a slim version for a smaller base image
FROM python:3.11.6-slim-bullseye

ARG DEV_MODE
ENV DEV_MODE=$DEV_MODE

# Install GEOS library, Rust, and other dependencies, then clean up
RUN apt-get clean && apt-get update && apt-get install -y \
libgeos-dev \
libcurl4-openssl-dev \
libssl-dev \
binutils \
pandoc \
curl \
git \
build-essential && \
rm -rf /var/lib/apt/lists/* && apt-get clean

# Add Rust binaries to the PATH
ENV PATH="/root/.cargo/bin:${PATH}"

WORKDIR /code

# Copy just the requirements first
COPY ./requirements.txt .

# Upgrade pip
RUN pip install --upgrade pip

# Increase timeout to wait for the new installation
RUN pip install --no-cache-dir -r requirements.txt --timeout 200

RUN if [ "$DEV_MODE" = "true" ]; then pip install --no-cache debugpy --timeout 200; fi

# Copy the rest of the application
COPY . .

EXPOSE 5050

CMD ["uvicorn", "main:app","--reload", "--host", "0.0.0.0", "--port", "5050", "--workers", "6"]
9 changes: 4 additions & 5 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from dotenv import load_dotenv # type: ignore

load_dotenv()
import pypandoc
import sentry_sdk
from fastapi import FastAPI, HTTPException
from fastapi.responses import JSONResponse
Expand Down Expand Up @@ -50,10 +49,10 @@
add_cors_middleware(app)


@app.on_event("startup")
async def startup_event():
if not os.path.exists(pypandoc.get_pandoc_path()):
pypandoc.download_pandoc()
# @app.on_event("startup")
# async def startup_event():
# if not os.path.exists(pypandoc.get_pandoc_path()):
# pypandoc.download_pandoc()


app.include_router(brain_router)
Expand Down
10 changes: 3 additions & 7 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
pymupdf==1.22.3
# pymupdf==1.22.3
langchain==0.0.332
litellm==0.13.2
Markdown==3.4.4
# Markdown==3.4.4
openai==0.27.8
GitPython==3.1.36
pdf2image==1.16.3
pypdf==3.9.0
StrEnum==0.4.15
supabase==1.1.0
tiktoken==0.4.0
unstructured==0.6.7
fastapi==0.95.2
python-multipart==0.0.6
uvicorn==0.22.0
pypandoc==1.11

docx2txt==0.8
python-jose==3.3.0
transformers==4.30.1
asyncpg==0.27.0
flake8==6.0.0
flake8-black==0.3.6
sentence_transformers>=2.0.0
sentry-sdk==1.26.0
pyright==1.1.316
resend==0.5.1
psycopg2-binary==2.9.6
sqlalchemy==2.0.19
html5lib==1.1
beautifulsoup4
newspaper3k
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
- ./backend/.env
build:
context: backend
dockerfile: Dockerfile
dockerfile: Dockerfile.dev
args:
- DEV_MODE=true
container_name: backend-core
Expand All @@ -49,7 +49,7 @@ services:
- ./backend/.env
build:
context: backend
dockerfile: Dockerfile
dockerfile: Dockerfile.dev
container_name: worker
command: celery -A celery_worker worker -l info
restart: unless-stopped
Expand All @@ -64,7 +64,7 @@ services:
- ./backend/.env
build:
context: backend
dockerfile: Dockerfile
dockerfile: Dockerfile.dev
container_name: flower
command: celery -A celery_worker flower -l info --port=5555
restart: unless-stopped
Expand Down
8 changes: 0 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ services:
dockerfile: Dockerfile
container_name: backend-core
restart: always
volumes:
- ./backend/:/code/
depends_on:
- redis
- worker
Expand All @@ -49,8 +47,6 @@ services:
restart: always
depends_on:
- redis
volumes:
- ./backend/:/code/

beat:
image: backend-base
Expand All @@ -64,8 +60,6 @@ services:
restart: always
depends_on:
- redis
volumes:
- ./backend/:/code/

flower:
image: backend-base
Expand All @@ -77,8 +71,6 @@ services:
container_name: flower
command: celery -A celery_worker flower -l info --port=5555
restart: always
volumes:
- ./backend/:/code/
depends_on:
- redis
- worker
Expand Down
15 changes: 13 additions & 2 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
.next/
node_modules/
**/.next/
**/node_modules/
**/.vercel/
**/__pycache__
*/.pytest_cache
**/__pycache__
**/.benchmarks/
**/.cache/
**/.pytest_cache/
**/.next/
**/build/
**/.docusaurus/
**/node_modules/
38 changes: 10 additions & 28 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,49 +1,31 @@
# First stage: Build environment
FROM node:18.13.0-alpine as builder

FROM node:18.13.0-alpine
# Install Python and essential build tools
RUN apk add --update --no-cache python3 make g++ && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools

# Create a Python virtual environment
RUN python3 -m venv /venv
ENV PATH="/venv/bin:$PATH"

# Create the directory where our app will live
# Create the directory on the node image
# where our Next.js app will live
RUN mkdir -p /app

# Set /app as the working directory
WORKDIR /app

# Copy package.json and yarn.lock to the working directory
# Copy package.json and yarn.lock
# to the /app working directory
COPY package*.json yarn.lock ./

# Install Node.js dependencies
# Install dependencies in /app
RUN yarn install --network-timeout 1000000

# Copy the rest of the Next.js folder into /app
# Copy the rest of our Next.js folder into /app
COPY . .

# Build the Next.js application
RUN yarn build

# Second stage: Runtime environment
FROM node:18.13.0-alpine

# Copy the virtual environment from the builder stage
COPY --from=builder /venv /venv
ENV PATH="/venv/bin:$PATH"

# Set the working directory
WORKDIR /app

# Copy built assets from the builder stage
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/public ./public

# Ensure port 3000 is accessible to our system
EXPOSE 3000

# Run yarn start, as we would via the command line
# Run yarn start, as we would via the command line
CMD ["yarn", "start"]
Loading