Skip to content

Commit

Permalink
Refactor docker entrypoint (#922)
Browse files Browse the repository at this point in the history
* Revert "Test without entrypoint changes"

This reverts commit 1c9eb67.

* Fix guard clause for apps in prod

* Test default envs

* Export defaults only

* Evaluate printed envs for export

* Improve env var preparation
  • Loading branch information
peterdavidhamilton authored Nov 3, 2023
1 parent 0c30552 commit 9a9f636
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 35 deletions.
4 changes: 0 additions & 4 deletions .docker-profile

This file was deleted.

2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ ENV PUPPETEER_EXECUTABLE_PATH /usr/bin/chromium-browser
ENV APP_HOME /srv
ENV RAILS_ENV ${RAILS_ENV:-production}

COPY .docker-profile /root/.profile

RUN mkdir -p ${APP_HOME}/tmp/pids ${APP_HOME}/log

WORKDIR ${APP_HOME}
Expand Down
76 changes: 47 additions & 29 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,75 @@
# ------------------------------------------------------------------------------
set -e

if [ !${RAILS_ENV}=="production" ]
if [ ${RAILS_ENV} != "production" ]
then

if [ -z ${PROXY_CERT} ]
then
echo "No proxy certificate to append"
else
echo "Appending proxy certificate"
cat $PROXY_CERT >> /etc/ssl/certs/ca-certificates.crt
fi

#
# Development & Test
#
# ------------------------------------------------------------------------------
if bundle check
then
echo "$RAILS_ENV gems already bundled"
else
bundle
fi

if [ ! -d "node_modules" ]; then
if [ ! -d "node_modules" ]
then
bundle exec rails yarn:install
fi

rm -f tmp/pids/server.pid

if [ -z ${PROXY_CERT} ]
if [ -z ${DATABASE_URL} ]
then
echo "No proxy certificate to append"
echo "DATABASE_URL is not defined and cannot be prepared"
else
echo "Appending proxy certificate"
cat $PROXY_CERT >> /etc/ssl/certs/ca-certificates.crt
bundle exec rails db:create db:migrate
fi
fi

if [ -z ${DATABASE_URL} ]
then
echo "DATABASE_URL is not defined and cannot be prepared"
else
bundle exec rails db:create db:migrate
fi
rm -f tmp/pids/server.pid

if [ -z ${ENVIRONMENT} ]
then
echo "ENVIRONMENT is not defined so the app may not startup as intended"
# ------------------------------------------------------------------------------
else
/usr/sbin/sshd

if [ !${ENVIRONMENT}=="development" ]
#
# Production
#
# ------------------------------------------------------------------------------
if [ -z ${ENVIRONMENT} ]
then
bundle exec rails db:prepare assets:precompile db:seed eyfs:bot sitemap:refresh:no_ping
fi
echo "Azure ENVIRONMENT is not defined"
else
# Azure WebSSH
/usr/sbin/sshd
eval $(printenv | xargs 2>/dev/null | export > /root/.profile)

if [ !${ENVIRONMENT}=="staging" ]
then
bundle exec rails db:prepare assets:precompile
fi
bundle exec rails db:prepare

if [ !${ENVIRONMENT}=="production" ]
then
rm public/robots.txt && touch public/robots.txt && bundle exec rails db:prepare assets:precompile
case ${ENVIRONMENT} in
"development" )
bundle exec rails db:seed eyfs:bot sitemap:refresh:no_ping
;;
"staging" )
# no op
;;
"production" )
rm public/robots.txt && touch public/robots.txt
;;
* )
echo "Azure ENVIRONMENT ${ENVIRONMENT} is not supported"
esac
fi

# ------------------------------------------------------------------------------
fi

exec bundle exec "$@"

0 comments on commit 9a9f636

Please sign in to comment.