leowuming commited on
Commit
870808c
·
verified ·
1 Parent(s): 1e03e99

Update docker/Dockerfile

Browse files
Files changed (1) hide show
  1. docker/Dockerfile +27 -180
docker/Dockerfile CHANGED
@@ -1,180 +1,27 @@
1
- # Setup base image
2
- FROM ubuntu:jammy-20240627.1 AS base
3
-
4
- # Build arguments
5
- ARG ARG_UID=1000
6
- ARG ARG_GID=1000
7
-
8
- FROM base AS build-arm64
9
- RUN echo "Preparing build of AnythingLLM image for arm64 architecture"
10
-
11
- SHELL ["/bin/bash", "-o", "pipefail", "-c"]
12
-
13
- # Install system dependencies
14
- # hadolint ignore=DL3008,DL3013
15
- RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
16
- DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
17
- unzip curl gnupg libgfortran5 libgbm1 tzdata netcat \
18
- libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 \
19
- libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libx11-6 libx11-xcb1 libxcb1 \
20
- libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 \
21
- libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release \
22
- xdg-utils git build-essential ffmpeg && \
23
- mkdir -p /etc/apt/keyrings && \
24
- curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
25
- 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 && \
26
- apt-get update && \
27
- # Install node and yarn
28
- apt-get install -yq --no-install-recommends nodejs && \
29
- curl -LO https://github.com/yarnpkg/yarn/releases/download/v1.22.19/yarn_1.22.19_all.deb \
30
- && dpkg -i yarn_1.22.19_all.deb \
31
- && rm yarn_1.22.19_all.deb && \
32
- # Install uvx (pinned to 0.6.10) for MCP support
33
- curl -LsSf https://astral.sh/uv/0.6.10/install.sh | sh && \
34
- mv /root/.local/bin/uv /usr/local/bin/uv && \
35
- mv /root/.local/bin/uvx /usr/local/bin/uvx && \
36
- echo "Installed uvx! $(uv --version)" && \
37
- apt-get clean && \
38
- rm -rf /var/lib/apt/lists/*
39
-
40
- # Create a group and user with specific UID and GID
41
- RUN groupadd -g "$ARG_GID" anythingllm && \
42
- useradd -l -u "$ARG_UID" -m -d /app -s /bin/bash -g anythingllm anythingllm && \
43
- mkdir -p /app/frontend/ /app/server/ /app/collector/ && chown -R anythingllm:anythingllm /app
44
-
45
- # Copy docker helper scripts
46
- COPY ./docker/docker-entrypoint.sh /usr/local/bin/
47
- COPY ./docker/docker-healthcheck.sh /usr/local/bin/
48
- COPY --chown=anythingllm:anythingllm ./docker/.env.example /app/server/.env
49
-
50
- # Ensure the scripts are executable
51
- RUN chmod +x /usr/local/bin/docker-entrypoint.sh && \
52
- chmod +x /usr/local/bin/docker-healthcheck.sh
53
-
54
- USER anythingllm
55
- WORKDIR /app
56
-
57
- # Puppeteer does not ship with an ARM86 compatible build for Chromium
58
- # so web-scraping would be broken in arm docker containers unless we patch it
59
- # by manually installing a compatible chromedriver.
60
- RUN echo "Need to patch Puppeteer x Chromium support for ARM86 - installing dep!" && \
61
- curl https://playwright.azureedge.net/builds/chromium/1088/chromium-linux-arm64.zip -o chrome-linux.zip && \
62
- unzip chrome-linux.zip && \
63
- rm -rf chrome-linux.zip
64
-
65
- ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
66
- ENV CHROME_PATH=/app/chrome-linux/chrome
67
- ENV PUPPETEER_EXECUTABLE_PATH=/app/chrome-linux/chrome
68
-
69
- RUN echo "Done running arm64 specific installation steps"
70
-
71
- #############################################
72
-
73
- # amd64-specific stage
74
- FROM base AS build-amd64
75
- RUN echo "Preparing build of AnythingLLM image for non-ARM architecture"
76
-
77
- SHELL ["/bin/bash", "-o", "pipefail", "-c"]
78
-
79
- # Install system dependencies
80
- # hadolint ignore=DL3008,DL3013
81
- RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
82
- DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
83
- curl gnupg libgfortran5 libgbm1 tzdata netcat \
84
- libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 \
85
- libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libx11-6 libx11-xcb1 libxcb1 \
86
- libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 \
87
- libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release \
88
- xdg-utils git build-essential ffmpeg && \
89
- mkdir -p /etc/apt/keyrings && \
90
- curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
91
- 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 && \
92
- apt-get update && \
93
- # Install node and yarn
94
- apt-get install -yq --no-install-recommends nodejs && \
95
- curl -LO https://github.com/yarnpkg/yarn/releases/download/v1.22.19/yarn_1.22.19_all.deb \
96
- && dpkg -i yarn_1.22.19_all.deb \
97
- && rm yarn_1.22.19_all.deb && \
98
- # Install uvx (pinned to 0.6.10) for MCP support
99
- curl -LsSf https://astral.sh/uv/0.6.10/install.sh | sh && \
100
- mv /root/.local/bin/uv /usr/local/bin/uv && \
101
- mv /root/.local/bin/uvx /usr/local/bin/uvx && \
102
- echo "Installed uvx! $(uv --version)" && \
103
- apt-get clean && \
104
- rm -rf /var/lib/apt/lists/*
105
-
106
- # Create a group and user with specific UID and GID
107
- RUN groupadd -g "$ARG_GID" anythingllm && \
108
- useradd -l -u "$ARG_UID" -m -d /app -s /bin/bash -g anythingllm anythingllm && \
109
- mkdir -p /app/frontend/ /app/server/ /app/collector/ && chown -R anythingllm:anythingllm /app
110
-
111
- # Copy docker helper scripts
112
- COPY ./docker/docker-entrypoint.sh /usr/local/bin/
113
- COPY ./docker/docker-healthcheck.sh /usr/local/bin/
114
- COPY --chown=anythingllm:anythingllm ./docker/.env.example /app/server/.env
115
-
116
- # Ensure the scripts are executable
117
- RUN chmod +x /usr/local/bin/docker-entrypoint.sh && \
118
- chmod +x /usr/local/bin/docker-healthcheck.sh
119
-
120
- #############################################
121
- # COMMON BUILD FLOW FOR ALL ARCHS
122
- #############################################
123
-
124
- # hadolint ignore=DL3006
125
- FROM build-${TARGETARCH} AS build
126
- RUN echo "Running common build flow of AnythingLLM image for all architectures"
127
-
128
- USER anythingllm
129
- WORKDIR /app
130
-
131
- # Install & Build frontend layer
132
- FROM build AS frontend-build
133
- COPY --chown=anythingllm:anythingllm ./frontend /app/frontend/
134
- WORKDIR /app/frontend
135
- RUN yarn install --network-timeout 100000 && yarn cache clean
136
- RUN yarn build && \
137
- cp -r dist /tmp/frontend-build && \
138
- rm -rf * && \
139
- cp -r /tmp/frontend-build dist && \
140
- rm -rf /tmp/frontend-build
141
- WORKDIR /app
142
-
143
- # Install server layer
144
- # Also pull and build collector deps (chromium issues prevent bad bindings)
145
- FROM build AS backend-build
146
- COPY --chown=anythingllm:anythingllm ./server /app/server/
147
- WORKDIR /app/server
148
- RUN yarn install --production --network-timeout 100000 && yarn cache clean
149
- WORKDIR /app
150
-
151
- # Install collector dependencies
152
- COPY --chown=anythingllm:anythingllm ./collector/ ./collector/
153
- WORKDIR /app/collector
154
- ENV PUPPETEER_DOWNLOAD_BASE_URL=https://storage.googleapis.com/chrome-for-testing-public
155
- RUN yarn install --production --network-timeout 100000 && yarn cache clean
156
-
157
- WORKDIR /app
158
- USER anythingllm
159
-
160
- # Since we are building from backend-build we just need to move built frontend into server/public
161
- FROM backend-build AS production-build
162
- WORKDIR /app
163
- COPY --chown=anythingllm:anythingllm --from=frontend-build /app/frontend/dist /app/server/public
164
- USER root
165
- RUN chown -R anythingllm:anythingllm /app/server && \
166
- chown -R anythingllm:anythingllm /app/collector
167
- USER anythingllm
168
-
169
- # Setup the environment
170
- ENV NODE_ENV=production
171
- ENV ANYTHING_LLM_RUNTIME=docker
172
- ENV DEPLOYMENT_VERSION=1.8.5
173
-
174
- # Setup the healthcheck
175
- HEALTHCHECK --interval=1m --timeout=10s --start-period=1m \
176
- CMD /bin/bash /usr/local/bin/docker-healthcheck.sh || exit 1
177
-
178
- # Run the server
179
- # CMD ["sh", "-c", "tail -f /dev/null"] # For development: keep container open
180
- ENTRYPOINT ["/bin/bash", "/usr/local/bin/docker-entrypoint.sh"]
 
1
+ #!/bin/bash
2
+
3
+ # Check if STORAGE_DIR is set
4
+ if [ -z "$STORAGE_DIR" ]; then
5
+ echo "================================================================"
6
+ echo "⚠️ ⚠️ ⚠️ WARNING: STORAGE_DIR environment variable is not set! ⚠️ ⚠️ ⚠️"
7
+ echo ""
8
+ echo "Not setting this will result in data loss on container restart since"
9
+ echo "the application will not have a persistent storage location."
10
+ echo "It can also result in weird errors in various parts of the application."
11
+ echo ""
12
+ echo "Please run the container with the official docker command at"
13
+ echo "https://docs.anythingllm.com/installation-docker/quickstart"
14
+ echo ""
15
+ echo "⚠️ ⚠️ ⚠️ WARNING: STORAGE_DIR environment variable is not set! ⚠️ ⚠️ ⚠️"
16
+ echo "================================================================"
17
+ fi
18
+
19
+ {
20
+ cd /app/server/ &&
21
+ npx prisma generate --schema=./prisma/schema.prisma &&
22
+ npx prisma migrate deploy --schema=./prisma/schema.prisma &&
23
+ node /app/server/index.js
24
+ } &
25
+ { node /app/collector/index.js; } &
26
+ wait -n
27
+ exit $?