Skip to content

Instantly share code, notes, and snippets.

@johnrlive
Forked from dariocravero/deploy.rb
Created July 21, 2013 01:04
Show Gist options
  • Save johnrlive/6047077 to your computer and use it in GitHub Desktop.
Save johnrlive/6047077 to your computer and use it in GitHub Desktop.
require 'mina/git'
require 'mina/rbenv'
require 'mina-contrib/rbenv'
require 'mina-contrib/config'
require 'mina-contrib/bundler'
require 'mina-contrib/safety-check'
require 'mina-contrib/nginx'
require 'mina-contrib/puma'
set :term_mode, :pretty
set :application, :'your-app'
set :environment, :production
set :domain, 'your-server'
set :branch, :master
set :user, 'deploy-user'
set :deploy_to, lambda { "/home/deploy-user/apps/#{application}" }
set :nginx_upstream, lambda { puma_socket }
set :application_domain_names, 'your-app.com'
set :repository, 'git@your-server:your-app-repo.git'
set :shared_paths, ['config/puma.rb', 'config/nginx.conf', 'tmp/puma', 'log']
set :keep_releases, 3
set :config_tasks, [:'puma:config', :'nginx:config']
task :load_environment do
invoke :'rbenv:load'
end
desc 'Deploys the current version to the server'
task :deploy => :load_environment do
deploy do
invoke :'git:clone'
invoke :'bundler:install'
invoke :'deploy:link_shared_paths'
invoke :'deploy:cleanup'
to :launch do
invoke :'puma:restart'
end
end
end
desc 'Creates an instance of this master api server'
task :create => :load_environment do
invoke :'deploy:safety_check'
invoke :setup
deploy do
invoke :'git:clone'
invoke :'bundler:install'
invoke :'deploy:link_shared_paths'
to :launch do
invoke :'config:all'
# # The folders need to exist for puma to be configured
invoke :'puma:config'
invoke :'nginx:reload'
invoke :'puma:start'
end
end
end
desc 'Destroys the instance'
task :destroy do
queue %{echo "-----> Destroying the app"}
# invoke :'monit:destroy'
invoke :'puma:destroy'
invoke :'nginx:destroy'
queue %{
echo "-----> Removing the app's directory"
#{echo_cmd "rm -rf #{deploy_to}"}
}
end
upstream <%= nginx_site %> {
server <%= nginx_upstream %>;
}
server {
listen 80;
server_name <%= application_domain_names %>;
keepalive_timeout 5;
root <%= deploy_to %>/current/public;
access_log <%= "#{deploy_to}/#{shared_path}/log/nginx.access.log" %>;
error_log <%= "#{deploy_to}/#{shared_path}/log/nginx.error.log" %>;
location ^~ /(javascripts|stylesheets)/(.+) {
deny all;
}
location / {
if ($http_user_agent ~ "MSIE 6.0" ) {
root <%= deploy_to %>/current/ancient-browser;
}
if ($http_user_agent ~ "MSIE 7.0" ) {
root <%= deploy_to %>/current/ancient-browser;
}
if ($http_user_agent ~ "MSIE 8.0" ) {
root <%= deploy_to %>/current/ancient-browser;
}
try_files /system/maintenance.html $uri $uri/index.html $uri.html @app;
}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://<%= nginx_site %>;
}
}
environment "<%= environment %>"
threads <%= puma_min_threads %>,<%= puma_max_threads %>
bind "<%= puma_socket %>"
pidfile "<%= puma_pid %>"
state_path "<%= puma_state %>"
<%= "activate_control_app" if puma_activate_control_app %>
<% if puma_on_restart %>
on_restart do
<%= puma_on_restart %>
end
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment