diff --git a/.dockerignore b/.dockerignore index de37917..77fc32b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -25,6 +25,9 @@ npm-debug.log .aws **/.ruff_cache/ +**/node_modules/ +**/dist +**/.mypy_cache/ __pycache__ *.pyc *.pyo diff --git a/.gitignore b/.gitignore index aa7ab65..f4c9f98 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ api/static/* **/.ruff_cache/ **/node_modules/ **/dist +**/.mypy_cache/ diff --git a/Dockerfile b/Dockerfile index 2a3b0bf..12be92c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,6 @@ # Base image for node FROM node:19-bullseye-slim as node_base -WORKDIR /usr/src/app - # --------------------------------------- # Base image for runtime FROM python:3.11-slim-bullseye as base @@ -18,30 +16,18 @@ RUN apt-get update \ && echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/redis.list \ && apt-get update \ && apt-get install -y redis \ + && apt-get clean \ && mkdir -p /etc/redis /var/redis \ - && pip install --upgrade pip - -# Add redis config -COPY ./config/redis.conf /etc/redis/redis.conf - -# --------------------------------------- -# Dev environment -FROM base as dev -ENV NODE_ENV='development' - -# Install Node.js and npm packages -COPY --from=node_base /usr/local /usr/local -COPY ./web/package*.json ./ -RUN npm ci - -COPY --chmod=0755 scripts/dev.sh /usr/src/app/dev.sh -CMD ./dev.sh + && pip install --upgrade pip \ + && echo "appendonly yes" >> /etc/redis/redis.conf \ + && echo "dir /data/db/" >> /etc/redis/redis.conf # --------------------------------------- # Build frontend FROM node_base as frontend_builder -COPY ./web/package*.json ./ +WORKDIR /usr/src/app +COPY ./web/package.json ./web/package-lock.json ./ RUN npm ci COPY ./web /usr/src/app/web/ @@ -52,14 +38,18 @@ RUN npm run build # Runtime environment FROM base as release +# Set ENV ENV NODE_ENV='production' WORKDIR /usr/src/app +# Copy artifacts COPY --from=frontend_builder /usr/src/app/web/build /usr/src/app/api/static/ COPY ./api /usr/src/app/api -COPY --chmod=0755 scripts/deploy.sh /usr/src/app/deploy.sh +COPY scripts/deploy.sh /usr/src/app/deploy.sh -RUN pip install --no-cache-dir ./api +# Install api dependencies +RUN pip install --no-cache-dir ./api \ + && chmod 755 /usr/src/app/deploy.sh EXPOSE 8008 CMD ./deploy.sh diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..0d86425 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,41 @@ +# --------------------------------------- +# Base image for node +FROM node:19-bullseye-slim as node_base + +# --------------------------------------- +# Base image for runtime +FROM python:3.11-slim-bullseye as base + +ENV TZ=Etc/UTC +WORKDIR /usr/src/app + +# Install Redis +RUN apt-get update \ + && apt-get install -y curl wget gnupg cmake lsb-release build-essential \ + && curl -fsSL https://packages.redis.io/gpg | gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg \ + && echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/redis.list \ + && apt-get update \ + && apt-get install -y redis \ + && apt-get clean \ + && mkdir -p /etc/redis /var/redis \ + && pip install --upgrade pip \ + && echo "appendonly yes" >> /etc/redis/redis.conf \ + && echo "dir /data/db/" >> /etc/redis/redis.conf + +# --------------------------------------- +# Dev environment +FROM base as dev + +# Set ENV +WORKDIR /usr/src/app +ENV NODE_ENV='development' + +# Install node.js and npm packages +COPY --from=node_base /usr/local /usr/local +COPY scripts/dev.sh /usr/src/app/dev.sh +COPY ./web/package.json ./web/package-lock.json ./ + +RUN npm ci \ + && chmod 755 /usr/src/app/dev.sh + +CMD ./dev.sh diff --git a/README.md b/README.md index 3db6ef1..b14f5d5 100644 --- a/README.md +++ b/README.md @@ -186,5 +186,5 @@ To run Serge in development mode: ```bash git clone https://github.com/serge-chat/serge.git -DOCKER_BUILDKIT=1 docker compose -f docker-compose.dev.yml up -d --build +docker compose -f docker-compose.dev.yml up -d --build ``` diff --git a/api/test/healthcheck_models.py b/api/test/healthcheck_models.py index 0bc09d4..14532d2 100644 --- a/api/test/healthcheck_models.py +++ b/api/test/healthcheck_models.py @@ -1,9 +1,9 @@ import json -import requests +from pathlib import Path + import huggingface_hub import pytest - -from pathlib import Path +import requests # this test file specifically doesn't start with test_* so it's not picked up by pytest diff --git a/config/redis.conf b/config/redis.conf deleted file mode 100644 index f6527d3..0000000 --- a/config/redis.conf +++ /dev/null @@ -1,2 +0,0 @@ -appendonly yes -dir /data/db/ \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index dcc9c7a..1f5fd09 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -3,8 +3,7 @@ services: restart: on-failure build: context: . - dockerfile: Dockerfile - target: dev + dockerfile: Dockerfile.dev volumes: - ./web:/usr/src/app/web/ - ./api:/usr/src/app/api/ @@ -16,4 +15,4 @@ services: volumes: datadb: - weights: \ No newline at end of file + weights: