Commit 309e2ceaf85929cc1d8dceaa24620cc1bdae0ede

Authored by Dmitriy Zaporozhets
2 parents 4bb1664a 65c35466

Merge pull request #2650 from riyad/setup-task-warning

Improve setup task, by making it less dangerous
doc/install/installation.md
@@ -260,7 +260,7 @@ used for the `email.from` setting in `config/gitlab.yml`) @@ -260,7 +260,7 @@ used for the `email.from` setting in `config/gitlab.yml`)
260 260
261 ## Initialise Database and Activate Advanced Features 261 ## Initialise Database and Activate Advanced Features
262 262
263 - sudo -u gitlab -H bundle exec rake gitlab:app:setup RAILS_ENV=production 263 + sudo -u gitlab -H bundle exec rake gitlab:setup RAILS_ENV=production
264 264
265 265
266 ## Install Init Script 266 ## Install Init Script
doc/raketasks/maintenance.md
1 -### Setup production application  
2 -  
3 -Runs the following rake tasks:  
4 -  
5 -* db:setup (Create the database, load the schema, and initialize with the seed data)  
6 -* db:seed_fu (Loads seed data for the current environment.)  
7 -* gitlab:app:enable_automerge (see "Features")  
8 -  
9 -```  
10 -bundle exec rake gitlab:app:setup RAILS_ENV=production  
11 -```  
12 -  
13 -  
14 ### Gather information about GitLab and the system it runs on 1 ### Gather information about GitLab and the system it runs on
15 2
16 This command gathers information about your GitLab installation and the System 3 This command gathers information about your GitLab installation and the System
lib/tasks/gitlab/setup.rake
1 namespace :gitlab do 1 namespace :gitlab do
2 - namespace :app do  
3 - desc "GITLAB | Setup production application"  
4 - task :setup => [  
5 - 'db:setup',  
6 - 'db:seed_fu',  
7 - 'gitlab:enable_automerge'  
8 - ] 2 + desc "GITLAB | Setup production application"
  3 + task :setup => :environment do
  4 + setup
  5 + end
  6 +
  7 + def setup
  8 + warn_user_is_not_gitlab
  9 +
  10 + puts "This will create the necessary database tables and seed the database."
  11 + puts "You will lose any previous data stored in the database."
  12 + ask_to_continue
  13 + puts ""
  14 +
  15 + Rake::Task["db:setup"].invoke
  16 + Rake::Task["db:seed_fu"].invoke
  17 + Rake::Task["gitlab:enable_automerge"].invoke
  18 + rescue Gitlab::TaskAbortedByUserError
  19 + puts "Quitting...".red
  20 + exit 1
9 end 21 end
10 end 22 end
lib/tasks/gitlab/task_helpers.rake
  1 +module Gitlab
  2 + class TaskAbortedByUserError < StandardError; end
  3 +end
  4 +
1 namespace :gitlab do 5 namespace :gitlab do
2 6
  7 + # Ask if the user wants to continue
  8 + #
  9 + # Returns "yes" the user chose to continue
  10 + # Raises Gitlab::TaskAbortedByUserError if the user chose *not* to continue
  11 + def ask_to_continue
  12 + answer = prompt("Do you want to continue (yes/no)? ".blue, %w{yes no})
  13 + raise Gitlab::TaskAbortedByUserError unless answer == "yes"
  14 + end
  15 +
3 # Check which OS is running 16 # Check which OS is running
4 # 17 #
5 # It will primarily use lsb_relase to determine the OS. 18 # It will primarily use lsb_relase to determine the OS.
@@ -22,6 +35,20 @@ namespace :gitlab do @@ -22,6 +35,20 @@ namespace :gitlab do
22 os_name.try(:squish!) 35 os_name.try(:squish!)
23 end 36 end
24 37
  38 + # Prompt the user to input something
  39 + #
  40 + # message - the message to display before input
  41 + # choices - array of strings of acceptible answers or nil for any answer
  42 + #
  43 + # Returns the user's answer
  44 + def prompt(message, choices = nil)
  45 + begin
  46 + print(message)
  47 + answer = STDIN.gets.chomp
  48 + end while choices.present? && !choices.include?(answer)
  49 + answer
  50 + end
  51 +
25 # Runs the given command and matches the output agains the given pattern 52 # Runs the given command and matches the output agains the given pattern
26 # 53 #
27 # Returns nil if nothing matched 54 # Returns nil if nothing matched