Commit 3f9ee97289919453281818e082b6fbbacbf68e4d
1 parent
2f02a818
Exists in
master
and in
29 other branches
git-upgrade: reuse features of script/production
This is still untested in practice. I intend to do that when I get a chance to play with putting up a git-based instance for the Noosfero website.
Showing
1 changed file
with
14 additions
and
96 deletions
Show diff stats
script/git-upgrade
| ... | ... | @@ -2,105 +2,23 @@ |
| 2 | 2 | |
| 3 | 3 | set -e |
| 4 | 4 | |
| 5 | -export RAILS_ENV=production | |
| 6 | - | |
| 7 | 5 | say(){ |
| 8 | - echo -e "\033[33;01m$0: $1\033[m" | |
| 9 | -} | |
| 10 | - | |
| 11 | -get_value(){ | |
| 12 | - ruby -ryaml -e "puts YAML.load_file('config/database.yml')['$RAILS_ENV']['$1']" | |
| 13 | -} | |
| 14 | - | |
| 15 | -usage(){ | |
| 16 | - echo "usage: $0 [OPTIONS]" | |
| 17 | - echo | |
| 18 | - echo "Options:" | |
| 19 | - echo | |
| 20 | - echo " -s, --shell Opens a shell just after upgrading code and" | |
| 21 | - echo " database to make manual steps if needed" | |
| 22 | - echo | |
| 23 | - echo " -h, --help Displays the help (this screen)" | |
| 24 | - echo | |
| 25 | - echo " -v, --version Displays Noosfero current version" | |
| 26 | - echo | |
| 27 | - exit $1 | |
| 28 | -} | |
| 29 | - | |
| 30 | -version(){ | |
| 31 | - version=$(ruby -Ilib -rnoosfero -e 'puts Noosfero::VERSION') | |
| 32 | - echo "Noosfero version $version" | |
| 33 | - exit 0 | |
| 34 | -} | |
| 35 | - | |
| 36 | -stop_service(){ | |
| 37 | - say "Stopping service" | |
| 38 | - ./script/production stop || say "Stop failed, trying to continue anyway" | |
| 39 | - sudo /etc/init.d/memcached restart | |
| 40 | -} | |
| 41 | - | |
| 42 | -start_service(){ | |
| 43 | - say "Starting service" | |
| 44 | - ./script/production start | |
| 45 | -} | |
| 46 | - | |
| 47 | -upgrade_code(){ | |
| 48 | - say "Upgrading code" | |
| 49 | - | |
| 50 | - # db:migrate always changes this | |
| 51 | - git checkout db/schema.rb | |
| 52 | - | |
| 53 | - git pull --quiet | |
| 54 | - | |
| 55 | - say "Compiling translations" | |
| 56 | - rake noosfero:translations:compile 2>/dev/null || (echo "Translations compilation failed; run manually to check"; false) | |
| 57 | - | |
| 58 | - # remove cached files | |
| 59 | - rm -f public/javascripts/cache*.js | |
| 60 | - rm -f public/stylesheets/cache*.css | |
| 6 | + if [ -t 1 ]; then | |
| 7 | + printf "\033[33;01m$0: $1\033[m\n" | |
| 8 | + fi | |
| 61 | 9 | } |
| 62 | 10 | |
| 63 | -upgrade_database(){ | |
| 64 | - say "Upgrading database" | |
| 65 | - | |
| 66 | - rake db:migrate | |
| 11 | +say "Upgrading code" | |
| 67 | 12 | |
| 68 | - if test "$shell" = "yes"; then | |
| 69 | - echo "################################################" | |
| 70 | - echo "# Noosfero upgrade shell #" | |
| 71 | - echo "################################################" | |
| 72 | - echo "# #" | |
| 73 | - echo "# If you need to do any manual steps during #" | |
| 74 | - echo "# this upgrade, now is the time. #" | |
| 75 | - echo "# #" | |
| 76 | - echo "# After you finish, just exit this shell and #" | |
| 77 | - echo "# the upgrade will proceed #" | |
| 78 | - echo "################################################" | |
| 79 | - export PS1="[Noosfero upgrade] $PS1" | |
| 80 | - bash --rcfile config/bashrc | |
| 81 | - fi | |
| 82 | -} | |
| 13 | +last_passed=$(curl --silent --fail http://ci.noosfero.org/noosfero/LAST_SUCCESS_HEAD || true) | |
| 14 | +if [ -n "$last_passed" ]; then | |
| 15 | + git fetch | |
| 16 | + git reset --hard "$last_passed" | |
| 17 | +else | |
| 18 | + exit | |
| 19 | +fi | |
| 83 | 20 | |
| 84 | -shell=no | |
| 85 | -while test $# -gt 0; do | |
| 86 | - case "$1" in | |
| 87 | - -s|--shell) | |
| 88 | - shell=yes | |
| 89 | - ;; | |
| 90 | - -h|--help) | |
| 91 | - usage 0 | |
| 92 | - ;; | |
| 93 | - -v|--version) | |
| 94 | - version | |
| 95 | - ;; | |
| 96 | - *) | |
| 97 | - usage 1 | |
| 98 | - ;; | |
| 99 | - esac | |
| 100 | - shift | |
| 101 | -done | |
| 21 | +say "Compiling translations" | |
| 22 | +rake noosfero:translations:compile 2>/dev/null || (echo "Translations compilation failed; run manually to check"; false) | |
| 102 | 23 | |
| 103 | -stop_service | |
| 104 | -upgrade_code | |
| 105 | -upgrade_database | |
| 106 | -start_service | |
| 24 | +./script/production restart | ... | ... |