Productive Rails application - HVboom/HowTo-DigitalOcean GitHub Wiki
Create a dedicated user
- follow the Development User instructions
- the name of the user will be the name of the application URL, like
bim.hvboom.netfor an application user bim
Install the application
-
login into the new user account
-
add
export RAILS_ENV='production'to your$HOME/.profileto ensure the right environment- logout and login again or run the command
export RAILS_ENV='production'in the current shell
- logout and login again or run the command
-
Checkout the GitLab repository of the application
cd $HOME/RubyOnRails git clone [email protected]:<application repository>.git # example: git clone [email protected]:HVboom/BuildingIntegrationModeling.git ln -s <application> $USER # example: ln -s BuildingIntegrationModeling bim -
Prepare Bundler production settings by creating a config file $HOME/RubyOnRails/<application>/.bundler/config
mkdir -p "$HOME/RubyOnRails/$USER/.bundle" touch "$HOME/RubyOnRails/$USER/.bundle/config" >/dev/null 2>&1 if [ -w "$HOME/RubyOnRails/$USER/.bundle/config" ] then echo '---' > $HOME/RubyOnRails/$USER/.bundle/config echo 'BUNDLE_WITHOUT: "development:test"' >> $HOME/RubyOnRails/$USER/.bundle/config echo 'BUNDLE_FROZEN: true' >> $HOME/RubyOnRails/$USER/.bundle/config echo 'BUNDLE_PATH: "vendor/bundle"' >> $HOME/RubyOnRails/$USER/.bundle/config echo 'BUNDLE_DISABLE_SHARED_GEMS: true' >> $HOME/RubyOnRails/$USER/.bundle/config fi # run 'bundle install' automatically cd $HOME/RubyOnRails/$USER
Setup the Ruby On Rails application
-
MySQL only: Create database user for the application user (e.g. bim) with phpMyAdmin
-
If you have the
config/master.keyfile, then you are lucky - otherwise- Delete the file
config/credentials.yml.enc - Create a new one with
EDITOR=vim bundle exec rails credentials:editusing the content ofconfig/credentials.yml.example
- Delete the file
-
Compile assets:
NODE_ENV=production RAILS_ENV=production bundle exec rake assets:precompile -
Setup the database:
RAILS_ENV=production bundle exec rake db:create db:schema:load db:seed -
Cleanup log and tmp directory:
RAILS_ENV=production bundle exec rake log:clear tmp:clear -
Restart application:
RAILS_ENV=production bundle exec rake restart
Update application
- Checkout new version:
cd $HOME/RubyOnRails/$USER && git pull - Update to newest Gem versions:
RAILS_ENV=production bundle install - Update to newest Node versions:
yarn install --production - Remove obsolete Gem version:
RAILS_ENV=production bundle clean --force - Compile assets:
NODE_ENV=production RAILS_ENV=production bundle exec rake assets:precompile - Setup the database:
RAILS_ENV=production bundle exec rake db:migrate - Cleanup log and tmp directory:
RAILS_ENV=production bundle exec rake log:clear tmp:clear - Restart application:
RAILS_ENV=production bundle exec rake restart