File size: 4,073 Bytes
1f8e638
 
 
 
 
 
 
df1355c
 
 
1f8e638
 
 
 
 
 
 
 
 
 
 
 
591adff
1f8e638
 
 
 
 
5db5d3c
1f8e638
 
 
 
 
e619fa7
d65b144
e2e7175
7bd2d15
 
baac152
e619fa7
ad3f5aa
 
c569261
e619fa7
 
 
 
 
 
d65b144
f8eab18
 
e2e7175
7bd2d15
 
baac152
e619fa7
 
1f8e638
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e619fa7
1f8e638
 
5db5d3c
 
 
 
1f8e638
5db5d3c
1f8e638
5db5d3c
 
 
1f8e638
5db5d3c
1f8e638
e619fa7
1f8e638
14ca325
df1355c
14ca325
5db5d3c
 
 
 
 
 
 
 
 
1f8e638
 
e619fa7
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
ARG MODEL_NAME
ARG MODEL_PROMPT_TEMPLATE
ARG APP_COLOR
ARG APP_NAME


FROM node:20 as chatui-builder

ENV PLAYWRIGHT_SKIP_BROWSER_GC=1

ARG MODEL_NAME
ARG APP_COLOR
ARG APP_NAME
ARG MODEL_PROMPT_TEMPLATE

WORKDIR /app

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
    git gettext && \
    rm -rf /var/lib/apt/lists/*


RUN git clone https://github.com/langtech-bsc/chat-ui.git --branch production

WORKDIR /app/chat-ui


COPY .env.local.template .env.local.template
COPY PRIVACY.md PRIVACY.md

RUN mkdir defaults
ADD defaults /defaults
RUN chmod -R 777 /defaults
RUN --mount=type=secret,id=MONGODB_URL,mode=0444 \
    --mount=type=secret,id=BASEURL,mode=0444 \
    --mount=type=secret,id=BASEURL_2b,mode=0444 \
    --mount=type=secret,id=BASEURL_SALAMANDRA_TOOLS,mode=0444 \
    --mount=type=secret,id=BASEURL_SALAMANDRA7B_TOOLS_V2,mode=0444 \
    --mount=type=secret,id=BASEURL_SALAMANDRA2B_TOOLS,mode=0444 \
    --mount=type=secret,id=BASEURL_ALIA40B,mode=0444 \
    --mount=type=secret,id=HF_TOKEN,mode=0444 \
    --mount=type=secret,id=HF_ORG_ADMIN,mode=0444 \
    --mount=type=secret,id=OPENID_CONFIG,mode=0444 \
    --mount=type=secret,id=SEARXNG_QUERY_URL,mode=0444 \
    export MODEL_NAME="${MODEL_NAME:=$(cat /defaults/MODEL_NAME)}" \
    && export MODEL_PROMPT_TEMPLATE="${MODEL_PROMPT_TEMPLATE:=$(cat /defaults/MODEL_PROMPT_TEMPLATE)}" \
    && export APP_COLOR="${APP_COLOR:=$(cat /defaults/APP_COLOR)}" \
    && export APP_NAME="${APP_NAME:=$(cat /defaults/APP_NAME)}" \
    && export MONGODB_URL=$(cat /run/secrets/MONGODB_URL | grep '^') \
    && export BASEURL=$(cat /run/secrets/BASEURL | grep '^') \
    && export BASEURL_2b=$(cat /run/secrets/BASEURL_2b | grep '^') \
    && export HF_ORG_ADMIN=$(cat /run/secrets/HF_ORG_ADMIN | grep '^') \
    && export OPENID_CONFIG=$(cat /run/secrets/OPENID_CONFIG | grep '^') \
    && export BASEURL_SALAMANDRA_TOOLS=$(cat /run/secrets/BASEURL_SALAMANDRA_TOOLS | grep '^') \
    && export BASEURL_SALAMANDRA7B_TOOLS_V2=$(cat /run/secrets/BASEURL_SALAMANDRA7B_TOOLS_V2 | grep '^') \
    && export BASEURL_SALAMANDRA2B_TOOLS=$(cat /run/secrets/BASEURL_SALAMANDRA2B_TOOLS | grep '^') \
    && export BASEURL_ALIA40B=$(cat /run/secrets/BASEURL_ALIA40B | grep '^') \
    && export HF_TOKEN=$(cat /run/secrets/HF_TOKEN | grep '^') \
    && envsubst < ".env.local.template" > ".env.local" \
    && rm .env.local.template


RUN --mount=type=cache,target=/app/.npm \
    npm set cache /app/.npm && \
    npm ci

RUN npm run build

ENV TZ=Europe/Paris \
    PORT=3000

COPY entrypoint.sh.template entrypoint.sh.template

RUN --mount=type=secret,id=MONGODB_URL,mode=0444 \
    MODEL_NAME="${MODEL_NAME:="$(cat /defaults/MODEL_NAME)"}" && export MODEL_NAME \
    && MODEL_PARAMS="${MODEL_PARAMS:="$(cat /defaults/MODEL_PARAMS)"}" && export MODEL_PARAMS \
    && MODEL_PROMPT_TEMPLATE="${MODEL_PROMPT_TEMPLATE:="$(cat /defaults/MODEL_PROMPT_TEMPLATE)"}" && export MODEL_PROMPT_TEMPLATE \
    && APP_COLOR="${APP_COLOR:="$(cat /defaults/APP_COLOR)"}" && export APP_COLOR \
    && APP_NAME="${APP_NAME:="$(cat /defaults/APP_NAME)"}" && export APP_NAME \
    && envsubst < "entrypoint.sh.template" > "entrypoint.sh" \
    && rm entrypoint.sh.template

# Create necessary directories and set permissions
RUN mkdir -p /data/db \
    && chown -R 1000:1000 /data \
    && chown -R 1000:1000 /app

# Add user only if it doesn't already exist

# Set user environment variables
ENV HOME=/home/node \
    PATH=/home/node/.local/bin:$PATH

RUN npm config set prefix /home/node/.local
RUN npm install -g pm2
RUN npm install -g dotenv-cli

# Install Playwright and its dependencies
RUN npx playwright install --with-deps chromium

RUN mv /app/chat-ui/node_modules /app/node_modules
RUN mv /app/chat-ui/package.json /app/package.json
RUN mv /app/chat-ui/build /app/build
RUN mv /app/chat-ui/.env /app/.env
RUN mv /app/chat-ui/.env.local /app/.env.local
RUN mv /app/chat-ui/entrypoint.sh /app/entrypoint.sh
RUN rm -rf /app/chat-ui

WORKDIR /app

ENTRYPOINT ["/bin/bash"]
CMD ["entrypoint.sh"]