From 0cc93280bbe844523c3a32ecc13b4f89f6efd6b2 Mon Sep 17 00:00:00 2001 From: Konstantin Gredeskoul Date: Fri, 26 Apr 2024 15:48:48 -0700 Subject: [PATCH] Remove config/master.key from Docker Image --- Dockerfile | 3 +++ bin/docker-entrypoint | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/Dockerfile b/Dockerfile index 272250f4..b5d453b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -88,6 +88,9 @@ EXPOSE 3000 RUN chmod 755 /rails/bin/docker-entrypoint +# Remove master key so that the Docker image does not have it +RUN rm -f config/master.key + ENV RAILS_ENV=production # Entrypoint prepares the database. diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint index 511f44a9..95fb4ad0 100755 --- a/bin/docker-entrypoint +++ b/bin/docker-entrypoint @@ -25,6 +25,11 @@ if [[ -z "${LD_PRELOAD+x}" ]] && [[ -f /usr/lib/*/libjemalloc.so.2 ]]; then export LD_PRELOAD="$(echo /usr/lib/*/libjemalloc.so.2)" fi +# Create config/master.key from the env variable +if [[ -n ${RAILS_MASTER_KEY} && ! -s config/master.key ]]; then + echo -n ${RAILS_MASTER_KEY} > config/master.key +fi + # If running the rails server then create or migrate existing database if [[ "${1}" == "./bin/rails" ]] && [[ "${2}" == "server" ]]; then ./bin/rails db:prepare