3 # Standard upgrade command to upgrade the Gitorious installation to a
4 # newer tagged version.
7 # script/upgrade_to <VERSION_TAG_NAME>
10 # script/upgrade_to v2.2.1
12 # You can determine your current version and the next version by running:
13 # bundle exec rake versioning:changelog
14 # This will tell you both your current version and what newer tagged versions exist.
16 # Note: an undo point is saved each time this command is run, so a
17 # failed run can be reversed by running script/undo_last_upgrade (note
18 # that each execution of /upgrade_to overwrites the undo point, so
19 # only do one upgrade at a time.)
22 # 1: If you are several versions behind, only upgrade one tagged version at a time.
23 # 2: Always perform a manual, extra backup (/script/snapshot) before attempting an upgrade
24 # 3: Take the Gitorious installation offline to prevent users from using it while upgrading
25 # 4: Before going through with the upgrade, check relevant release notes for any breaking changes,
26 # (particularly important for any major version upgrades)
30 puts
"Please run the task as superuser/root!"
36 puts
"script/upgrade_to <tag>"
43 require_relative
'../lib/gitorious/configuration_reader'
44 conf
= Gitorious
::ConfigurationReader.read('config/database.yml')
45 db_name
= conf
['production']['database']
46 puts
`mysqldump #{db_name} > /tmp/upgrade_db_backup.sql`
49 def backup_working_directory
50 puts
`rm -f /tmp/upgrade_working_dir_backup.tar && tar -czf /tmp/upgrade_working_dir_backup.tar .`
55 backup_working_directory
58 puts
"UPGRADE: About to attempt Gitorious upgrade. Please backup first. Proceed with upgrade? (y/n)"
59 response
= $stdin.gets
.chomp
65 puts
"UPGRADE: Attempting upgrade to #{new_tag}..."
67 puts
"UPGRADE: Fetching latest Gitorious code from the origin remote (should be gitorious.org)..."
68 puts
`git fetch origin`
70 puts
"UPGRADE: Preparing data needed by script/undo_last_upgrade..."
73 puts
"UPGRADE: Git checking out the '#{new_tag}' tag"
74 puts
`git checkout #{new_tag}`
76 puts
"UPGRADE: Updating submodules..."
77 puts
`git submodule init`
79 puts
"UPGRADE: Upgrading gem dependencies via Bundler..."
82 puts
"UPGRADE: Migrating database..."
83 puts
`env RAILS_ENV=production bundle exec rake db:migrate`
85 puts
"UPGRADE: Clearing asset pipeline..."
86 puts
`env RAILS_ENV=production bundle exec rake assets:clear`
88 puts
"UPGRADE: Restarting Gitorious..."
91 puts
"UPGRADE: Done, upgraded to #{new_tag}."
92 puts
"\nATTENTION: Please test and verify that your site works as expected. If any errors occur, rollback to the pre-upgrade state with script/undo_last_upgrade"