mirror of
https://github.com/serge-chat/serge.git
synced 2024-01-15 09:32:12 +03:00
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:
committed by
GitHub
parent
a641860228
commit
da8c3e27d3
@@ -25,6 +25,9 @@ npm-debug.log
|
||||
.aws
|
||||
|
||||
**/.ruff_cache/
|
||||
**/node_modules/
|
||||
**/dist
|
||||
**/.mypy_cache/
|
||||
__pycache__
|
||||
*.pyc
|
||||
*.pyo
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,3 +11,4 @@ api/static/*
|
||||
**/.ruff_cache/
|
||||
**/node_modules/
|
||||
**/dist
|
||||
**/.mypy_cache/
|
||||
|
||||
34
Dockerfile
34
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
|
||||
|
||||
41
Dockerfile.dev
Normal file
41
Dockerfile.dev
Normal 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
|
||||
@@ -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
|
||||
```
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
appendonly yes
|
||||
dir /data/db/
|
||||
@@ -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/
|
||||
|
||||
Reference in New Issue
Block a user