Skip to content
Maikel edited this page Jul 26, 2019 · 8 revisions

The Australian production server is provisioned and deployed with ofn-install.

Other services

The global website is hosted on this server as well. It's Wordpress with Mysql and stored under the openfoodnetwork-org user.

The Australian Wordpress site is hosted here as well.

Old deployment strategy

Deployments used to be triggered via git push. The Git repository on the server had a custom post-receive hook.

git push openfoodnetwork@prod2.openfoodnetwork.org.au:apps/openfoodnetwork/current v1.30.0:master

It executed this script on the server:

#!/bin/sh

set -e

APP_PATH="$HOME/apps/openfoodnetwork"
CURRENT_PATH="/home/openfoodnetwork/apps/openfoodnetwork/current"
SHARED_PATH="/home/openfoodnetwork/apps/openfoodnetwork/shared"
CONFIG_PATH="/home/openfoodnetwork/apps/openfoodnetwork/shared/config"
BUNDLE="$HOME/.rbenv/shims/bundle"
GEM_PATH="/home/openfoodnetwork/.gem"
APP="openfoodnetwork"
RAILS_ENV="production"

# We need ruby to call script/delayed_job
export PATH="$HOME/.rbenv/shims:$PATH"

cd "$CURRENT_PATH" || exit 1

unset GIT_DIR
NEWREF=$(cat /dev/stdin | cut -d ' ' -f 2)

# Check out the new revision
git reset --hard $NEWREF

# Symlink shared files
rm -f "$CURRENT_PATH/config/database.yml"
ln -s "$CONFIG_PATH/database.yml" "$CURRENT_PATH/config/database.yml"

# Install the required gems
# Note: the 'LANG=en_US.UTF-8' is a fix for jquery-rails 1.0.17...fails even though server has correct locale setting
LANG=en_US.UTF-8 $BUNDLE install --gemfile "$CURRENT_PATH/Gemfile" --path "$GEM_PATH" --deployment --without development test

# Clear cache to regenerate translations for i18n-js
#echo "Doing tmp:cache:clear..."
#$BUNDLE exec rake tmp:cache:clear

# Note: Calling standard assets:precompile is overkill and chews up heaps of memory.
#       Hence do steps one-by-one
#echo Doing total bundle install thing
#$BUNDLE exec rake RAILS_ENV=$RAILS_ENV assets:precompile RAILS_GROUPS=assets
echo Doing asset:precompile:primary...
$BUNDLE exec rake RAILS_ENV=$RAILS_ENV assets:precompile:primary RAILS_GROUPS=assets
echo Doing asset:precompile:nondigest...
$BUNDLE exec rake RAILS_ENV=$RAILS_ENV assets:precompile:nondigest RAILS_GROUPS=assets

# Stop Delayed Job. It needs starting again.
sudo /bin/systemctl stop delayed_job_openfoodnetwork.service

# Update the DB schema
$BUNDLE exec rake RAILS_ENV=$RAILS_ENV db:migrate

# Rotate log files
logrotate -s "$CURRENT_PATH/log/logrotate-status" "$CURRENT_PATH/log/logrotate.conf"

# http://unicorn.bogomips.org/SIGNALS.html
echo "Restarting unicorn..."
/etc/init.d/"unicorn_$APP" restart

# Start DJ workers
sudo /bin/systemctl start delayed_job_openfoodnetwork.service

# Install cron jobs
$BUNDLE exec whenever --set 'environment=$RAILS_ENV' --update-crontab

# Tell bugsnag about the deploy, keeps the error history clean
if [ -f "$CURRENT_PATH/config/initializers/bugsnag.rb" ]; then
    #echo Notifying bugsnag...
    #$BUNDLE exec rake RAILS_ENV=$RAILS_ENV bugsnag:deploy TO=$RAILS_ENV
    # The bugsnag-capistrano gem lower than v 2.0 contains this task. But we don't have it.
fi

echo Done.