-
Notifications
You must be signed in to change notification settings - Fork 0
Deployment guide
The deployment system is implemented with Vlad. The script is in config/deploy.rb
. This file contains server settings, deployment path and the git repository URL at the start. The script currently uses Ruby through rvm, which must be set up on the server for all users (in /usr/local/lib).
When everything is set up, the deployment is done with the following command:
rake vlad:deploy
You need a private ssh key to access the Amazon EC2 server (e.g. in ~/.ssh/aapps).
Ssh access to Github must be properly configured and the user must have reading rights to the repository. This includes setting your public ssh key as an allowed key in Github's admin panel. This key is separate from the key used with EC2 server. See Github's help pages for further instructions.
Ssh in the local computer needs to be set up to use the correct ssh key to when connecting to EC2 server. This can be done by adding the following lines to ~/.ssh/config
:
Host 79.125.124.244
IdentityFile ~/.ssh/aapps
User aaltoapps
ForwardAgent yes
This guide is for Ubuntu 11.04 running in an Amazon EC2 server.
-
Create a new user account. The application will run under this account and the account will be used for deployment. The following steps are done as this user. The user needs sudo privileges for this to work.
-
Install the following packages (
sudo apt-get install package1 package2 ...
):- gcc
- g++
- make
- automake1.9
- git
- postgresql
- zlib1g-dev
- libcurl4-openssl-dev or libcurl4-gnutls-dev
- libssl-dev
- libpq-dev
- language-pack-en and other language packs you might use
- PostgreSQL uses these for collation and other locale-specific string handling
- install these with the apt-get flag
--no-install-recommends
If some of the -dev-packages are not installed, ruby-build may silently skip building some of its core modules, which some gems may require.
-
Install ruby-build:
git clone git://github.com/sstephenson/ruby-build.git cd ruby-build sudo ./install.sh
-
Install rbenv:
cd git clone git://github.com/sstephenson/rbenv.git .rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile echo 'eval "$(rbenv init -)"' >> .bash_profile
-
Install the latest stable Ruby under
~/.rbenv/versions/
and set it as the default ruby:ruby-build 1.9.2-p290 $HOME/.rbenv/versions/1.9.2-p290 rbenv rehash rbenv global 1.9.2-p290
-
Install Nginx and Phusion Passenger:
gem install passenger --no-rdoc rbenv rehash sudo sh -c "PATH=\"$PATH\" passenger-install-nginx-module"
-
Create a directory for the application and give yourself write permissions to it:
sudo mkdir -p /deployment_path sudo chown your_username:your_groupname /deployment_path
In Ubuntu your_groupname is typically the same as your_username.
-
Edit Nginx configuration in file
/opt/nginx/conf/nginx.conf
. For basic installation replaceserver
section with the following:server { listen 80; server_name domain.name.of.the.server alternate.domain.name ...; root /deployment_path/current/public; passenger_enabled on; }
-
passenger-install-nginx-module
doesn't seen to create init script for Nginx, so we have to do it ourselves:-
Create file
/etc/init.d/nginx
as root with the following contents:#! /bin/sh ### BEGIN INIT INFO # Provides: nginx # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts the nginx web server # Description: starts nginx using start-stop-daemon ### END INIT INFO PATH=/opt/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/opt/nginx/sbin/nginx NAME=nginx DESC=nginx test -x $DAEMON || exit 0 # Include nginx defaults if available if [ -f /etc/default/nginx ] ; then . /etc/default/nginx fi set -e case "$1" in start) echo -n "Starting $DESC: " start-stop-daemon --start --quiet --pidfile /opt/nginx/logs/$NAME.pid \ --exec $DAEMON -- $DAEMON_OPTS echo "$NAME." ;; stop) echo -n "Stopping $DESC: " start-stop-daemon --stop --quiet --pidfile /opt/nginx/logs/$NAME.pid \ --exec $DAEMON echo "$NAME." ;; restart|force-reload) echo -n "Restarting $DESC: " start-stop-daemon --stop --quiet --pidfile \ /opt/nginx/logs/$NAME.pid --exec $DAEMON sleep 1 start-stop-daemon --start --quiet --pidfile \ /opt/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS echo "$NAME." ;; reload) echo -n "Reloading $DESC configuration: " start-stop-daemon --stop --signal HUP --quiet --pidfile /opt/nginx/logs/$NAME.pid \ --exec $DAEMON echo "$NAME." ;; *) N=/etc/init.d/$NAME echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2 exit 1 ;; esac exit 0
(copied from http://library.linode.com/frameworks/ruby-on-rails-nginx/ubuntu-10.10-maverick)
-
Give the file execute permission
-
Run the command:
/usr/sbin/update-rc.d -f nginx defaults
-
Start Nginx:
sudo /etc/init.d/nginx start
-
-
-
Set up PostgreSQL database
-
Edit
/etc/postgresql/8.4/main/pg_hba.conf
as root and add the line:local all all md5
-
Restart PostgreSQL (
sudo /etc/init.d/postgresql restart
) -
sudo -u postgres psql postgres
:CREATE ROLE aaltoapps WITH LOGIN PASSWORD 'random_password'; CREATE DATABASE aaltoapps OWNER aaltoapps;
-
-
Set up Ruby on Rails
-
do the following on your computer (not on the server):
- Set up a development environment
- Make sure that settings in the file
config/deploy.rd
are correct and that you have ssh access to the server - Run the following command in the development directory:
bundle exec rake vlad:setup
-
do the following on the server:
-
run these commands:
cd /deployment_path mkdir shared/config touch shared/config/{aaltoapps_config.yml,database.yml} chmod go= shared/config/{aaltoapps_config.yml,database.yml}
-
edit
shared/config/database.yml
:production: username: aaltoapps password: random_password database: aaltoapps adapter: postgresql
-
Copy config/aaltoapps_config.yml or config/aaltoapps_config_example.yml in your development directory to
shared/config/aaltoapps_config.yml
and edit it to suit your needs -
run the command:
gem install bundler
-
-
on your computer in the development directory:
bundle exec rake vlad:deploy
If the deployment fails, it may be because of a missing library. In that case install the library on the server and try again.
-