From bed500090e3cfe7a9e42e540cc2b8407b4ffcfc5 Mon Sep 17 00:00:00 2001 From: Mike Wyatt Date: Wed, 20 Feb 2013 00:13:18 -0330 Subject: [PATCH 1/3] Capistrano deployment example scripts --- Capfile.example | 4 +++ config/deploy.rb.example | 72 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 Capfile.example create mode 100644 config/deploy.rb.example diff --git a/Capfile.example b/Capfile.example new file mode 100644 index 00000000..8863835d --- /dev/null +++ b/Capfile.example @@ -0,0 +1,4 @@ +load 'deploy' +load 'deploy/assets' +require 'bundler/capistrano' +load 'config/deploy' diff --git a/config/deploy.rb.example b/config/deploy.rb.example new file mode 100644 index 00000000..88da580d --- /dev/null +++ b/config/deploy.rb.example @@ -0,0 +1,72 @@ +set :domain, 'set application domain here' +set :db_adapter, 'mysql' # or postgres +set :mount_point, '/' +set :application, 'gitlabhq' +set :user, 'gitlab' +set :rails_env, 'production' +set :deploy_to, "/home/#{user}/apps/#{application}" +set :bundle_without, %w[development test] + (%w[mysql postgres] - [db_adapter]) +set :asset_env, "RAILS_GROUPS=assets RAILS_RELATIVE_URL_ROOT=#{mount_point.sub /\/+\Z/, ''}" + +set :use_sudo, false +default_run_options[:pty] = true + +# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none` +set :scm, :git +set :repository, "git@#{domain}:#{application}.git" +set :deploy_via, :remote_cache + +# Alternatively, you can deploy via copy, if you don't have gitlab in git +#set :scm, :none +#set :repository, '.' +#set :deploy_via, :copy + +server domain, :app, :web, :db, primary: true + +namespace :foreman do + desc 'Export the Procfile to Ubuntu upstart scripts' + task :export, roles: :app do + foreman_export = "foreman export upstart /etc/init -f Procfile -a #{application} -u #{user} -l #{shared_path}/log/foreman" + run "cd #{release_path} && #{sudo} #{fetch :bundle_cmd, 'bundle'} exec #{foreman_export}" + end + + desc 'Start the application services' + task :start, roles: :app do + run "#{sudo} service #{application} start" + end + + desc 'Stop the application services' + task :stop, roles: :app do + run "#{sudo} service #{application} stop" + end + + desc 'Restart the application services' + task :restart, roles: :app do + run "#{sudo} service #{application} restart" + end +end + +namespace :deploy do + desc 'Start the application services' + task :start, roles: :app do + foreman.start + end + + desc 'Stop the application services' + task :stop, roles: :app do + foreman.stop + end + + desc 'Restart the application services' + task :restart, roles: :app do + foreman.restart + end +end + +after 'deploy:cold' do + run "cd #{release_path} && #{rake} gitlab:setup force=yes RAILS_ENV=#{rails_env}" + deploy.restart +end + +after 'deploy:update', 'foreman:export' # Export foreman scripts +#after 'deploy:update', 'foreman:restart' # Restart application scripts From c6f5b96ba8102738dcb9bf21f00f0fcb8b4fe1d1 Mon Sep 17 00:00:00 2001 From: Mike Wyatt Date: Wed, 20 Feb 2013 00:14:03 -0330 Subject: [PATCH 2/3] allow force=yes rake gitlab:setup for capistrano deploy:cold --- lib/tasks/gitlab/setup.rake | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/tasks/gitlab/setup.rake b/lib/tasks/gitlab/setup.rake index 8d4950cf..5b74daf9 100644 --- a/lib/tasks/gitlab/setup.rake +++ b/lib/tasks/gitlab/setup.rake @@ -7,10 +7,12 @@ namespace :gitlab do def setup_db warn_user_is_not_gitlab - puts "This will create the necessary database tables and seed the database." - puts "You will lose any previous data stored in the database." - ask_to_continue - puts "" + unless ENV['force'] == 'yes' + puts "This will create the necessary database tables and seed the database." + puts "You will lose any previous data stored in the database." + ask_to_continue + puts "" + end Rake::Task["db:setup"].invoke Rake::Task["db:seed_fu"].invoke From 4243105eb5cba030eb6dcdc9cb4d18c977a4fe6b Mon Sep 17 00:00:00 2001 From: mikew Date: Wed, 20 Feb 2013 17:11:41 -0430 Subject: [PATCH 3/3] deploys under git user --- config/deploy.rb.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/deploy.rb.example b/config/deploy.rb.example index 88da580d..ddce4671 100644 --- a/config/deploy.rb.example +++ b/config/deploy.rb.example @@ -2,7 +2,7 @@ set :domain, 'set application domain here' set :db_adapter, 'mysql' # or postgres set :mount_point, '/' set :application, 'gitlabhq' -set :user, 'gitlab' +set :user, 'git' set :rails_env, 'production' set :deploy_to, "/home/#{user}/apps/#{application}" set :bundle_without, %w[development test] + (%w[mysql postgres] - [db_adapter])