Skip to content

Instantly share code, notes, and snippets.

@artiwarahd
Created July 22, 2019 17:17
Show Gist options
  • Save artiwarahd/848a2caa9ee65cb6823011983c5db075 to your computer and use it in GitHub Desktop.
Save artiwarahd/848a2caa9ee65cb6823011983c5db075 to your computer and use it in GitHub Desktop.
EDOC deploy steps
### Ubuntu 18.04 x64 + Rails 5 + Nginx + Unicorn + PostgreSQL9.6 + Capistrano 3
SSH to server
$ ssh <user>@xxx.xxx.xxx.xx
$ sudo chown <user>:<user> /var/www/
Generate public key
$ su - <user>
$ mkdir ~/.ssh
$ cd ~/.ssh
$ ssh-keygen
Add authorized_keys
$ nano authorized_keys # then add your key
Install Curl
$ sudo apt-get update
$ sudo apt-get install curl
Install RVM
$ curl -L get.rvm.io | bash -s stable
$ source /etc/profile.d/rvm.sh (!!This command has changed, please see in the log after install rvm success)
$ rvm requirements
$ rvm install 2.4.2
$ rvm use 2.4.2 --default
$ rvm rubygems current
Install PostgreSQL
If got an error, please visit: https://www.postgresql.org/download/linux/ubuntu/
$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
$ wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install postgresql-9.6 postgresql-server-dev-9.6
$ gem install pg -- --with-pg-config=/usr/bin/pg_config
Create Postgres User
$ sudo -u postgres psql
create user <user> with password 'xxxxxxxx';
alter role <user> superuser createrole createdb replication;
create database <database_name> owner <user>;
Install GIT
$ sudo apt-get install git-core
Install Bundler
$ gem install bundler
Setup Nginx
$ sudo apt-get install nginx
$ nginx -h
$ cat /etc/init.d/nginx
$ /etc/init.d/nginx -h
$ sudo service nginx start
$ sudo vim /etc/nginx/sites-enabled/default
upstream unicorn {
server unix:/var/www/rails/<app_name>/current/tmp/sockets/unicorn.edocapi.sock fail_timeout=0;
}
server {
listen 80 default deferred;
# server_name example.com;
root /var/www/rails/<app_name>/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location ~ ^/(robots.txt|sitemap.xml.gz)/ {
root /var/www/rails/<app_name>/current/public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
Exit from ssh
$ exit
Update Production Deploy Config
$ vim config/deploy/production.rb
set :port, 22
set :user, '<username>'
set :deploy_via, :remote_cache
set :use_sudo, false
server 'xxx.xxx.xxx.xx', port: fetch(:port), user: fetch(:user), roles: %w{app db web}
set :stage, :production
set :rails_env, :production
set :unicorn_env, :production
set :unicorn_rack_env, 'production'
set :branch, "master"
Add server SSH Key to Bitbucket
1. goto https://bitbucket.org
2. select a project
3. goto Setting
4. goto Access keys
5. Add key
Check Deployment (Commit and Push)
$ cap production deploy:check
Deploy
$ cap production deploy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment