groupadd admin
useradd deployer -G admin -m -s /bin/bash
passwd deployer
ssh-copy-id deployer@server-ip
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev libpq-dev
# Qt and xvfb-run for Capybara Webkit
sudo apt-get install -y libqtwebkit-dev xvfb
# ImageMagick and Rmagick
sudo apt-get install -y imagemagick libmagickwand-dev
sudo apt-get install -y git nodejs
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
# Download keys if needed
# gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.2.0
rvm use 2.2.0 --default
ruby -v
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
~/.rbenv/bin/rbenv init
mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
rbenv install <ruby-version>
rbenv global <ruby-verions>
copy eval "$(rbenv init -)" to the bottom of .bash_profile so ruby -v works
sudo apt-get install -y dirmngr gnupg
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates
# Add our APT repository
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update
# Install Passenger + Nginx
sudo apt-get install -y nginx-extras passenger
# sudo vim /etc/nginx/nginx.conf` and uncomment as needed:
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/ruby;
# passenger_ruby /home/deployer/.rvm/wrappers/ruby-2.2.0/ruby; # If using rvm
# passenger_ruby /home/deployer/.rbenv/shims/ruby; # If using rbenv
Edit /etc/nginx/nginx.conf and uncomment include /etc/nginx/passenger.conf; Restart nginx
sudo apt-get install postgresql postgresql-contrib
sudo -i -u postgres
createuser --interactive
Enter name of role to add: deployer
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
postgres@programservices:~$ exit```
OR
sudo su - postgres
createuser USERNAME --pwprompt
exit
# sudo sudo -u postgres psql -1 -c "CREATE USER deployer WITH PASSWORD 'secret';"
# sudo sudo -u postgres psql -1 -c "ALTER USER deployer WITH SUPERUSER;"
# sudo sudo -u postgres psql -1 -c "CREATE DATABASE awesomeapp_prod;"
- Check PG port with
netstat -an |grep 5432
- Change
pg_hba
authentication mode frompeer
tomd5
if needed - sudo -u postgres psql my_app_development
- create extension hstore;
If you are using the bare bones $5/mo droplet then...
sudo dd if=/dev/zero of=/swapfile bs=1024 count=256k
sudo mkswap /swapfile
sudo swapon /swapfile
See also https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-12-04
group :development do
# ....
gem 'capistrano'
gem 'capistrano-rails'
gem 'capistrano-bundler'
# gem 'capistrano-rbenv'
gem 'capistrano-rvm'
gem 'capistrano-passenger'
end
bundle install
bundle --binstubs
cap --install
# Load DSL and set up stages
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/passenger'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
lock '3.4.0'
set :application, 'awesomeapp'
set :repo_url, '[email protected]:Mardiniii/scrapping-workshop.git'
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
set :deploy_to, '/home/deployer/awesomeapp'
set :scm, :git
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
set :keep_releases, 5
namespace :deploy do
# Not needed if using capistrano-passenger gem/recipe
# desc 'Restart application'
# task :restart do
# on roles(:app), in: :sequence, wait: 5 do
# execute :touch, release_path.join('tmp/restart.txt')
# end
# end
after :publishing, 'deploy:restart'
after :finishing, 'deploy:cleanup'
end
server '104.236.76.72', user: 'deployer', roles: %w{app db web}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
# server_name mydomain.com;
server_name localhost;
passenger_enabled on;
rails_env production;
root /home/deployer/awesomeapp/current/public;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
pg: &pg
adapter: postgresql
encoding: unicode
username: pgadmin
password: secret
host: localhost
pool: 5
production:
<<: *pg
database: awesomeapp_prod
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
cap production deploy
cap production deploy:restart
cap -T