File size: 2,797 Bytes
f711f7f
 
 
 
 
 
 
802c885
f711f7f
 
802c885
f711f7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9f3d4f0
 
f711f7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
02384fe
f711f7f
 
 
 
 
 
 
9f3d4f0
 
f711f7f
 
 
 
 
 
 
 
aa291c4
9f3d4f0
f711f7f
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
FROM node:20-bookworm-slim AS frontend-builder

WORKDIR /build/main

ENV NEXT_TELEMETRY_DISABLED=1
ARG NEXT_PUBLIC_API_BASE_URL=""
ARG NEXT_INTERNAL_API_PROXY_TARGET="http://127.0.0.1:8000"
ARG NEXT_PUBLIC_GOOGLE_CLIENT_ID=""
ENV NEXT_PUBLIC_API_BASE_URL=${NEXT_PUBLIC_API_BASE_URL}
ENV NEXT_INTERNAL_API_PROXY_TARGET=${NEXT_INTERNAL_API_PROXY_TARGET}
ENV NEXT_PUBLIC_GOOGLE_CLIENT_ID=${NEXT_PUBLIC_GOOGLE_CLIENT_ID}

COPY main/package.json main/package-lock.json ./
RUN npm ci

COPY main ./
RUN npm run build && npm prune --omit=dev

FROM node:20-bookworm-slim

WORKDIR /app

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
ENV PORT=7860
ENV PATH="/opt/venv/bin:${PATH}"
ENV HF_HOME=/app/.cache/huggingface
ENV HUGGINGFACE_HUB_CACHE=/app/.cache/huggingface/hub

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        build-essential \
        ca-certificates \
        curl \
        ffmpeg \
        git \
        libcairo2 \
        libffi-dev \
        libgomp1 \
        libsndfile1 \
        nginx \
        python3 \
        python3-dev \
        python3-pip \
        python3-venv \
    && rm -rf /var/lib/apt/lists/*

RUN python3 -m venv /opt/venv

COPY api/api-gateway/requirements.txt /tmp/api-gateway-requirements.txt
COPY api/auth-service/requirements.txt /tmp/auth-service-requirements.txt
COPY api/ai-service/requirements.txt /tmp/ai-service-requirements.txt

RUN pip install --no-cache-dir --upgrade pip wheel "setuptools<81" \
    && pip install --no-cache-dir --index-url https://download.pytorch.org/whl/cpu torch torchaudio \
    && pip install --no-cache-dir \
        -r /tmp/api-gateway-requirements.txt \
        -r /tmp/auth-service-requirements.txt \
        -r /tmp/ai-service-requirements.txt \
    && python -c "from pathlib import Path; import unidic, unidic_lite; target = Path(unidic_lite.__file__).parent / 'dicdir'; link = Path(unidic.__file__).parent / 'dicdir'; link.exists() or link.symlink_to(target, target_is_directory=True)"

RUN python -c "from transformers import CLIPModel, CLIPProcessor; model='openai/clip-vit-base-patch32'; CLIPModel.from_pretrained(model); CLIPProcessor.from_pretrained(model)"

COPY api /app/api
COPY router /app/router
COPY --from=frontend-builder /build/main /app/main
COPY deploy/huggingface/nginx.conf /etc/nginx/nginx.conf
COPY deploy/huggingface/start-hf.sh /app/start-hf.sh

RUN chmod +x /app/start-hf.sh \
    && mkdir -p \
        /app/ai \
        /app/.cache/huggingface \
        /app/router/ai/public/generated_routes \
        /tmp/nginx-client-body \
        /tmp/nginx-proxy \
        /tmp/nginx-fastcgi \
        /tmp/nginx-uwsgi \
        /tmp/nginx-scgi \
        /tmp/runnimal-tts-cache

EXPOSE 7860

CMD ["/app/start-hf.sh"]