aboutsummaryrefslogtreecommitdiffstats
path: root/script/rails-post-deploy
blob: 2b66673c51af9b16322d92f34db64ff091de0971 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
#
# rails-post-deploy
# For Ruby on Rails, run this in exec_extras in vhosts.pl. It makes symlinks
# from vendor to the server version of rails, and migrates the db to the most
# recent version.
#
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
# $Id: rails-post-deploy,v 1.18 2009-09-03 23:44:50 francis Exp $
#

set -e
#set -x # debug

APP_DIR=`pwd`

# make sure that there is an app directory, so are in a rails app tree
cd app/..

# read config file in for later (STAGING_SITE)
if [ -e "config/general" ] || [ -e "config/general.yml" ]
then
	. commonlib/shlib/deployfns
	read_conf config/general
else
	OPTION_DOMAIN=127.0.0.1:3000
	OPTION_STAGING_SITE=1
fi

# create initial log files
if [ -e $APP_DIR/../logs ]
then
	# mySociety servers have logs dir in level above
	rm -f log
	ln -s $APP_DIR/../logs log
else
	# otherwise just make the directory
	if [ -h log ]
	then
		# remove any old-style symlink first
		rm -f log
	fi
	mkdir -p log
fi
# link the "downloads" directory in the cache to somewhere it can be served
if [ ! -e "$APP_DIR/public/download" ]
then
	mkdir -p "$APP_DIR/cache/zips/download"
	ln -s "$APP_DIR/cache/zips/download" "$APP_DIR/public/"
fi

cd log
touch development.log fastcgi.crash.log production.log test.log
cd ..

# Force appropriate environment in production
if [ "$OPTION_STAGING_SITE" = "0" ]
then
    cat <<-END
		
	***************************************************************** 
	WARNING: About to make config/rails_env.rb which, via special
	code in config/boot.rb, forces the Rails environment to be
	"production". If this is a development system, please edit your
	config/general.yml file and set the STAGING_SITE option to 1,
	and also delete the generated config/rails_env.rb file.
	Alternatively, you can override config/rails_env.rb at any time 
	with an environment variable.
	***************************************************************** 
	
	END
    echo "ENV['RAILS_ENV'] ||= 'production'" > config/rails_env.rb
fi

local bundle_install_options
if [ "$OPTION_STAGING_SITE" = "0" ]
then
    bundle_install_options="--without development:test --deployment"
fi

# Ordinarily we would expect simply to run "bundle install" here.
# However, at the time of writing there is a bug in bundler that
# causes gems from github to be rebuilt every time bundle install
# is run, which makes the process very extremely slow in our case
# because Xapian takes a long time to build. Running
# "bundle exec bundle install" is a workaround for this bug.
#
# However clearly one cannot run bundle exec till the bundle has
# initially been installed, so we use a flag file .bundler-has-run
# to indicate whether we are doing an initial install.
#
# If you ever need to rerun the initial install, just remove
# this flag file.
#
# https://groups.google.com/forum/?fromgroups#!topic/alaveteli-dev/lCDuW9H4uBI
if [ -e .bundler-has-run ]
then
    bundle exec bundle install $bundle_install_options
else
    bundle install $bundle_install_options
    touch .bundler-has-run
fi

if [ -n "$OPTION_THEME_URLS" ]
then
    for THEME in "${OPTION_THEME_URLS[@]}"
    do
        echo "Installing $THEME..."
        script/plugin install --force $THEME
    done
fi

# Old version of the above, for backwards compatibility
if [ -n "$OPTION_THEME_URL" ]
then
        echo "Installing $OPTION_THEME_URL using deprecated THEME_URL..."
        script/plugin install --force $OPTION_THEME_URL
fi

# upgrade database
bundle exec rake db:migrate #--trace