Skip to content

Commit 3493307

Browse files
committed
fix dockerfile
1 parent 08eb35d commit 3493307

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Dockerfile

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ WORKDIR /rails
1616

1717
# Install base packages
1818
RUN apt-get update -qq && \
19-
apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 && \
19+
apt-get install --no-install-recommends -y curl libjemalloc2 libvips && \
2020
rm -rf /var/lib/apt/lists /var/cache/apt/archives
2121

2222
# Set production environment
@@ -28,17 +28,30 @@ ENV RAILS_ENV="production" \
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 && \
3434
rm -rf /var/lib/apt/lists /var/cache/apt/archives
3535

36+
# Install JavaScript dependencies
37+
ARG NODE_VERSION=20.18.1
38+
ARG YARN_VERSION=1.22.22
39+
ENV PATH=/usr/local/node/bin:$PATH
40+
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
41+
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
42+
npm install -g yarn@$YARN_VERSION && \
43+
rm -rf /tmp/node-build-master
44+
3645
# Install application gems
3746
COPY Gemfile Gemfile.lock ./
3847
RUN bundle install && \
3948
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
4049
bundle exec bootsnap precompile --gemfile
4150

51+
# Install node modules
52+
COPY package.json yarn.lock ./
53+
RUN yarn install --immutable
54+
4255
# Copy application code
4356
COPY . .
4457

@@ -49,6 +62,7 @@ RUN bundle exec bootsnap precompile app/ lib/
4962
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
5063

5164

65+
RUN rm -rf node_modules
5266

5367

5468
# Final stage for app image
@@ -61,7 +75,7 @@ COPY --from=build /rails /rails
6175
# Run and own only the runtime files as a non-root user for security
6276
RUN groupadd --system --gid 1000 rails && \
6377
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
64-
chown -R rails:rails db log storage tmp
78+
chown -R rails:rails log storage tmp
6579
USER 1000:1000
6680

6781
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

0 commit comments

Comments
 (0)