Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save frizbee/33eb67dc4586a53f56133172d4c3e781 to your computer and use it in GitHub Desktop.
Save frizbee/33eb67dc4586a53f56133172d4c3e781 to your computer and use it in GitHub Desktop.

install nodejs

sudo apt-get update
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
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.list
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 nodejs yarn

install ruby

sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.4.2
rvm use 2.4.2@shift-manager --create  
gem install bundler

install nginx

sudo apt-get install nginx
sudo service nginx start

install mysql

sudo apt-get install mysql-server mysql-client libmysqlclient-dev
mysql -u root -p
CREATE DATABASE shift_manager_staging;

install capistrano

gem 'puma', '~> 3.11'
group :development do
    gem 'capistrano', '~> 3.10.1'
	gem 'capistrano-rails', '~> 1.3.1'
	gem 'capistrano-rvm', '~> 0.1.2'
	gem 'capistrano3-puma', '~> 3.1', '>= 3.1.1'
end

create capfile

bundle install
bundle exec cap install

config Capfile

require "capistrano/rvm"
require 'capistrano/rails'
require 'capistrano/puma'
require 'capistrano/puma/nginx'
install_plugin Capistrano::Puma
install_plugin Capistrano::Puma::Nginx

config config/deploy.rb

set :application, "my_app_name"
set :repo_url, "git@gitlab.com:thanhtoan1196/deploy_test.git"
append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system", "public/uploads", "vendor/bundle"
append :linked_files, "config/database.yml", "config/secrets.yml"

set :nginx_server_name, "localhost #{fetch(:application)}.local stg.shiftmanager.visunware.com"

set :rvm_type, :user
set :rvm_ruby_version, '2.4.2@shift-manager'

config config/deploy/staging.rb

server '34.257.22.153', user: 'ubuntu', roles: %w{app db web}
set :deploy_to, "/home/ubuntu/deploy_staging/#{fetch(:rails_env)}"
set :branch, :master
set :stage, :staging
set :ssh_options, {
    keys: %w(~/.ssh/shift-manager.pem),
    auth_methods: %w(publickey)
}

create /home/ubuntu/deploy_staging/shared/config/database.yml

staging:
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password: abcd
  socket: /var/run/mysqld/mysqld.sock
  database: shift_manager_staging

create /home/ubuntu/deploy_staging/shared/config/secrets.yml

rake secret
staging:
   secret_key_base: xxx

config puma

cap staging deploy:check
cap staging puma:config
cap staging puma:nginx_config
cap staging deploy

seed database

bundle exec rake db:seed RAILS_ENV=staging

restart nginx

sudo service nginx restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment