@@ -13,28 +13,32 @@ ENV RAILS_ENV="production" \
13
13
BUNDLE_PATH="/usr/local/bundle" \
14
14
BUNDLE_WITHOUT="development"
15
15
16
+
16
17
# Throw-away build stage to reduce size of final image
17
18
FROM base as build
18
19
19
20
# Install packages needed to build gems and node modules
20
21
RUN apt-get update -qq && \
21
- apt-get install --no-install-recommends -y build-essential curl git libpq-dev libvips node-gyp pkg-config python-is-python3
22
+ apt-get install --no-install-recommends -y build-essential curl git libvips node-gyp pkg-config python-is-python3
23
+
24
+ # Install JavaScript dependencies
25
+ ARG NODE_VERSION=20.11.1
26
+ ARG YARN_VERSION=1.22.22
27
+ ENV PATH=/usr/local/node/bin:$PATH
28
+ RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
29
+ /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
30
+ npm install -g yarn@$YARN_VERSION && \
31
+ rm -rf /tmp/node-build-master
22
32
23
33
# Install application gems
24
34
COPY Gemfile Gemfile.lock ./
25
35
RUN bundle install && \
26
36
rm -rf ~/.bundle/ "${BUNDLE_PATH}" /ruby/*/cache "${BUNDLE_PATH}" /ruby/*/bundler/gems/*/.git && \
27
37
bundle exec bootsnap precompile --gemfile
28
38
29
- # Install node modules if package.json is present
39
+ # Install node modules
30
40
COPY package.json yarn.lock ./
31
- RUN if [ -f package.json ]; then \
32
- curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
33
- /tmp/node-build-master/bin/node-build "21.5.0" /usr/local/node && \
34
- npm install -g yarn@1.22.19 && \
35
- yarn install --frozen-lockfile && \
36
- rm -rf /tmp/node-build-master; \
37
- fi
41
+ RUN yarn install --frozen-lockfile
38
42
39
43
# Copy application code
40
44
COPY . .
@@ -45,21 +49,19 @@ RUN bundle exec bootsnap precompile app/ lib/
45
49
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
46
50
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
47
51
52
+
48
53
# Final stage for app image
49
54
FROM base
50
55
51
56
# Install packages needed for deployment
52
57
RUN apt-get update -qq && \
53
- apt-get install --no-install-recommends -y curl libvips postgresql-client && \
58
+ apt-get install --no-install-recommends -y curl libsqlite3-0 libvips && \
54
59
rm -rf /var/lib/apt/lists /var/cache/apt/archives
55
60
56
61
# Copy built artifacts: gems, application
57
62
COPY --from=build /usr/local/bundle /usr/local/bundle
58
63
COPY --from=build /rails /rails
59
64
60
- # Ensure mini_racer is installed for ExecJS
61
- RUN gem install mini_racer
62
-
63
65
# Run and own only the runtime files as a non-root user for security
64
66
RUN useradd rails --create-home --shell /bin/bash && \
65
67
chown -R rails:rails db log storage tmp
0 commit comments