Skip to content

Commit 9ce3d11

Browse files
franzbischofftimothycarambat
andauthoredMar 7, 2024
Update Ubuntu base image and improve Dockerfile (Mintplex-Labs#609)
* Update Ubuntu base image and improve Dockerfile * Add unzip to Docker image dependencies Needed for the arm64 build * reset tabs * formalized lint rules for hadolint. however the Docker formatting is being handled by MS Docker extension which doesn't indent code as expected. WIP. * found a workaround to keep formatting --------- Co-authored-by: timothycarambat <rambat1010@gmail.com>
1 parent 5907eb9 commit 9ce3d11

File tree

5 files changed

+62
-30
lines changed

5 files changed

+62
-30
lines changed
 

‎.hadolint.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
failure-threshold: warning
2+
ignored:
3+
- DL3008
4+
- DL3013
5+
format: tty
6+
trustedRegistries:
7+
- docker.io
8+
- gcr.io

‎.vscode/settings.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
"Weaviate",
1919
"Zilliz"
2020
],
21-
"eslint.experimental.useFlatConfig": true
22-
}
21+
"eslint.experimental.useFlatConfig": true,
22+
"docker.languageserver.formatter.ignoreMultilineInstructions": true
23+
}

‎docker/Dockerfile

+40-18
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# Setup base image
2-
FROM ubuntu:jammy-20230522 AS base
2+
FROM ubuntu:jammy-20230916 AS base
33

4+
# Build arguments
45
ARG ARG_UID=1000
56
ARG ARG_GID=1000
67

78
FROM base AS build-arm64
89
RUN echo "Preparing build of AnythingLLM image for arm64 architecture"
910

11+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
12+
13+
# Install system dependencies
14+
# hadolint ignore=DL3008,DL3013
1015
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
1116
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
1217
unzip curl gnupg libgfortran5 libgbm1 tzdata netcat \
@@ -25,8 +30,8 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
2530
&& rm yarn_1.22.19_all.deb
2631

2732
# 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 && \
33+
RUN groupadd -g "$ARG_GID" anythingllm && \
34+
useradd -l -u "$ARG_UID" -m -d /app -s /bin/bash -g anythingllm anythingllm && \
3035
mkdir -p /app/frontend/ /app/server/ /app/collector/ && chown -R anythingllm:anythingllm /app
3136

3237
# Copy docker helper scripts
@@ -61,6 +66,10 @@ RUN echo "Done running arm64 specific installtion steps"
6166
FROM base AS build-amd64
6267
RUN echo "Preparing build of AnythingLLM image for non-ARM architecture"
6368

69+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
70+
71+
# Install system dependencies
72+
# hadolint ignore=DL3008,DL3013
6473
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
6574
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
6675
curl gnupg libgfortran5 libgbm1 tzdata netcat \
@@ -79,8 +88,8 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
7988
&& rm yarn_1.22.19_all.deb
8089

8190
# 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 && \
91+
RUN groupadd -g "$ARG_GID" anythingllm && \
92+
useradd -l -u "$ARG_UID" -m -d /app -s /bin/bash -g anythingllm anythingllm && \
8493
mkdir -p /app/frontend/ /app/server/ /app/collector/ && chown -R anythingllm:anythingllm /app
8594

8695
# Copy docker helper scripts
@@ -95,50 +104,63 @@ RUN chmod +x /usr/local/bin/docker-entrypoint.sh && \
95104
#############################################
96105
# COMMON BUILD FLOW FOR ALL ARCHS
97106
#############################################
107+
108+
# hadolint ignore=DL3006
98109
FROM build-${TARGETARCH} AS build
99110
RUN echo "Running common build flow of AnythingLLM image for all architectures"
100111

101112
USER anythingllm
102113
WORKDIR /app
103114

104115
# Install frontend dependencies
105-
FROM build as frontend-deps
116+
FROM build AS frontend-deps
106117

107118
COPY ./frontend/package.json ./frontend/yarn.lock ./frontend/
108-
RUN cd ./frontend/ && yarn install --network-timeout 100000 && yarn cache clean
119+
WORKDIR /app/frontend
120+
RUN yarn install --network-timeout 100000 && yarn cache clean
121+
WORKDIR /app
109122

110123
# Install server dependencies
111-
FROM build as server-deps
124+
FROM build AS server-deps
112125
COPY ./server/package.json ./server/yarn.lock ./server/
113-
RUN cd ./server/ && yarn install --production --network-timeout 100000 && yarn cache clean
126+
WORKDIR /app/server
127+
RUN yarn install --production --network-timeout 100000 && yarn cache clean
128+
WORKDIR /app
114129

115130
# Compile Llama.cpp bindings for node-llama-cpp for this operating system.
116131
USER root
117-
RUN cd ./server && npx --no node-llama-cpp download
132+
WORKDIR /app/server
133+
RUN npx --no node-llama-cpp download
134+
WORKDIR /app
118135
USER anythingllm
119136

120137
# Build the frontend
121-
FROM frontend-deps as build-stage
138+
FROM frontend-deps AS build-stage
122139
COPY ./frontend/ ./frontend/
123-
RUN cd ./frontend/ && yarn build && yarn cache clean
140+
WORKDIR /app/frontend
141+
RUN yarn build && yarn cache clean
142+
WORKDIR /app
124143

125144
# Setup the server
126-
FROM server-deps as production-stage
145+
FROM server-deps AS production-stage
127146
COPY --chown=anythingllm:anythingllm ./server/ ./server/
128147

129148
# Copy built static frontend files to the server public directory
130-
COPY --from=build-stage /app/frontend/dist ./server/public
149+
COPY --chown=anythingllm:anythingllm --from=build-stage /app/frontend/dist ./server/public
131150

132151
# Copy the collector
133152
COPY --chown=anythingllm:anythingllm ./collector/ ./collector/
134153

135154
# Install collector dependencies
155+
WORKDIR /app/collector
136156
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
157+
RUN yarn install --production --network-timeout 100000 && yarn cache clean
138158

139159
# 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
160+
WORKDIR /app/server
161+
RUN npx prisma generate --schema=./prisma/schema.prisma && \
162+
npx prisma migrate deploy --schema=./prisma/schema.prisma
163+
WORKDIR /app
142164

143165
# Setup the environment
144166
ENV NODE_ENV=production
@@ -152,4 +174,4 @@ HEALTHCHECK --interval=1m --timeout=10s --start-period=1m \
152174
CMD /bin/bash /usr/local/bin/docker-healthcheck.sh || exit 1
153175

154176
# Run the server
155-
ENTRYPOINT ["/bin/bash", "/usr/local/bin/docker-entrypoint.sh"]
177+
ENTRYPOINT ["/bin/bash", "/usr/local/bin/docker-entrypoint.sh"]

‎docker/docker-entrypoint.sh

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/bin/bash
2-
{ cd /app/server/ &&\
3-
npx prisma generate --schema=./prisma/schema.prisma &&\
4-
npx prisma migrate deploy --schema=./prisma/schema.prisma &&\
5-
node /app/server/index.js
2+
{
3+
cd /app/server/ &&
4+
npx prisma generate --schema=./prisma/schema.prisma &&
5+
npx prisma migrate deploy --schema=./prisma/schema.prisma &&
6+
node /app/server/index.js
67
} &
78
{ node /app/collector/index.js; } &
89
wait -n
9-
exit $?
10+
exit $?

‎docker/docker-healthcheck.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
response=$(curl --write-out '%{http_code}' --silent --output /dev/null http://localhost:3001/api/ping)
55

66
# If the HTTP response code is 200 (OK), the server is up
7-
if [ $response -eq 200 ]; then
8-
echo "Server is up"
9-
exit 0
7+
if [ "$response" -eq 200 ]; then
8+
echo "Server is up"
9+
exit 0
1010
else
11-
echo "Server is down"
12-
exit 1
11+
echo "Server is down"
12+
exit 1
1313
fi

0 commit comments

Comments
 (0)
Please sign in to comment.