From aad36d72974b4f8fd2753e91d44e08a7d4e9429e Mon Sep 17 00:00:00 2001
From: Pascal Ernster <pascal.ernster@rub.de>
Date: Tue, 14 Mar 2023 12:21:33 +0100
Subject: [PATCH] Create assets on first run in production mode

Currently, starting RDMS after rebuilding and reinstalling it from
scratch in `RAILS_ENV=production` mode fails because assets are not
created automatically. I'd prefer to put the required commands into the
`Dockerfile`, but this doesn't work currently because the path used to
store these assets is a Docker volume shared between multiple Docker
containers, which are not available at build time of these container
images/execution time of the corresponding `Dockerfile`. Therefore, for
the time being, we execute the commands in the container's
`hyrax/docker-entrypoint.sh`.
---
 hyrax/docker-entrypoint.sh | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/hyrax/docker-entrypoint.sh b/hyrax/docker-entrypoint.sh
index a2f1e61d..9c53001b 100644
--- a/hyrax/docker-entrypoint.sh
+++ b/hyrax/docker-entrypoint.sh
@@ -11,6 +11,14 @@ else
     bundle check || bundle install --without production
 fi
 
+if [ ! -f "/data/yarn.lock" ]; then
+    yarn install
+fi
+
+if [ ! -d "/data/public/uv" ]; then
+    bundle exec rake assets:clean assets:precompile
+fi
+
 ## Run any pending migrations, if the database exists
 ## If not setup the database
 bundle exec rake db:exists && bundle exec rake db:migrate || bundle exec rake db:setup
-- 
GitLab