Skip to content

Commit 6812276

Browse files
committed
Add nodejs to the Dockerfile
1 parent 83f42df commit 6812276

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

Dockerfile

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,35 @@ RUN apt-get update -qq && \
2323
ENV RAILS_ENV="production" \
2424
BUNDLE_DEPLOYMENT="1" \
2525
BUNDLE_PATH="/usr/local/bundle" \
26-
BUNDLE_WITHOUT="development"
26+
BUNDLE_WITHOUT="development:test"
2727

2828
# Throw-away build stage to reduce size of final image
2929
FROM base AS build
3030

31-
# Install packages needed to build gems
31+
# Install packages needed to build gems and node modules
3232
RUN apt-get update -qq && \
33-
apt-get install --no-install-recommends -y build-essential git libyaml-dev pkg-config && \
33+
apt-get install --no-install-recommends -y build-essential git libyaml-dev node-gyp pkg-config python-is-python3 && \
3434
rm -rf /var/lib/apt/lists /var/cache/apt/archives
3535

36+
# Install JavaScript dependencies
37+
ARG NODE_VERSION=22.13.1
38+
ENV PATH=/usr/local/node/bin:$PATH
39+
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
40+
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
41+
rm -rf /tmp/node-build-master
42+
3643
# Install application gems
37-
COPY Gemfile Gemfile.lock ./
44+
COPY Gemfile Gemfile.lock vendor ./
45+
3846
RUN bundle install && \
3947
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
4048
bundle exec bootsnap precompile --gemfile
4149

50+
# Install node modules
51+
COPY package.json package-lock.json ./
52+
RUN npm ci && \
53+
rm -rf ~/.npm
54+
4255
# Copy application code
4356
COPY . .
4457

@@ -48,7 +61,7 @@ RUN bundle exec bootsnap precompile app/ lib/
4861
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
4962
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
5063

51-
64+
RUN rm -rf node_modules
5265

5366

5467
# Final stage for app image

0 commit comments

Comments
 (0)