Sarmad Sabih
Full Stack Senior Software Engineer
Principal Software Engineer
Syed Sarmad Sabih
CreativeChaos
Full-Stack Software Engineer
Coding in Ruby for 6+ years
Aspiring Writer
Run code without thinking about servers. Pay only for the compute time you consume.
Requirements
Let's Get The Hands Dirty
Make Changes To The Gemfile
gem "capistrano3-puma"
gem "capistrano"
gem "capistrano-bundler", require: false
gem "capistrano-rvm"
gem "capistrano-rails", require: false
gem "aws-sdk-autoscaling"
gem "aws-sdk-ec2"
Setup EC2 instance using this Sitepoint article of mine: https://www.sitepoint.com/continous-deployment-of-rails-with-semaphoreci/
Setup Infrastructure
Configure Nginx In /etc/nginx/sites-available/default:
upstream app {
# Path to Puma SOCK file, as defined previously
server unix:///home/ubuntu/deploy_like_a_pro/shared/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 80;
server_name localhost;
root /home/ubuntu/deploy_like_a_pro/current/public;
try_files $uri/index.html $uri @app;
location / {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Connection '';
proxy_pass http://app;
}
location ~ ^/(assets|fonts|system)/|favicon.ico|robots.txt {
gzip_static on;
expires max;
add_header Cache-Control public;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
Create an AMI image of the EC2 instance, which will be used as a template by the Auto Scaling group when scaling up servers.
Note: Your EC2 servers' SSH key must be added to your Github, Bitbucket or Gitlab account. And your deployment machine's SSH key must be added in all of your EC2 instances' authorized_keys file.
Setup Capistrano
Prepare For The First Deployment
Taking It Further
Final Steps
Get In Touch
LinkedIn: https://www.linkedin.com/in/sarmad-sabih-754b5264
Github: https://www.github.com/sarmad90
I Write At
If this meetup has inspired you to take Ruby on Rails on a spin, then you should give this piece a read:
https://medium.com/@sarmadsabih/a-brief-guide-to-learning-ruby-on-rails-b5c0e32acabb
By Sarmad Sabih