Refactor production Dockerfile, Add development Dockerfile (#485)

* Refactor Dockerfile, add Dockerfile.dev for development

* We need dev dependencies for running vite build
This commit is contained in:
Juan Calderon-Perez
2023-07-01 22:47:29 -04:00
committed by GitHub
parent a641860228
commit da8c3e27d3
8 changed files with 63 additions and 31 deletions

View File

@@ -25,6 +25,9 @@ npm-debug.log
.aws .aws
**/.ruff_cache/ **/.ruff_cache/
**/node_modules/
**/dist
**/.mypy_cache/
__pycache__ __pycache__
*.pyc *.pyc
*.pyo *.pyo

1
.gitignore vendored
View File

@@ -11,3 +11,4 @@ api/static/*
**/.ruff_cache/ **/.ruff_cache/
**/node_modules/ **/node_modules/
**/dist **/dist
**/.mypy_cache/

View File

@@ -2,8 +2,6 @@
# Base image for node # Base image for node
FROM node:19-bullseye-slim as node_base FROM node:19-bullseye-slim as node_base
WORKDIR /usr/src/app
# --------------------------------------- # ---------------------------------------
# Base image for runtime # Base image for runtime
FROM python:3.11-slim-bullseye as base 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 \ && 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 update \
&& apt-get install -y redis \ && apt-get install -y redis \
&& apt-get clean \
&& mkdir -p /etc/redis /var/redis \ && mkdir -p /etc/redis /var/redis \
&& pip install --upgrade pip && pip install --upgrade pip \
&& echo "appendonly yes" >> /etc/redis/redis.conf \
# Add redis config && echo "dir /data/db/" >> /etc/redis/redis.conf
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
# --------------------------------------- # ---------------------------------------
# Build frontend # Build frontend
FROM node_base as frontend_builder 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 RUN npm ci
COPY ./web /usr/src/app/web/ COPY ./web /usr/src/app/web/
@@ -52,14 +38,18 @@ RUN npm run build
# Runtime environment # Runtime environment
FROM base as release FROM base as release
# Set ENV
ENV NODE_ENV='production' ENV NODE_ENV='production'
WORKDIR /usr/src/app WORKDIR /usr/src/app
# Copy artifacts
COPY --from=frontend_builder /usr/src/app/web/build /usr/src/app/api/static/ COPY --from=frontend_builder /usr/src/app/web/build /usr/src/app/api/static/
COPY ./api /usr/src/app/api 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 EXPOSE 8008
CMD ./deploy.sh CMD ./deploy.sh

41
Dockerfile.dev Normal file
View File

@@ -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

View File

@@ -186,5 +186,5 @@ To run Serge in development mode:
```bash ```bash
git clone https://github.com/serge-chat/serge.git 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
``` ```

View File

@@ -1,9 +1,9 @@
import json import json
import requests from pathlib import Path
import huggingface_hub import huggingface_hub
import pytest import pytest
import requests
from pathlib import Path
# this test file specifically doesn't start with test_* so it's not picked up by pytest # this test file specifically doesn't start with test_* so it's not picked up by pytest

View File

@@ -1,2 +0,0 @@
appendonly yes
dir /data/db/

View File

@@ -3,8 +3,7 @@ services:
restart: on-failure restart: on-failure
build: build:
context: . context: .
dockerfile: Dockerfile dockerfile: Dockerfile.dev
target: dev
volumes: volumes:
- ./web:/usr/src/app/web/ - ./web:/usr/src/app/web/
- ./api:/usr/src/app/api/ - ./api:/usr/src/app/api/
@@ -16,4 +15,4 @@ services:
volumes: volumes:
datadb: datadb:
weights: weights: