Better production container precompiling and bootstrapping (#10280)
* Create entrypoint-dev.sh to be used with devel workflows with docker/podman compose and adjust the compose files to use it. * Adjust the entrypoint script so we have better control over when we run rake assets:precompile and rake app_initializer:setup. * Copy vendor/cache so we can bundle install from cached gems instead of fetching them from the Internet. * Run rake assets:precompile in the container build. * Add in clobber and clean tasks to entrypoint.
This commit is contained in:
parent
ebc894a07c
commit
f34dbf4693
5 changed files with 49 additions and 5 deletions
|
|
@ -38,6 +38,7 @@ WORKDIR "${APP_HOME}"
|
|||
|
||||
COPY ./.ruby-version "${APP_HOME}"
|
||||
COPY ./Gemfile ./Gemfile.lock "${APP_HOME}"
|
||||
COPY ./vendor/cache "${APP_HOME}"/vendor/cache
|
||||
|
||||
# Fixes https://github.com/sass/sassc-ruby/issues/146
|
||||
RUN bundle config build.sassc --disable-march-tune-native
|
||||
|
|
@ -52,6 +53,8 @@ RUN mkdir -p "${APP_HOME}"/public/{assets,images,packs,podcasts,uploads}
|
|||
|
||||
COPY . "${APP_HOME}"
|
||||
|
||||
RUN bundle exec rake assets:precompile
|
||||
|
||||
RUN echo $(date -u +'%Y-%m-%dT%H:%M:%SZ') >> "${APP_HOME}"/FOREM_BUILD_DATE && \
|
||||
echo $(git rev-parse --short HEAD) >> "${APP_HOME}"/FOREM_BUILD_SHA && \
|
||||
rm -rf "${APP_HOME}"/.git/
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ services:
|
|||
volumes:
|
||||
- .:/opt/apps/forem:z
|
||||
- ./.gems:/opt/apps/bundle:z
|
||||
entrypoint: ["dockerize", "-wait", "tcp://db:5432", "-wait", "http://elasticsearch:9200", "-wait", "tcp://redis:6379", "-wait", "file:///opt/apps/bundle/bundle_finished", "-timeout", "300s", "./scripts/entrypoint.sh"]
|
||||
entrypoint: ["dockerize", "-wait", "tcp://db:5432", "-wait", "http://elasticsearch:9200", "-wait", "tcp://redis:6379", "-wait", "file:///opt/apps/bundle/bundle_finished", "-timeout", "300s", "./scripts/entrypoint-dev.sh"]
|
||||
command: ["bundle", "exec", "rails","server","-b","0.0.0.0","-p","3000"]
|
||||
|
||||
bundle:
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ services:
|
|||
volumes:
|
||||
- .:/opt/apps/forem:delegated
|
||||
- ./.gems:/opt/apps/bundle:delegated
|
||||
entrypoint: ["dockerize", "-wait", "tcp://db:5432", "-wait", "http://elasticsearch:9200", "-wait", "tcp://redis:6379", "-wait", "file:///opt/apps/bundle/bundle_finished", "-timeout", "2700s", "./scripts/entrypoint.sh"]
|
||||
entrypoint: ["dockerize", "-wait", "tcp://db:5432", "-wait", "http://elasticsearch:9200", "-wait", "tcp://redis:6379", "-wait", "file:///opt/apps/bundle/bundle_finished", "-timeout", "2700s", "./scripts/entrypoint-dev.sh"]
|
||||
command: ["bundle", "exec", "rails","server","-b","0.0.0.0","-p","3000"]
|
||||
|
||||
bundle:
|
||||
|
|
|
|||
16
scripts/entrypoint-dev.sh
Normal file
16
scripts/entrypoint-dev.sh
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
if [ -f tmp/pids/server.pid ]; then
|
||||
rm -f tmp/pids/server.pid
|
||||
fi
|
||||
|
||||
export RELEASE_FOOTPRINT=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
||||
export FOREM_BUILD_DATE=$(cat FOREM_BUILD_DATE)
|
||||
export FOREM_BUILD_SHA=$(cat FOREM_BUILD_SHA)
|
||||
|
||||
echo "Running rake app_initializer:setup..."
|
||||
bundle exec rake app_initializer:setup
|
||||
|
||||
exec "$@"
|
||||
|
|
@ -10,7 +10,32 @@ export RELEASE_FOOTPRINT=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
|||
export FOREM_BUILD_DATE=$(cat FOREM_BUILD_DATE)
|
||||
export FOREM_BUILD_SHA=$(cat FOREM_BUILD_SHA)
|
||||
|
||||
echo "Running rake app_initializer:setup..."
|
||||
bundle exec rake app_initializer:setup
|
||||
case "$@" in
|
||||
|
||||
exec "$@"
|
||||
precompile)
|
||||
echo "Running rake assets:precompile..."
|
||||
bundle exec rake assets:precompile
|
||||
;;
|
||||
|
||||
clean)
|
||||
echo "Running rake assets:clean..."
|
||||
bundle exec rake assets:clean
|
||||
;;
|
||||
|
||||
clobber)
|
||||
echo "Running rake assets:clobber..."
|
||||
bundle exec rake assets:clobber
|
||||
;;
|
||||
|
||||
bootstrap)
|
||||
echo "Running rake app_initializer:setup..."
|
||||
bundle exec rake app_initializer:setup
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Running command:"
|
||||
echo "$@"
|
||||
exec "$@"
|
||||
;;
|
||||
|
||||
esac
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue