- HTTP server
nginx - Rails web server
passenger - Database
PosgreSQL - Deployment utility
mina
-
Set a name for your droplet
-
Select your droplet region
-
Select your droplet image (OS),
Ubuntuis prefered. -
After creating your droplet, you are going to receive an email from DigitalOcean which contains your
root passwordandinstance's IPYour new Droplet is all set to go! You can access it using the following credentials
Droplet Name: eastagile-droplet
IP Address: 104.236.34.222
Username: root
Password: dbvpnxgasrse
-
SSH to your
instance's IPwith yourroot passwordssh root@INSTANCE_IP
-
As of May 7, Ubuntu 14.04 x64, you may be asked to change root password
Changing password for root.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
-
Create a new user used for deployment
adduser deploy
-
You will be asked for your
deployuser password. Please keep it safe. -
You will be asked a few questions, all of them are optional so that you can hit
ENTERto skip those fields. -
Add your newly created user to
sudogroupgpasswd -a deploy sudo
-
Add a public key authentication
-
Generate a key pair (from your local machine)
ssh-keygen
-
Assumming your local username is
eastagile, you will see output similar to thisGenerating public/private rsa key pair.
Enter file in which to save the key (/Users/eastagile/.ssh/id_rsa):
-
Copy the public key
cat ~/.ssh/id_rsa.pub
-
It should print your public SSH key, which looks similar to this
ssh-rsa AAAAB3NzaC1yc2EAAAA...
-
Add public key to the new
deployuser-
On the server, as the root user, switch to
deployusersu - deploy
-
You are now in the
deployuser home folder, now create a.sshfoldermkdir ~/.ssh
chmod 700 ~/.ssh
-
In
.sshfolder, create a file calledauthorized_keysand add your public key to this filenano .ssh/authorized_keys
-
Restrict the permissions of this file
chmod 600 ~/.ssh/authorized_keys
-
Return to root user
exit
-
-
Configuring SSH
-
Opening configuration file
nano /etc/ssh/sshd_config
-
Disable root login through SSH by modifying this line in the configuration file
PermitRootLogin no
-
Save the file and reload SSH service
service ssh restart
-
-
-
SSH to your server via
deployuserssh deploy@INSTANCE_IP
-
Installing rvm
curl -sSL https://rvm.io/mpapis.asc | gpg --import -
curl -sSL https://get.rvm.io | bash -s stable
-
Exit your server and ssh to it again to re-sourcing the
.bashrcfile so that RVM is available -
Update all packages
sudo apt-get update
-
Install ruby
rvm install 2.2.3
-
Use current ruby as default system ruby
rvm use 2.2.3 --default
-
Double check if ruby is installed properly
ruby -v
ruby 2.2.3
-
Install
passengergemgem install passenger gem install bundler
-
Run the phusion passenger installer and follow the onscreen instruction
rvmsudo passenger-install-nginx-module
-
In my case, I have to run the following commands so that the installation process can continue
sudo apt-get install libcurl4-openssl-dev
sudo dd if=/dev/zero of=/swap bs=1M count=1024
sudo mkswap /swap
sudo swapon /swap
-
I chosed option 1 for
nginxinstallation (download, compile and install Nginx for me)
-
Installing PosgreSQL
sudo apt-get install postgresql postgresql-contrib
-
Login as
posgresusersudo -i -u postgres
-
Run the PosgreSQL console
psql
-
Create a new user and password for your upcoming Rails database (your database username will be
deployand your database password will bedeploypassword)create role deploy with createdb login password 'deploypassword';
-
Also create a
deploydatabase so that you can runpsqlfromdeployuser (type\qto quit thepsqlconsole)create database deploy;
-
Exit the
posgresuserexit
-
Install nginx as a service
wget -O init-deb.sh https://gist.githubusercontent.com/chautoni/1e1dea0ca1a43d245393/raw/c8825bf2e9c9243201e4e0e974626501592ce81e/init-deb.sh
sudo mv init-deb.sh /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults
sudo service nginx start
-
Edit the nginx configuration
sudo nano /opt/nginx/conf/nginx.conf
-
Please make sure that your
nginx.conflooks similar to this
server {
listen 80;
server_name example.com;
passenger_enabled on;
root /home/deploy/eastagile_digital_ocean_deployment/current/public;
}- Reload the nginx server
sudo service nginx restart
-
Generate mina sample
deploy.rbmina init
-
This is a sample
config/deploy.rbafter configration
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rvm' # for rvm support. (http://rvm.io)
set :domain, '104.236.34.222'
set :deploy_to, '/home/deploy/eastagile_digital_ocean_deployment'
set :repository, '[email protected]:chautoni/eastagile_digital_ocean_deployment.git'
set :branch, 'master'
set :shared_paths, ['config/database.yml', 'config/secrets.yml', 'log']
set :user, 'deploy' # Username in the server to SSH to.
set :forward_agent, true # SSH forward_agent.
task :environment do
invoke :'rvm:use[ruby-2.1.2@digital_ocean_deployment]'
end
task :setup => :environment do
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/log"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/log"]
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/config"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/config"]
queue! %[touch "#{deploy_to}/#{shared_path}/config/database.yml"]
queue %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/config/database.yml'."]
queue! %[touch "#{deploy_to}/#{shared_path}/config/secrets.yml"]
queue %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/config/secrets.yml'."]
end
desc "Deploys the current version to the server."
task :deploy => :environment do
to :before_hook do
# Put things to run locally before ssh
end
deploy do
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'rails:db_migrate'
invoke :'rails:assets_precompile'
invoke :'deploy:cleanup'
to :launch do
queue "mkdir -p #{deploy_to}/#{current_path}/tmp/"
queue "touch #{deploy_to}/#{current_path}/tmp/restart.txt"
end
end
end-
ssh to your server and create the designated folder for deployment
mkdir /home/eastagile_digital_ocean_deployment
-
Then run mina setup command in your local machine
mina setup
-----> Done.
-----> Be sure to edit '/home/deploy/eastagile_digital_ocean_deployment/shared/config/database.yml'.
-----> Be sure to edit '/home/deploy/eastagile_digital_ocean_deployment/shared/config/secrets.yml'.
-
ssh to your server and edit your
database.ymlandsecrets.ymlfile with appropriate credentials.
-
Installing git onto your server
sudo apt-get install git
-
Add
github.comcert to your serverknown_hostsssh-keyscan -H github.com >> ~/.ssh/known_hosts
-
Run
psqland createeastagile_digital_ocean_deploymentdatabasecreate database digital_ocean_production;
-
Install additional PosgreSQL and JS runtime packages
sudo apt-get install nodejs libpq-dev
-
Install gem bundle to install gem when deploy on specific gemset > rvm use ruby-2.1.2@digital_ocean_deployment > gem install bundle
-
Deploy to server from your local machine
mina deploy
- Version 1.0 - Initial guide (ThachChau)
- Version 1.1 - Update guide to latest ruby version 2.2.3
- Version 1.2 - Update missing command: install bundle before run
mina deploy