11# The image to build from.
2- FROM ruby:3.2.1
2+ FROM ruby:3.2.1-slim
33
44# Properties/labels for the image.
55LABEL maintainer="Notebook.ai Contributors"
@@ -12,14 +12,24 @@ ENV RAILS_ENV=${RAILS_ENV}
1212RUN groupadd --system --gid 1000 notebookai && \
1313 useradd --system --home-dir /home/notebookai --gid notebookai --uid 1000 --shell /bin/bash notebookai
1414
15- # Install system dependencies
16- RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \
17- apt-get update -qq && \
18- apt-get install -y build-essential libpq-dev nodejs imagemagick libmagickwand-dev curl && \
15+ # Install system dependencies (including curl which is needed for Node download, and git for Bundler)
16+ RUN apt-get update -qq && \
17+ apt-get install -y build-essential libpq-dev imagemagick libmagickwand-dev curl git libjemalloc2 && \
1918 rm --recursive --force /var/lib/apt/lists/*
2019
21- # Install yarn via npm (avoids the deprecated apt-key approach)
22- RUN npm install -g yarn
20+ # Install Node.js 16.x explicitly and support both ARM and x64 architectures
21+ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" && \
22+ case "${dpkgArch##*-}" in \
23+ amd64) ARCH='x64' ;; \
24+ arm64) ARCH='arm64' ;; \
25+ *) echo "unsupported architecture" ; exit 1 ;; \
26+ esac && \
27+ curl -fsSLO "https://nodejs.org/dist/v16.20.2/node-v16.20.2-linux-$ARCH.tar.gz" && \
28+ tar -xzf "node-v16.20.2-linux-$ARCH.tar.gz" -C /usr/local --strip-components=1 && \
29+ rm "node-v16.20.2-linux-$ARCH.tar.gz"
30+
31+ # Install yarn via npm (matches local tools specification)
32+ RUN npm install -g yarn@1.22.22
2333
2434# Set the notebookai user's home directory as the working directory.
2535WORKDIR /home/notebookai
@@ -37,11 +47,21 @@ COPY . .
3747# Adjust permissions on all copied files to match the system user
3848RUN chown -R notebookai:notebookai /home/notebookai
3949
50+ # Drop down to the unprivileged user before running Rake, so any files it generates (like logs) are owned correctly
51+ USER notebookai
52+
53+ # Precompile assets during docker build to prevent OOM memory spikes at runtime
54+ # We strictly limit Node.js memory to 1GB to prevent Railway's Builder container from OOMing
55+ RUN NODE_OPTIONS="--max_old_space_size=1024" SECRET_KEY_BASE=dummy bundle exec rake assets:precompile
56+
4057# This image should expose port 3000.
4158EXPOSE 3000/tcp
4259
43- # Run unprivileged
44- USER notebookai
60+ # Enable jemalloc to drastically reduce memory fragmentation and usage
61+ ENV LD_PRELOAD="libjemalloc.so.2"
62+
63+ # Configure the main process to run when running the image
64+ ENTRYPOINT ["./docker-entrypoint.sh" ]
4565
4666# Start the server using Puma!
4767CMD ["bundle" , "exec" , "puma" , "-C" , "config/puma.rb" , "-e" , "development" , "-b" , "tcp://0.0.0.0:3000" ]
0 commit comments