Last active
August 2, 2023 09:14
-
-
Save imtiaz-emu/dcb87fde71a9562037d2 to your computer and use it in GitHub Desktop.
Gist about capistrano deployment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load DSL and Setup Up Stages | |
require 'capistrano/setup' | |
# Includes default deployment tasks | |
require 'capistrano/deploy' | |
#load 'deploy/assets' | |
require 'capistrano/rails' | |
require 'rvm1/capistrano3' | |
require 'capistrano/bundler' | |
require 'capistrano/rails/assets' | |
require 'capistrano/rails/migrations' | |
require 'capistrano/file-permissions' | |
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined. | |
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config valid only for Capistrano 3.1 | |
lock '3.2.1' | |
set :application, 'your_app_name' | |
set :repo_url, 'your_repo_url.git' | |
set :user, 'deployer' // your server SSH user | |
set :use_sudo, false | |
# Default branch is :master | |
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call | |
# Default deploy_to directory is /var/www/my_app | |
# Default value for :scm is :git | |
set :scm, :git | |
set :deploy_via, :remote_cache # off while it is first deployment | |
# Default value for :format is :pretty | |
# set :format, :pretty | |
set :rvm1_ruby_version, "ruby-2.1.5" | |
# Default value for :log_level is :debug | |
# set :log_level, :debug | |
# Default value for :pty is false | |
# set :pty, true | |
# Default value for :linked_files is [] | |
set :linked_files, %w{config/database.yml} | |
# Default value for linked_dirs is [] | |
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle} | |
set :linked_dirs, fetch(:linked_dirs) + %w{public/system public/uploads} | |
# Default value for default_env is {} | |
# set :default_env, { path: "/opt/ruby/bin:$PATH" } | |
set :pty, true | |
# Default value for keep_releases is 5 | |
set :keep_releases, 5 | |
# set config unicorn.rb, unicorn_init.sh, nginx.conf file permission after deployment | |
set :file_permissions_roles, :all | |
set :file_permissions_users, ['deployer'] | |
set :file_permissions_chmod_mode, "0777" | |
namespace :deploy do | |
desc 'Restart application' | |
task :restart do | |
on roles(:app), in: :sequence, wait: 1 do | |
# Your restart mechanism here, for example: | |
execute :touch, release_path.join('tmp/restart.txt') | |
# execute "sudo service nginx restart" | |
# execute "sudo service unicorn restart" | |
end | |
end | |
before "deploy:updated", "deploy:set_permissions:chmod" | |
after :publishing, :restart | |
after :restart, :clear_cache do | |
on roles(:web), in: :groups, limit: 3, wait: 10 do | |
# Here we can do anything such as: | |
# within release_path do | |
# execute :rake, 'cache:clear' | |
# end | |
end | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
group :development, :test do | |
gem 'capistrano', '~> 3.2.1' | |
gem 'capistrano-ext', '~> 1.2.1' | |
gem 'capistrano-rails', '~> 1.1.2' | |
gem 'rvm1-capistrano3', require: false | |
gem 'capistrano-file-permissions', '~> 0.1.0' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set :stage, :production # change environment | |
set :branch, 'master' # change git brunch name | |
set :server_name, "104.123.30.92 " | |
set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}" | |
# Simple Role Syntax | |
# ================== | |
# Supports bulk-adding hosts to roles, the primary server in each group | |
# is considered to be the first unless any hosts have the primary | |
# property set. Don't declare `role :all`, it's a meta role. | |
# | |
#role :app, %w{[email protected]} | |
#role :web, %w{[email protected]} | |
#role :db, %w{[email protected]} | |
# set your own server's IP | |
role :web, "104.123.30.92 " # Your HTTP server, Apache/etc | |
role :app, "104.123.30.92 " # This may be the same as your `Web` server | |
role :db, "104.123.30.92 ", :primary => true # This is where Rails migrations will run | |
set :deploy_to, '/home/deployer/apps/your_app' # change the directory of project | |
set 'rails_env', :staging | |
# Extended Server Syntax | |
# ====================== | |
# This can be used to drop a more detailed server definition into the | |
# server list. The second argument is a, or duck-types, Hash and is | |
# used to set extended properties on the server. | |
#server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value | |
# Custom SSH Options | |
# ================== | |
# You may pass any option but keep in mind that net/ssh understands a | |
# limited set of options, consult[net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start). | |
# | |
# Global options | |
# -------------- | |
set :ssh_options, { | |
forward_agent: false, | |
auth_methods: %w(password), | |
password: '********', # change to your password | |
user: 'deployer', # change to your server SSH user | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment