You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
7.1 KiB

11 months ago
  1. # Setup base image
  2. FROM ubuntu:jammy-20240627.1 AS base
  3. # Build arguments
  4. ARG ARG_UID=1000
  5. ARG ARG_GID=1000
  6. FROM base AS build-arm64
  7. RUN echo "Preparing build of AnythingLLM image for arm64 architecture"
  8. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  9. # Install system dependencies
  10. # hadolint ignore=DL3008,DL3013
  11. RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
  12. DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
  13. unzip curl gnupg libgfortran5 libgbm1 tzdata netcat \
  14. libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 \
  15. libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libx11-6 libx11-xcb1 libxcb1 \
  16. libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 \
  17. libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release \
  18. xdg-utils git build-essential ffmpeg && \
  19. mkdir -p /etc/apt/keyrings && \
  20. curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
  21. 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 && \
  22. apt-get update && \
  23. apt-get install -yq --no-install-recommends nodejs && \
  24. curl -LO https://github.com/yarnpkg/yarn/releases/download/v1.22.19/yarn_1.22.19_all.deb \
  25. && dpkg -i yarn_1.22.19_all.deb \
  26. && rm yarn_1.22.19_all.deb && \
  27. apt-get clean && \
  28. rm -rf /var/lib/apt/lists/*
  29. # Create a group and user with specific UID and GID
  30. RUN groupadd -g "$ARG_GID" anythingllm && \
  31. useradd -l -u "$ARG_UID" -m -d /app -s /bin/bash -g anythingllm anythingllm && \
  32. mkdir -p /app/frontend/ /app/server/ /app/collector/ && chown -R anythingllm:anythingllm /app
  33. # Copy docker helper scripts
  34. COPY ./docker/docker-entrypoint.sh /usr/local/bin/
  35. COPY ./docker/docker-healthcheck.sh /usr/local/bin/
  36. COPY --chown=anythingllm:anythingllm ./docker/.env.example /app/server/.env
  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. USER anythingllm
  41. WORKDIR /app
  42. # Puppeteer does not ship with an ARM86 compatible build for Chromium
  43. # so web-scraping would be broken in arm docker containers unless we patch it
  44. # by manually installing a compatible chromedriver.
  45. RUN echo "Need to patch Puppeteer x Chromium support for ARM86 - installing dep!" && \
  46. curl https://playwright.azureedge.net/builds/chromium/1088/chromium-linux-arm64.zip -o chrome-linux.zip && \
  47. unzip chrome-linux.zip && \
  48. rm -rf chrome-linux.zip
  49. ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
  50. ENV CHROME_PATH=/app/chrome-linux/chrome
  51. ENV PUPPETEER_EXECUTABLE_PATH=/app/chrome-linux/chrome
  52. RUN echo "Done running arm64 specific installation steps"
  53. #############################################
  54. # amd64-specific stage
  55. FROM base AS build-amd64
  56. RUN echo "Preparing build of AnythingLLM image for non-ARM architecture"
  57. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  58. # Install system dependencies
  59. # hadolint ignore=DL3008,DL3013
  60. RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
  61. DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
  62. curl gnupg libgfortran5 libgbm1 tzdata netcat \
  63. libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 \
  64. libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libx11-6 libx11-xcb1 libxcb1 \
  65. libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 \
  66. libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release \
  67. xdg-utils git build-essential ffmpeg && \
  68. mkdir -p /etc/apt/keyrings && \
  69. curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
  70. 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 && \
  71. apt-get update && \
  72. apt-get install -yq --no-install-recommends nodejs && \
  73. curl -LO https://github.com/yarnpkg/yarn/releases/download/v1.22.19/yarn_1.22.19_all.deb \
  74. && dpkg -i yarn_1.22.19_all.deb \
  75. && rm yarn_1.22.19_all.deb && \
  76. apt-get clean && \
  77. rm -rf /var/lib/apt/lists/*
  78. # Create a group and user with specific UID and GID
  79. RUN groupadd -g "$ARG_GID" anythingllm && \
  80. useradd -l -u "$ARG_UID" -m -d /app -s /bin/bash -g anythingllm anythingllm && \
  81. mkdir -p /app/frontend/ /app/server/ /app/collector/ && chown -R anythingllm:anythingllm /app
  82. # Copy docker helper scripts
  83. COPY ./docker/docker-entrypoint.sh /usr/local/bin/
  84. COPY ./docker/docker-healthcheck.sh /usr/local/bin/
  85. COPY --chown=anythingllm:anythingllm ./docker/.env.example /app/server/.env
  86. # Ensure the scripts are executable
  87. RUN chmod +x /usr/local/bin/docker-entrypoint.sh && \
  88. chmod +x /usr/local/bin/docker-healthcheck.sh
  89. #############################################
  90. # COMMON BUILD FLOW FOR ALL ARCHS
  91. #############################################
  92. # hadolint ignore=DL3006
  93. FROM build-${TARGETARCH} AS build
  94. RUN echo "Running common build flow of AnythingLLM image for all architectures"
  95. USER anythingllm
  96. WORKDIR /app
  97. # Install & Build frontend layer
  98. FROM build AS frontend-build
  99. COPY --chown=anythingllm:anythingllm ./frontend /app/frontend/
  100. WORKDIR /app/frontend
  101. RUN yarn install --network-timeout 100000 && yarn cache clean
  102. RUN yarn build && \
  103. cp -r dist /tmp/frontend-build && \
  104. rm -rf * && \
  105. cp -r /tmp/frontend-build dist && \
  106. rm -rf /tmp/frontend-build
  107. WORKDIR /app
  108. # Install server layer
  109. # Also pull and build collector deps (chromium issues prevent bad bindings)
  110. FROM build AS backend-build
  111. COPY ./server /app/server/
  112. WORKDIR /app/server
  113. RUN yarn install --production --network-timeout 100000 && yarn cache clean
  114. WORKDIR /app
  115. # Install collector dependencies
  116. COPY ./collector/ ./collector/
  117. WORKDIR /app/collector
  118. ENV PUPPETEER_DOWNLOAD_BASE_URL=https://storage.googleapis.com/chrome-for-testing-public
  119. RUN yarn install --production --network-timeout 100000 && yarn cache clean
  120. WORKDIR /app
  121. USER anythingllm
  122. # Since we are building from backend-build we just need to move built frontend into server/public
  123. FROM backend-build AS production-build
  124. WORKDIR /app
  125. COPY --chown=anythingllm:anythingllm --from=frontend-build /app/frontend/dist /app/server/public
  126. USER root
  127. RUN chown -R anythingllm:anythingllm /app/server && \
  128. chown -R anythingllm:anythingllm /app/collector
  129. USER anythingllm
  130. # No longer needed? (deprecated)
  131. # WORKDIR /app/server
  132. # RUN npx prisma generate --schema=./prisma/schema.prisma && \
  133. # npx prisma migrate deploy --schema=./prisma/schema.prisma
  134. # WORKDIR /app
  135. # Setup the environment
  136. ENV NODE_ENV=production
  137. ENV ANYTHING_LLM_RUNTIME=docker
  138. # Setup the healthcheck
  139. HEALTHCHECK --interval=1m --timeout=10s --start-period=1m \
  140. CMD /bin/bash /usr/local/bin/docker-healthcheck.sh || exit 1
  141. # Run the server
  142. # CMD ["sh", "-c", "tail -f /dev/null"] # For development: keep container open
  143. ENTRYPOINT ["/bin/bash", "/usr/local/bin/docker-entrypoint.sh"]