From 567853e805817d439106f8120ed839a1ac2decae Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Mon, 26 Aug 2024 18:47:18 +0300 Subject: [PATCH 1/2] Fixes shellcheck SC2144 Currently, this code only works if there is only one match. If for any reason there will be more than one, it'll fail. See https://github.com/koalaman/shellcheck/wiki/SC2144 --- .../rails/app/templates/docker-entrypoint.tt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/railties/lib/rails/generators/rails/app/templates/docker-entrypoint.tt b/railties/lib/rails/generators/rails/app/templates/docker-entrypoint.tt index 45a0dfb3d23f6..e5f853fce16de 100755 --- a/railties/lib/rails/generators/rails/app/templates/docker-entrypoint.tt +++ b/railties/lib/rails/generators/rails/app/templates/docker-entrypoint.tt @@ -1,8 +1,17 @@ #!/bin/bash -e # Enable jemalloc for reduced memory usage and latency. -if [ -z "${LD_PRELOAD+x}" ] && [ -f /usr/lib/*/libjemalloc.so.2 ]; then - export LD_PRELOAD="$(echo /usr/lib/*/libjemalloc.so.2)" +jemalloc_found=false +for lib in /usr/lib/*/libjemalloc.so.2; do + if [ -f "$lib" ]; then + export LD_PRELOAD="$lib" + jemalloc_found=true + break + fi +done + +if [ "$jemalloc_found" = false ]; then + echo "Warning: jemalloc not found" fi <% unless skip_active_record? -%> From c10edc8409aab6d1c1a6502c34da6d46b2a3cbde Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Mon, 26 Aug 2024 20:34:41 +0300 Subject: [PATCH 2/2] Changes due to review --- .../rails/app/templates/docker-entrypoint.tt | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/railties/lib/rails/generators/rails/app/templates/docker-entrypoint.tt b/railties/lib/rails/generators/rails/app/templates/docker-entrypoint.tt index e5f853fce16de..3234606742a42 100755 --- a/railties/lib/rails/generators/rails/app/templates/docker-entrypoint.tt +++ b/railties/lib/rails/generators/rails/app/templates/docker-entrypoint.tt @@ -1,17 +1,9 @@ #!/bin/bash -e # Enable jemalloc for reduced memory usage and latency. -jemalloc_found=false -for lib in /usr/lib/*/libjemalloc.so.2; do - if [ -f "$lib" ]; then - export LD_PRELOAD="$lib" - jemalloc_found=true - break - fi -done - -if [ "$jemalloc_found" = false ]; then - echo "Warning: jemalloc not found" +if [ -z "${LD_PRELOAD+x}" ]; then + LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit) + export LD_PRELOAD fi <% unless skip_active_record? -%>