Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Add AnythingLLM Docker configuration
Browse files- Dockerfile +155 -38
Dockerfile
CHANGED
@@ -1,38 +1,155 @@
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Setup base image
|
2 |
+
FROM ubuntu:jammy-20230522 AS base
|
3 |
+
|
4 |
+
ARG ARG_UID=1000
|
5 |
+
ARG ARG_GID=1000
|
6 |
+
|
7 |
+
FROM base AS build-arm64
|
8 |
+
RUN echo "Preparing build of AnythingLLM image for arm64 architecture"
|
9 |
+
|
10 |
+
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
|
11 |
+
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
|
12 |
+
unzip curl gnupg libgfortran5 libgbm1 tzdata netcat \
|
13 |
+
libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 \
|
14 |
+
libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libx11-6 libx11-xcb1 libxcb1 \
|
15 |
+
libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 \
|
16 |
+
libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release \
|
17 |
+
xdg-utils git build-essential ffmpeg && \
|
18 |
+
mkdir -p /etc/apt/keyrings && \
|
19 |
+
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
|
20 |
+
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
|
21 |
+
apt-get update && \
|
22 |
+
apt-get install -yq --no-install-recommends nodejs && \
|
23 |
+
curl -LO https://github.com/yarnpkg/yarn/releases/download/v1.22.19/yarn_1.22.19_all.deb \
|
24 |
+
&& dpkg -i yarn_1.22.19_all.deb \
|
25 |
+
&& rm yarn_1.22.19_all.deb
|
26 |
+
|
27 |
+
# Create a group and user with specific UID and GID
|
28 |
+
RUN groupadd -g $ARG_GID anythingllm && \
|
29 |
+
useradd -u $ARG_UID -m -d /app -s /bin/bash -g anythingllm anythingllm && \
|
30 |
+
mkdir -p /app/frontend/ /app/server/ /app/collector/ && chown -R anythingllm:anythingllm /app
|
31 |
+
|
32 |
+
# Copy docker helper scripts
|
33 |
+
COPY ./docker/docker-entrypoint.sh /usr/local/bin/
|
34 |
+
COPY ./docker/docker-healthcheck.sh /usr/local/bin/
|
35 |
+
COPY --chown=anythingllm:anythingllm ./docker/.env.example /app/server/.env
|
36 |
+
|
37 |
+
# Ensure the scripts are executable
|
38 |
+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh && \
|
39 |
+
chmod +x /usr/local/bin/docker-healthcheck.sh
|
40 |
+
|
41 |
+
USER anythingllm
|
42 |
+
WORKDIR /app
|
43 |
+
|
44 |
+
# Puppeteer does not ship with an ARM86 compatible build for Chromium
|
45 |
+
# so web-scraping would be broken in arm docker containers unless we patch it
|
46 |
+
# by manually installing a compatible chromedriver.
|
47 |
+
RUN echo "Need to patch Puppeteer x Chromium support for ARM86 - installing dep!" && \
|
48 |
+
curl https://playwright.azureedge.net/builds/chromium/1088/chromium-linux-arm64.zip -o chrome-linux.zip && \
|
49 |
+
unzip chrome-linux.zip && \
|
50 |
+
rm -rf chrome-linux.zip
|
51 |
+
|
52 |
+
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
|
53 |
+
ENV CHROME_PATH=/app/chrome-linux/chrome
|
54 |
+
ENV PUPPETEER_EXECUTABLE_PATH=/app/chrome-linux/chrome
|
55 |
+
|
56 |
+
RUN echo "Done running arm64 specific installtion steps"
|
57 |
+
|
58 |
+
#############################################
|
59 |
+
|
60 |
+
# amd64-specific stage
|
61 |
+
FROM base AS build-amd64
|
62 |
+
RUN echo "Preparing build of AnythingLLM image for non-ARM architecture"
|
63 |
+
|
64 |
+
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
|
65 |
+
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
|
66 |
+
curl gnupg libgfortran5 libgbm1 tzdata netcat \
|
67 |
+
libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 \
|
68 |
+
libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libx11-6 libx11-xcb1 libxcb1 \
|
69 |
+
libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 \
|
70 |
+
libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release \
|
71 |
+
xdg-utils git build-essential ffmpeg && \
|
72 |
+
mkdir -p /etc/apt/keyrings && \
|
73 |
+
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
|
74 |
+
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
|
75 |
+
apt-get update && \
|
76 |
+
apt-get install -yq --no-install-recommends nodejs && \
|
77 |
+
curl -LO https://github.com/yarnpkg/yarn/releases/download/v1.22.19/yarn_1.22.19_all.deb \
|
78 |
+
&& dpkg -i yarn_1.22.19_all.deb \
|
79 |
+
&& rm yarn_1.22.19_all.deb
|
80 |
+
|
81 |
+
# Create a group and user with specific UID and GID
|
82 |
+
RUN groupadd -g $ARG_GID anythingllm && \
|
83 |
+
useradd -u $ARG_UID -m -d /app -s /bin/bash -g anythingllm anythingllm && \
|
84 |
+
mkdir -p /app/frontend/ /app/server/ /app/collector/ && chown -R anythingllm:anythingllm /app
|
85 |
+
|
86 |
+
# Copy docker helper scripts
|
87 |
+
COPY ./docker/docker-entrypoint.sh /usr/local/bin/
|
88 |
+
COPY ./docker/docker-healthcheck.sh /usr/local/bin/
|
89 |
+
COPY --chown=anythingllm:anythingllm ./docker/.env.example /app/server/.env
|
90 |
+
|
91 |
+
# Ensure the scripts are executable
|
92 |
+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh && \
|
93 |
+
chmod +x /usr/local/bin/docker-healthcheck.sh
|
94 |
+
|
95 |
+
#############################################
|
96 |
+
# COMMON BUILD FLOW FOR ALL ARCHS
|
97 |
+
#############################################
|
98 |
+
FROM build-${TARGETARCH} AS build
|
99 |
+
RUN echo "Running common build flow of AnythingLLM image for all architectures"
|
100 |
+
|
101 |
+
USER anythingllm
|
102 |
+
WORKDIR /app
|
103 |
+
|
104 |
+
# Install frontend dependencies
|
105 |
+
FROM build as frontend-deps
|
106 |
+
|
107 |
+
COPY ./frontend/package.json ./frontend/yarn.lock ./frontend/
|
108 |
+
RUN cd ./frontend/ && yarn install --network-timeout 100000 && yarn cache clean
|
109 |
+
|
110 |
+
# Install server dependencies
|
111 |
+
FROM build as server-deps
|
112 |
+
COPY ./server/package.json ./server/yarn.lock ./server/
|
113 |
+
RUN cd ./server/ && yarn install --production --network-timeout 100000 && yarn cache clean
|
114 |
+
|
115 |
+
# Compile Llama.cpp bindings for node-llama-cpp for this operating system.
|
116 |
+
USER root
|
117 |
+
RUN cd ./server && npx --no node-llama-cpp download
|
118 |
+
USER anythingllm
|
119 |
+
|
120 |
+
# Build the frontend
|
121 |
+
FROM frontend-deps as build-stage
|
122 |
+
COPY ./frontend/ ./frontend/
|
123 |
+
RUN cd ./frontend/ && yarn build && yarn cache clean
|
124 |
+
|
125 |
+
# Setup the server
|
126 |
+
FROM server-deps as production-stage
|
127 |
+
COPY --chown=anythingllm:anythingllm ./server/ ./server/
|
128 |
+
|
129 |
+
# Copy built static frontend files to the server public directory
|
130 |
+
COPY --from=build-stage /app/frontend/dist ./server/public
|
131 |
+
|
132 |
+
# Copy the collector
|
133 |
+
COPY --chown=anythingllm:anythingllm ./collector/ ./collector/
|
134 |
+
|
135 |
+
# Install collector dependencies
|
136 |
+
ENV PUPPETEER_DOWNLOAD_BASE_URL=https://storage.googleapis.com/chrome-for-testing-public
|
137 |
+
RUN cd /app/collector && yarn install --production --network-timeout 100000 && yarn cache clean
|
138 |
+
|
139 |
+
# Migrate and Run Prisma against known schema
|
140 |
+
RUN cd ./server && npx prisma generate --schema=./prisma/schema.prisma
|
141 |
+
RUN cd ./server && npx prisma migrate deploy --schema=./prisma/schema.prisma
|
142 |
+
|
143 |
+
# Setup the environment
|
144 |
+
ENV NODE_ENV=production
|
145 |
+
ENV ANYTHING_LLM_RUNTIME=docker
|
146 |
+
|
147 |
+
# Expose the server port
|
148 |
+
EXPOSE 3001
|
149 |
+
|
150 |
+
# Setup the healthcheck
|
151 |
+
HEALTHCHECK --interval=1m --timeout=10s --start-period=1m \
|
152 |
+
CMD /bin/bash /usr/local/bin/docker-healthcheck.sh || exit 1
|
153 |
+
|
154 |
+
# Run the server
|
155 |
+
ENTRYPOINT ["/bin/bash", "/usr/local/bin/docker-entrypoint.sh"]
|