Skip to content

Latest commit

 

History

History
133 lines (104 loc) · 3.08 KB

server_setup.adoc

File metadata and controls

133 lines (104 loc) · 3.08 KB

Setting up the servers for our rails apps

Required gems

  # Capistrano for Deployment to server
  gem 'capistrano', require: false
  gem 'capistrano-rvm', require: false
  gem 'capistrano-bundler', require: false
  gem 'capistrano-rails', require: false
  gem 'capistrano-systemd', require: false
  gem 'capistrano-maintenance', require: false
  gem 'capistrano-pending', require: false
  gem 'pg' #postgres database

Add the capistrano-related gems to the development group and the pg gem to the production group.

Prerequisites

Install the dependencies on the server:

apt-get update
#postgres
apt-get install postgresql postgresql-contrib libpq-dev rbenv
#ruby build
apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev

Capistrano configuration

Setup capistrano in your repository by running:

bundle install
bundle exec cap install
 To minimize the configuration steps, copy the files over from one of the existing applications (gildamesh/dozentron).
Then update the following two configs in `config/deploy.rb`:
set :application, '<app name>'
set :repo_url, '<app repository url>'

Update the deploy configuration for production in config/deploy/production.rb:

server '<production server url>', user: 'production', roles: %w{app db web}
set :branch, 'master'

Add the following lines to the database configuration in config/database.yml:

server_default: &server_default
  adapter: postgresql
  encoding: unicode
  pool: 10

production:
  <<: *server_default

User & Postgres setup

The following steps must be repeated for each environment. The following guide creates only the production environment.

Create a user for each environment:

adduser --disabled-password production

Create the postgres user, his db and give him all privileges on the db:

#become postgres user
su - postgres

#create PG users
createuser production

#create db
createdb production

#set privileges by running the psql shell
psql
psql$ grant all privileges on database production to production;

rbenv setup

For each environment user, install the ruby-build plugin:

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
  1. install the needed ruby version:

rbenv install 2.5.1
rbenv rehash

(--- only done for production)

  1. and install bundler for this version:

rbenv local 2.5.1
rbenv exec gem install bundler

setup ssh access for deployment:

mkdir -p /home/{production,development,test}/.ssh

#copy authorized_keys & change owner
cp /root/.ssh/authorized_keys /home/production/.ssh
chown production:production /home/production/.ssh
chown production:production /home/production/.ssh/authorized_keys
chmod 700 /home/production/.ssh

generate an ssh-deploy-key and add them as deploy-key to your gitlab/-hub project:

su - production
production$ ssh-keygen -t rsa -C "production@time-tracker" -b 4096