Skip to content

Commit

Permalink
Merge pull request #972 from birs-math/update-docker-environment
Browse files Browse the repository at this point in the history
Make image building lightweight
  • Loading branch information
birs-math committed Jun 1, 2023
2 parents b7713e3 + c9069c9 commit 6f7913b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 78 deletions.
22 changes: 22 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.git
.gitignore

config/master.key

/.bundle
/vendor/bundle
/node_modules

/public/packs
/public/packs-test
/public/assets

/yarn-error.log
yarn-debug.log*
.yarn-integrity

/tmp

.byebug_history


19 changes: 7 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,18 @@ ENV LC_ALL en_CA.utf8
# Match deployment userid
RUN /usr/sbin/usermod -u 40130 app

#COPY rails-env.conf /etc/nginx/main.d/rails-env.conf
#RUN chmod 644 /etc/nginx/main.d/rails-env.conf
ENV APP_HOME /home/app/proposals
# disabled because we mount host directory in $APP_HOME
COPY . $APP_HOME
COPY --chown=app . $APP_HOME
WORKDIR $APP_HOME
RUN /usr/local/rvm/bin/rvm default use 2.7.7

RUN /usr/local/rvm/bin/rvm --default use 2.7.7
RUN /usr/local/rvm/bin/rvm-exec 2.7.7 gem install bundler
RUN /usr/local/rvm/bin/rvm-exec 2.7.7 gem uninstall turbo-rails
RUN bundle install
RUN RAILS_ENV=development bundle exec cap install
# Answer no to overwrite prompts
RUN RAILS_ENV=development yes n | bundle exec rails webpacker:install
RUN RAILS_ENV=development bundle exec rails turbo:install
RUN yarn install
RUN chown app:app -R /usr/local/rvm/gems
RUN chown app:app -R /home/app/proposals

RUN yarn install
RUN chown app:app -R /home/app/proposals/node_modules
RUN chmod -R 755 /home/app/proposals/node_modules

RUN echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf
EXPOSE 80 443
Expand Down
70 changes: 4 additions & 66 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ rm /etc/timezone
rm /etc/localtime
dpkg-reconfigure --frontend noninteractive tzdata

if [ ! -e /usr/local/rvm/gems/ruby-2.7.7 ]; then
echo
echo "Create gemset..."
gpg --keyserver keys.openpgp.org --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
/usr/bin/curl -sSL https://get.rvm.io | bash -s stable
bash -lc 'rvm --default use ruby-2.7.7'
/usr/local/rvm/bin/rvm gemset create ruby-2.7.7
/usr/local/rvm/bin/rvm gemset use ruby-2.7.7@global
/usr/local/rvm/bin/rvm cleanup all
/usr/local/rvm/bin/rvm reload
fi

echo
echo "Ruby version:"
ruby -v
Expand All @@ -45,30 +33,6 @@ echo
echo "Yarn version:"
yarn --version

echo
echo "Installing latest bundler..."
/usr/local/rvm/bin/rvm-exec 2.7.7 gem install bundler

if [ ! -e /usr/local/rvm/gems/ruby-2.7.7/gems/rails-6.1.4.1 ]; then
echo
echo "Installing Rails 6.1.4.1..."
su - app -c "cd /home/app/proposals; /usr/local/rvm/bin/rvm-exec 2.7.7 gem install rails -v 6.1.4.1"
fi

if [ ! -e /home/app/proposals/bin ]; then
echo
echo "Starting new rails app..."
su - app -c "cd /home/app; rails new proposals"
fi

# echo
# echo "Bundle install..."
# su - app -c "cd /home/app/proposals; /usr/local/rvm/gems/default/bin/bundle install"

echo
echo "Bundle update..."
su - app -c "cd /home/app/proposals; /usr/local/rvm/gems/default/bin/bundle update"

root_owned_files=`find /usr/local/rvm/gems -user root -print`
if [ -z "$root_owned_files" ]; then
echo
Expand All @@ -80,43 +44,17 @@ if [ -e /home/app/proposals/db/migrate ]; then
echo
echo "Running migrations..."
cd /home/app/proposals
SECRET_KEY_BASE=token DB_USER=$DB_USER DB_PASS=$DB_PASS
SECRET_KEY_BASE=$SECRET_KEY_BASE DB_USER=$DB_USER DB_PASS=$DB_PASS
rake db:migrate RAILS_ENV=production
rake db:migrate RAILS_ENV=development
rake db:migrate RAILS_ENV=test
fi

if [ ! -e /home/app/proposals/config/webpacker.yml ]; then
echo "Installing Webpacker..."
su - app -c "cd /home/app/proposals; SECRET_KEY_BASE=token bundle exec rails webpacker:install"

echo
echo "Turbo install..."
su - app -c "cd /home/app/proposals; SECRET_KEY_BASE=token bundle exec rails turbo:install"
echo "Done!"
echo
fi

if [ ! -e /home/app/proposals/app/assets/stylesheets/actiontext.scss ]; then
echo "Setting up ActionText..."
su - app -c "cd /home/app/proposals; bin/rails action_text:install"
echo
echo "Done!"
fi

if [ "$RAILS_ENV" == "production" ]; then
echo
echo "Updating file permissions..."
chown app:app -R /home/app/proposals
fi

echo
echo "Compiling Assets..."
chmod 755 /home/app/proposals/node_modules
su - app -c "cd /home/app/proposals; yarn install"

if [ "$RAILS_ENV" == "production" ]; then
su - app -c "cd /home/app/proposals; RAILS_ENV=production SECRET_KEY_BASE=token bundle exec rake assets:precompile --trace"
su - app -c "cd /home/app/proposals; RAILS_ENV=production SECRET_KEY_BASE=$SECRET_KEY_BASE bundle exec rake assets:precompile --trace"
su - app -c "cd /home/app/proposals; yarn"

# Update release tag
Expand All @@ -129,10 +67,10 @@ su - app -c "cd /home/app/proposals; bin/webpack --verbose --progress"
echo
echo "Done compiling assets!"

if [ "$APPLICATION_HOST" == "localhost" ]; then
if [ "$RAILS_ENV" == "development" ]; then
echo
echo "Launching webpack-dev-server..."
su - app -c "cd /home/app/proposals; RAILS_ENV=development SECRET_KEY_BASE=token bundle exec bin/webpack-dev-server &"
su - app -c "cd /home/app/proposals; RAILS_ENV=development SECRET_KEY_BASE=$SECRET_KEY_BASE bundle exec bin/webpack-dev-server &"
fi

echo
Expand Down

0 comments on commit 6f7913b

Please sign in to comment.