Open vdias38 opened 2 years ago
https://rubygems.org/gems/bundler/versions On deploy we use gem v1.17 released on October 25, 2018, latest version is 2.3.11 - April 07, 2022
debian@vps-4316bebe:~$ gem list
YAML safe loading is not available. Please upgrade psych to a version that supports safe loading (>= 2.0).
*** LOCAL GEMS ***
bigdecimal (1.1.0)
bundler (1.17.0, default: 1.16.6)
bundler-unload (1.0.2)
executable-hooks (1.6.1)
gem-wrappers (1.4.0)
io-console (0.3)
json (1.5.5)
minitest (2.5.1)
passenger (6.0.13, 6.0.2)
rack (1.6.11)
rake (0.9.2.2)
rdoc (3.9.5)
rubygems-bundler (1.4.5)
rvm (1.11.3.9)
debian@vps-4316bebe:~$ ruby -v
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]
meumobi@vps-4316bebe:/home/debian$ ssh -T git@github.com
Hi vdias38! You've successfully authenticated, but GitHub does not provide shell access
We’ll be using SSH Keys for authorization. First shake hands with GitHub, the Git Remote where the codebase is hosted.
deploy$ ssh -T git@github.com
Hi vdias38! You've successfully authenticated, but GitHub does not provide shell access.
Don’t worry if you get a Permission denied (publickey) message. Check if you have a SSH key (a Public/Private Key Pair) for your server, should be saved as ~/.ssh/id_rsa
(private key) and ~/.ssh/id_rsa.pub
(public key).
I you don't have a SSH key generate one:
deploy$ ssh-keygen -t rsa
Add the public key (~/.ssh/id_rsa.pub) to your repository’s deployment keys:
If all the steps were completed correctly, you should now be able to clone your git repository (over the SSH Protocol, not HTTP) without entering your password:
deploy$ git clone git@github.com:meumobi/yahooStocksService.git
The git clone command will create a directory with the same name as your app.
We are cloning only to check if our deployment keys are working, we don’t need to clone or pull our repository every time we push new changes. We’ll let Capistrano handle all that for us. You can now delete this cloned directory if you want to.
Open a terminal on your local machine. If you don’t have a SSH Key for your local computer, create one for it as well, and add your local SSH Key to your server Authorized Keys file:
local$ scp ~/.ssh/id_rsa.pub deploy@vps-4316bebe.vps.ovh.net:~/.ssh/authorized_keys
On your local machine, create configuration for Capistrano. Start by adding these lines to the Gemfile on root App:
source 'https://rubygems.org'
group :development do
gem 'capistrano', require: false
gem 'capistrano-rvm', require: false
gem 'capistrano-bundler', require: false
end
Use bundler to install the gems you just specified in your Gemfile. Enter the following command to bundle your App:
local$ bundle install --path vendor/bundle
Using rake 13.0.6
Using net-ssh 6.1.0
Using net-scp 3.0.0
Using sshkit 1.21.2
Using airbrussh 1.4.0
Using bundler 1.17.2
Using concurrent-ruby 1.1.10
Using i18n 1.10.0
Using capistrano 3.17.0
Using capistrano-bundler 2.0.1
Using capistrano-rvm 0.1.2
Bundle complete! 3 Gemfile dependencies, 11 gems now installed.
Bundled gems are installed into `./vendor/bundle`
After bundling, run the following command to configure Capistrano:
local$ bundle exec cap install
This will create:
Capfile
in the root directory of your Appdeploy.rb
file in the config directorydeploy
directory in the config directoryReplace the contents of your Capfile
with the following:
# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
require 'capistrano/bundler'
require 'capistrano/rvm'
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
This Capfile
loads some pre-defined tasks in to your Capistrano configuration files to make your deployments hassle-free, such as automatically:
You can list available tasks:
local$ bundle exec cap -T
cap bundler:clean # Remove unused gems installed by bundler
cap bundler:config # Configure the Bundler environment for the release so that subequent
cap bundler:install # Install the current Bundler environment
cap bundler:map_bins # Maps all binaries to use `bundle exec` by default
cap deploy # Deploy a new release
cap deploy:check # Check required files and directories exist
...
cap doctor # Display a Capistrano troubleshooting report (all doctor: tasks)
cap doctor:environment # Display Ruby environment details
cap doctor:gems # Display Capistrano gem versions
cap doctor:servers # Display the effective servers configuration
cap doctor:variables # Display the values of all Capistrano variables
cap git:check # Check that the repository is reachable
cap git:clone # Clone the repo to the cache
cap git:create_release # Copy repo to releases
cap git:set_current_revision # Determine the revision that will be deployed
cap git:update # Update the repo mirror to reflect the origin state
cap git:wrapper # Upload the git wrapper script, this script guarantees that we can script git without getting an...
cap install # Install Capistrano, cap install STAGES=staging,production
cap rvm:check # Prints the RVM and Ruby version on the target host
Replace the contents of config/deploy.rb
with the following:
# config valid for current version and patch releases of Capistrano
lock "~> 3.17.0"
set :application, "yahooStocksService"
set :repo_url, 'git@github.com:meumobi/yahooStocksService.git'
# Default branch is :master, else `bundle exec cap meumobi-03 deploy BRANCH=chore/upgrade-cap `
set :branch, ENV['BRANCH'] || 'master'
And create a custom config for each stage you need, for example config/deploy/production.rb
:
role :app, %w{vps-4316bebe.vps.ovh.net}
set :deploy_to, '/home/meumobi/PROJECTS/services.meumobi.com'
set :ssh_options, {
user: 'meumobi'
}
You can set any configuration variable like in config/deploy.rb. These variables are then only loaded and set in this stage.