Skip to content

Commit 1d27dd9

Browse files
authored
Merge pull request rails#55252 from igor-alexandrov/ld_preload_in_dockerfile
Moved LD_PRELOAD variable initialization to the Dockerfile from the entrypoint
2 parents 367532d + c7074bb commit 1d27dd9

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

railties/lib/rails/generators/rails/app/templates/Dockerfile.tt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ WORKDIR /rails
1717
# Install base packages
1818
RUN apt-get update -qq && \
1919
apt-get install --no-install-recommends -y <%= dockerfile_base_packages.join(" ") %> && \
20+
ln -s /usr/lib/$(uname -m)-linux-gnu/libjemalloc.so.2 /usr/local/lib/libjemalloc.so && \
2021
rm -rf /var/lib/apt/lists /var/cache/apt/archives
2122

22-
# Set production environment
23+
# Set production environment variables and enable jemalloc for reduced memory usage and latency.
2324
ENV RAILS_ENV="production" \
2425
BUNDLE_DEPLOYMENT="1" \
2526
BUNDLE_PATH="/usr/local/bundle" \
26-
BUNDLE_WITHOUT="development"
27+
BUNDLE_WITHOUT="development" \
28+
LD_PRELOAD=/usr/local/lib/libjemalloc.so
2729

2830
# Throw-away build stage to reduce size of final image
2931
FROM base AS build

railties/lib/rails/generators/rails/app/templates/docker-entrypoint.tt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
#!/bin/bash -e
22

3-
# Enable jemalloc for reduced memory usage and latency.
4-
if [ -z "${LD_PRELOAD+x}" ]; then
5-
LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit)
6-
export LD_PRELOAD
7-
fi
8-
93
<% unless skip_active_record? -%>
104
# If running the rails server then create or migrate existing database
115
if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then

0 commit comments

Comments
 (0)