-
-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathDockerfile
More file actions
67 lines (50 loc) · 2.51 KB
/
Dockerfile
File metadata and controls
67 lines (50 loc) · 2.51 KB
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
# The image to build from.
FROM ruby:3.2.1-slim
# Properties/labels for the image.
LABEL maintainer="Notebook.ai Contributors"
# Development ENV by default, but overridable with RAILS_ENV
ARG RAILS_ENV=development
ENV RAILS_ENV=${RAILS_ENV}
# Create the notebookai user and group
RUN groupadd --system --gid 1000 notebookai && \
useradd --system --home-dir /home/notebookai --gid notebookai --uid 1000 --shell /bin/bash notebookai
# Install system dependencies (including curl which is needed for Node download, and git for Bundler)
RUN apt-get update -qq && \
apt-get install -y build-essential libpq-dev imagemagick libmagickwand-dev curl git libjemalloc2 && \
rm --recursive --force /var/lib/apt/lists/*
# Install Node.js 16.x explicitly and support both ARM and x64 architectures
RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" && \
case "${dpkgArch##*-}" in \
amd64) ARCH='x64';; \
arm64) ARCH='arm64';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac && \
curl -fsSLO "https://nodejs.org/dist/v16.20.2/node-v16.20.2-linux-$ARCH.tar.gz" && \
tar -xzf "node-v16.20.2-linux-$ARCH.tar.gz" -C /usr/local --strip-components=1 && \
rm "node-v16.20.2-linux-$ARCH.tar.gz"
# Install yarn via npm (matches local tools specification)
RUN npm install -g yarn@1.22.22
# Set the notebookai user's home directory as the working directory.
WORKDIR /home/notebookai
# Copy dependencies first to maximize Docker layer caching
COPY Gemfile Gemfile.lock package.json yarn.lock ./
# Install app dependencies
RUN bundle install && \
yarn install
# Copy the remaining application files
COPY . .
# Adjust permissions on all copied files to match the system user
RUN chown -R notebookai:notebookai /home/notebookai
# Drop down to the unprivileged user before running Rake, so any files it generates (like logs) are owned correctly
USER notebookai
# Precompile assets during docker build to prevent OOM memory spikes at runtime
# We strictly limit Node.js memory to 1GB to prevent Railway's Builder container from OOMing
RUN NODE_OPTIONS="--max_old_space_size=1024" SECRET_KEY_BASE=dummy bundle exec rake assets:precompile
# This image should expose port 3000.
EXPOSE 3000/tcp
# Enable jemalloc to drastically reduce memory fragmentation and usage
ENV LD_PRELOAD="libjemalloc.so.2"
# Configure the main process to run when running the image
ENTRYPOINT ["./docker-entrypoint.sh"]
# Start the server using Puma!
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb", "-e", "development", "-b", "tcp://0.0.0.0:3000"]