From bc59fd046f9f786c8bbc5512a9177359b384b329 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Thu, 17 Jan 2013 21:19:36 +0100 Subject: [PATCH 1/3] Add a warning prompt to the setup task --- lib/tasks/gitlab/setup.rake | 24 +++++++++++++++++++----- lib/tasks/gitlab/task_helpers.rake | 27 +++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/lib/tasks/gitlab/setup.rake b/lib/tasks/gitlab/setup.rake index 572a22aa1f6..ce6d0eb363d 100644 --- a/lib/tasks/gitlab/setup.rake +++ b/lib/tasks/gitlab/setup.rake @@ -1,10 +1,24 @@ namespace :gitlab do namespace :app do desc "GITLAB | Setup production application" - task :setup => [ - 'db:setup', - 'db:seed_fu', - 'gitlab:enable_automerge' - ] + task :setup => :environment do + setup + end + + def setup + 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 "" + + Rake::Task["db:setup"].invoke + Rake::Task["db:seed_fu"].invoke + Rake::Task["gitlab:enable_automerge"].invoke + rescue Gitlab::TaskAbortedByUserError + puts "Quitting...".red + exit 1 + end end end diff --git a/lib/tasks/gitlab/task_helpers.rake b/lib/tasks/gitlab/task_helpers.rake index 12fd5181ecb..d494125f76c 100644 --- a/lib/tasks/gitlab/task_helpers.rake +++ b/lib/tasks/gitlab/task_helpers.rake @@ -1,5 +1,18 @@ +module Gitlab + class TaskAbortedByUserError < StandardError; end +end + namespace :gitlab do + # Ask if the user wants to continue + # + # Returns "yes" the user chose to continue + # Raises Gitlab::TaskAbortedByUserError if the user chose *not* to continue + def ask_to_continue + answer = prompt("Do you want to continue (yes/no)? ".blue, %w{yes no}) + raise Gitlab::TaskAbortedByUserError unless answer == "yes" + end + # Check which OS is running # # It will primarily use lsb_relase to determine the OS. @@ -22,6 +35,20 @@ namespace :gitlab do os_name.try(:squish!) end + # Prompt the user to input something + # + # message - the message to display before input + # choices - array of strings of acceptible answers or nil for any answer + # + # Returns the user's answer + def prompt(message, choices = nil) + begin + print(message) + answer = STDIN.gets.chomp + end while choices.present? && !choices.include?(answer) + answer + end + # Runs the given command and matches the output agains the given pattern # # Returns nil if nothing matched From b7457f39b48a067fe142be5486895dc08224963f Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Thu, 17 Jan 2013 21:20:18 +0100 Subject: [PATCH 2/3] Remove the setup task from the maintenance docs --- doc/raketasks/maintenance.md | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/doc/raketasks/maintenance.md b/doc/raketasks/maintenance.md index 758580b6832..ee5a8a3b5fb 100644 --- a/doc/raketasks/maintenance.md +++ b/doc/raketasks/maintenance.md @@ -1,16 +1,3 @@ -### Setup production application - -Runs the following rake tasks: - -* db:setup (Create the database, load the schema, and initialize with the seed data) -* db:seed_fu (Loads seed data for the current environment.) -* gitlab:app:enable_automerge (see "Features") - -``` -bundle exec rake gitlab:app:setup RAILS_ENV=production -``` - - ### Gather information about GitLab and the system it runs on This command gathers information about your GitLab installation and the System From 65c35466b695b06807c997859ce4ca5b515b6550 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Thu, 17 Jan 2013 21:26:22 +0100 Subject: [PATCH 3/3] Rename gitlab:app:setup task to gitlab:setup --- doc/install/installation.md | 2 +- lib/tasks/gitlab/setup.rake | 34 ++++++++++++++++------------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/doc/install/installation.md b/doc/install/installation.md index 12a0cc917be..811f8a45f42 100644 --- a/doc/install/installation.md +++ b/doc/install/installation.md @@ -260,7 +260,7 @@ used for the `email.from` setting in `config/gitlab.yml`) ## Initialise Database and Activate Advanced Features - sudo -u gitlab -H bundle exec rake gitlab:app:setup RAILS_ENV=production + sudo -u gitlab -H bundle exec rake gitlab:setup RAILS_ENV=production ## Install Init Script diff --git a/lib/tasks/gitlab/setup.rake b/lib/tasks/gitlab/setup.rake index ce6d0eb363d..5699e5d6188 100644 --- a/lib/tasks/gitlab/setup.rake +++ b/lib/tasks/gitlab/setup.rake @@ -1,24 +1,22 @@ namespace :gitlab do - namespace :app do - desc "GITLAB | Setup production application" - task :setup => :environment do - setup - end + desc "GITLAB | Setup production application" + task :setup => :environment do + setup + end - def setup - warn_user_is_not_gitlab + def setup + 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 "" + 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 "" - Rake::Task["db:setup"].invoke - Rake::Task["db:seed_fu"].invoke - Rake::Task["gitlab:enable_automerge"].invoke - rescue Gitlab::TaskAbortedByUserError - puts "Quitting...".red - exit 1 - end + Rake::Task["db:setup"].invoke + Rake::Task["db:seed_fu"].invoke + Rake::Task["gitlab:enable_automerge"].invoke + rescue Gitlab::TaskAbortedByUserError + puts "Quitting...".red + exit 1 end end