Deploy Rails without Capistrano and anger
BLAh blah not finished article yet.
First think which you need to know — you don’t have to use Capistrano for deploy your ruby on rails web application.
1. Setting ubuntu
WARNING: DON”T USE UBUNTU up than 18.04 yet. Because Passenger.
$ adduser deploy
$ adduser deploy sudo #add user to sudo group
$ cd .. && cd /home/deploy
$ mkdir .ssh
$ ssh-keygen -t rsa -C 'enotikalt@gmail.com'
STOP COPYING!!!!
when shh program will ask you about place of file — past this:
/home/deploy/.ssh/id_rsa
Generate ssh on server and add public ssh key from your local computer to file /home/someuser/.ssh/authorized_keys
on a server.
install nodejs, yarn, redis-server etc
# Adding Node.js repositorycurl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -# Adding Yarn repo
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.listsudo add-apt-repository ppa:chris-lea/redis-server# Refresh our packages list with the new repositoriessudo apt-get update# Install our dependencies for compiiling Ruby along with Node.js and Yarnsudo 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 software-properties-common libffi-dev dirmngr gnupg apt-transport-https ca-certificates redis-server redis-tools nodejs yarn
RBENV is sucks. Let’s install rvm
$ gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB$ \curl -sSL https://get.rvm.io | bash
CREATE Gemset. Gemset is a folder inside RVM (like box). In this place you can install gems, but in the future, when you will want to update your rails application for newest rails version — you can just create new gemset (box with gems lol). If something went wrong — just change CURRENT gemset and it will works again.
Check your bundler gem version on local machine and install it in gemset on server
$ bundle info bundler
server
$ gem install bundler -v 3.3.3.3.3
2. Passenger
INSTALL PASSENGER
passenger it’s a program which knows how to work with ruby projects. It works after nginx get request
# Install our PGP key and add HTTPS support for APT
$ 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 bionic main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update# Install Passenger + Nginx module
sudo apt-get install -y libnginx-mod-http-passenger
enable the Passenger Nginx module and restart Nginx
$ if [ ! -f /etc/nginx/modules-enabled/50-mod-http-passenger.conf ]; then sudo ln -s /usr/share/nginx/modules-available/mod-http-passenger.load /etc/nginx/modules-enabled/50-mod-http-passenger.conf ; fi
$ sudo ls /etc/nginx/conf.d/mod-http-passenger.conf
If you don’t see a file at /etc/nginx/conf.d/mod-http-passenger.conf
; then you need to create it yourself and set the passenger_ruby
and passenger_root
config options. For example:
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/passenger_free_ruby;#REWRITE THIS LINE TO:->passenger_ruby /home/deploy/.rvm/wrappers/ruby-3.0.0@r6131/ruby;
—
$ sudo service nginx restart
YAY!
3. NGINX, DATABASE, ENVIRONMENT VARIABLES
connect to server
clone your your project from github
git clone git://github.com/username/myapp.git
WARNING : REMEMBER NAME OF THIS FOLDER
sudo rm /etc/nginx/sites-enabled/default
sudo vim /etc/nginx/sites-enabled/myapp
server {
listen 80;
listen [::]:80;
server_name 1.2.3.4; #this is yout ip or domain name
root /home/deploy/myapp/public;
passenger_enabled on;
passenger_app_env production;
location /cable {
passenger_app_group_name myapp_websocket;
passenger_force_max_concurrent_requests_per_process 0;
}
# Allow uploads up to 100MB in size
client_max_body_size 100m;
location ~ ^/(assets|packs) {
expires max;
gzip_static on;
}
}
$ sudo service nginx reload
$ sudo apt-get install postgresql postgresql-contrib libpq-dev
$ sudo -u postgres psql
psql#> create role deploy with createdb login password ‘qwerty’;$ psql -d postgres -U myuser # myuser == created role inside postgres before
It will login you to user which we was create inside postgresql
> create database myapp_production;
export DATABASE_URL=postgresql://deploy:juice@127.0.0.1/myapp_production
export RAILS_MASTER_KEY=bla2bla3
export RAILS_SECRET_KEY_BASE=keyFrom_rails_credentialsEdit
export REDIS_URL=redis://127.0.0.1:6379/1
export RAILS_ENV=production
export REDIS_SIDEKIQ_DB=0# For Postgres
export DATABASE_URL=postgresql://deploy:PASSWORD@127.0.0.1/myapp
# For MySQL
export DATABASE_URL=mysql2://deploy:$omeFancyPassword123@localhost/myapp
export RAILS_MASTER_KEY=ohai
export SECRET_KEY_BASE=1234567890
STRIPE_PUBLIC_KEY=x
STRIPE_PRIVATE_KEY=y
thats all, your app is works now. Check your ip via browser