diff options
author | Riyad Preukschas <riyad@informatik.uni-bremen.de> | 2013-01-15 00:52:25 +0100 |
---|---|---|
committer | Riyad Preukschas <riyad@informatik.uni-bremen.de> | 2013-01-15 00:52:25 +0100 |
commit | 30227869482bbbdbfea153f2b45ef3bb9a9fd218 (patch) | |
tree | aff64071116447092751770d2896998f62d1b44a /lib/tasks | |
parent | 8ee5fce9d64b70d8981896457484fae622d142c9 (diff) | |
parent | aca0caa8cc1a6bd481f87dd810284e69d3747050 (diff) | |
download | gitlab-ce-30227869482bbbdbfea153f2b45ef3bb9a9fd218.tar.gz |
Merge commit 'master' into discussions
Conflicts:
app/assets/stylesheets/sections/notes.scss
app/contexts/notes/load_context.rb
app/models/project.rb
app/observers/note_observer.rb
app/roles/votes.rb
app/views/commit/show.html.haml
app/views/merge_requests/_show.html.haml
app/views/merge_requests/diffs.js.haml
app/views/merge_requests/show.js.haml
app/views/notes/_note.html.haml
features/steps/project/project_merge_requests.rb
spec/models/note_spec.rb
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/gitlab/backup.rake | 106 | ||||
-rw-r--r-- | lib/tasks/gitlab/check.rake | 161 | ||||
-rw-r--r-- | lib/tasks/gitlab/cleanup.rake | 128 | ||||
-rw-r--r-- | lib/tasks/gitlab/enable_automerge.rake | 36 | ||||
-rw-r--r-- | lib/tasks/gitlab/enable_namespaces.rake | 95 | ||||
-rw-r--r-- | lib/tasks/gitlab/generate_docs.rake | 7 | ||||
-rw-r--r-- | lib/tasks/gitlab/gitolite_rebuild.rake | 21 | ||||
-rw-r--r-- | lib/tasks/gitlab/import.rake | 12 | ||||
-rw-r--r-- | lib/tasks/gitlab/info.rake | 31 | ||||
-rw-r--r-- | lib/tasks/gitlab/task_helpers.rake | 39 | ||||
-rw-r--r-- | lib/tasks/resque.rake | 10 | ||||
-rw-r--r-- | lib/tasks/sidekiq.rake | 23 | ||||
-rw-r--r-- | lib/tasks/travis.rake | 12 |
13 files changed, 465 insertions, 216 deletions
diff --git a/lib/tasks/gitlab/backup.rake b/lib/tasks/gitlab/backup.rake index 44da6d671e0..ae2b1bb793f 100644 --- a/lib/tasks/gitlab/backup.rake +++ b/lib/tasks/gitlab/backup.rake @@ -5,6 +5,8 @@ namespace :gitlab do # Create backup of GitLab system desc "GITLAB | Create a backup of the GitLab system" task :create => :environment do + warn_user_is_not_gitlab + Rake::Task["gitlab:backup:db:create"].invoke Rake::Task["gitlab:backup:repo:create"].invoke @@ -22,23 +24,23 @@ namespace :gitlab do end # create archive - print "Creating backup archive: #{Time.now.to_i}_gitlab_backup.tar " + print "Creating backup archive: #{Time.now.to_i}_gitlab_backup.tar ... " if Kernel.system("tar -cf #{Time.now.to_i}_gitlab_backup.tar repositories/ db/ backup_information.yml") - puts "[DONE]".green + puts "done".green else - puts "[FAILED]".red + puts "failed".red end # cleanup: remove tmp files - print "Deleting tmp directories..." + print "Deleting tmp directories ... " if Kernel.system("rm -rf repositories/ db/ backup_information.yml") - puts "[DONE]".green + puts "done".green else - puts "[FAILED]".red + puts "failed".red end # delete backups - print "Deleting old backups... " + print "Deleting old backups ... " if Gitlab.config.backup.keep_time > 0 file_list = Dir.glob("*_gitlab_backup.tar").map { |f| f.split(/_/).first.to_i } file_list.sort.each do |timestamp| @@ -46,15 +48,17 @@ namespace :gitlab do %x{rm #{timestamp}_gitlab_backup.tar} end end - puts "[DONE]".green + puts "done".green else - puts "[SKIPPING]".yellow + puts "skipping".yellow end end # Restore backup of GitLab system desc "GITLAB | Restore a previously created backup" task :restore => :environment do + warn_user_is_not_gitlab + Dir.chdir(Gitlab.config.backup.path) # check for existing backups in the backup dir @@ -63,22 +67,22 @@ namespace :gitlab do if file_list.count > 1 && ENV["BACKUP"].nil? puts "Found more than one backup, please specify which one you want to restore:" puts "rake gitlab:backup:restore BACKUP=timestamp_of_backup" - exit 1; + exit 1 end tar_file = ENV["BACKUP"].nil? ? File.join("#{file_list.first}_gitlab_backup.tar") : File.join(ENV["BACKUP"] + "_gitlab_backup.tar") unless File.exists?(tar_file) puts "The specified backup doesn't exist!" - exit 1; + exit 1 end - print "Unpacking backup... " + print "Unpacking backup ... " unless Kernel.system("tar -xf #{tar_file}") - puts "[FAILED]".red + puts "failed".red exit 1 else - puts "[DONE]".green + puts "done".green end settings = YAML.load_file("backup_information.yml") @@ -86,7 +90,7 @@ namespace :gitlab do # restoring mismatching backups can lead to unexpected problems if settings[:gitlab_version] != %x{git rev-parse HEAD}.gsub(/\n/,"") - puts "gitlab_version mismatch:".red + puts "GitLab version mismatch:".red puts " Your current HEAD differs from the HEAD in the backup!".red puts " Please switch to the following revision and try again:".red puts " revision: #{settings[:gitlab_version]}".red @@ -97,11 +101,11 @@ namespace :gitlab do Rake::Task["gitlab:backup:repo:restore"].invoke # cleanup: remove tmp files - print "Deleting tmp directories..." + print "Deleting tmp directories ... " if Kernel.system("rm -rf repositories/ db/ backup_information.yml") - puts "[DONE]".green + puts "done".green else - puts "[FAILED]".red + puts "failed".red end end @@ -114,12 +118,23 @@ namespace :gitlab do task :create => :environment do backup_path_repo = File.join(Gitlab.config.backup.path, "repositories") FileUtils.mkdir_p(backup_path_repo) until Dir.exists?(backup_path_repo) - puts "Dumping repositories:" - project = Project.all.map { |n| [n.path, n.path_to_repo] } - project << ["gitolite-admin.git", File.join(Gitlab.config.git_base_path, "gitolite-admin.git")] - project.each do |project| - print "- Dumping repository #{project.first}... " - if Kernel.system("cd #{project.second} > /dev/null 2>&1 && git bundle create #{backup_path_repo}/#{project.first}.bundle --all > /dev/null 2>&1") + puts "Dumping repositories ...".blue + + Project.find_each(:batch_size => 1000) do |project| + print " * #{project.path_with_namespace} ... " + + if project.empty_repo? + puts "[SKIPPED]".cyan + next + end + + # Create namespace dir if missing + FileUtils.mkdir_p(File.join(backup_path_repo, project.namespace.path)) if project.namespace + + # Build a destination path for backup + path_to_bundle = File.join(backup_path_repo, project.path_with_namespace + ".bundle") + + if Kernel.system("cd #{project.repository.path_to_repo} > /dev/null 2>&1 && git bundle create #{path_to_bundle} --all > /dev/null 2>&1") puts "[DONE]".green else puts "[FAILED]".red @@ -129,18 +144,21 @@ namespace :gitlab do task :restore => :environment do backup_path_repo = File.join(Gitlab.config.backup.path, "repositories") - puts "Restoring repositories:" - project = Project.all.map { |n| [n.path, n.path_to_repo] } - project << ["gitolite-admin.git", File.join(File.dirname(project.first.second), "gitolite-admin.git")] - project.each do |project| - print "- Restoring repository #{project.first}... " - FileUtils.rm_rf(project.second) if File.dirname(project.second) # delete old stuff - if Kernel.system("cd #{File.dirname(project.second)} > /dev/null 2>&1 && git clone --bare #{backup_path_repo}/#{project.first}.bundle #{project.first}.git > /dev/null 2>&1") - permission_commands = [ - "sudo chmod -R g+rwX #{Gitlab.config.git_base_path}", - "sudo chown -R #{Gitlab.config.ssh_user}:#{Gitlab.config.ssh_user} #{Gitlab.config.git_base_path}" - ] - permission_commands.each { |command| Kernel.system(command) } + repos_path = Gitlab.config.gitolite.repos_path + + puts "Restoring repositories ... " + + Project.find_each(:batch_size => 1000) do |project| + print "#{project.path_with_namespace} ... " + + if project.namespace + project.namespace.ensure_dir_exist + end + + # Build a backup path + path_to_bundle = File.join(backup_path_repo, project.path_with_namespace + ".bundle") + + if Kernel.system("git clone --bare #{path_to_bundle} #{project.repository.path_to_repo} > /dev/null 2>&1") puts "[DONE]".green else puts "[FAILED]".red @@ -156,9 +174,9 @@ namespace :gitlab do backup_path_db = File.join(Gitlab.config.backup.path, "db") FileUtils.mkdir_p(backup_path_db) unless Dir.exists?(backup_path_db) - puts "Dumping database tables:" + puts "Dumping database tables ... ".blue ActiveRecord::Base.connection.tables.each do |tbl| - print "- Dumping table #{tbl}... " + print " * #{tbl.yellow} ... " count = 1 File.open(File.join(backup_path_db, tbl + ".yml"), "w+") do |file| ActiveRecord::Base.connection.select_all("SELECT * FROM `#{tbl}`").each do |line| @@ -167,25 +185,25 @@ namespace :gitlab do file << output.to_yaml.gsub(/^---\n/,'') + "\n" count += 1 end - puts "[DONE]".green + puts "done".green end end end - task :restore=> :environment do + task :restore => :environment do backup_path_db = File.join(Gitlab.config.backup.path, "db") - puts "Restoring database tables:" + puts "Restoring database tables (loading fixtures) ... " Rake::Task["db:reset"].invoke Dir.glob(File.join(backup_path_db, "*.yml") ).each do |dir| fixture_file = File.basename(dir, ".*" ) - print "- Loading fixture #{fixture_file}..." + print "#{fixture_file.yellow} ... " if File.size(dir) > 0 ActiveRecord::Fixtures.create_fixtures(backup_path_db, fixture_file) - puts "[DONE]".green + puts "done".green else - puts "[SKIPPING]".yellow + puts "skipping".yellow end end end diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index baa706d2bee..5d850a17fe3 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -48,24 +48,24 @@ namespace :gitlab do see_database_guide, "http://guides.rubyonrails.org/getting_started.html#configuring-a-database" ) - check_failed + fix_and_rerun end end def check_database_is_not_sqlite - print "Database is not SQLite ... " + print "Database is SQLite ... " database_config_file = Rails.root.join("config", "database.yml") - unless File.read(database_config_file) =~ /sqlite/ - puts "yes".green + unless File.read(database_config_file) =~ /adapter:\s+sqlite/ + puts "no".green else - puts "no".red + puts "yes".red for_more_information( "https://github.com/gitlabhq/gitlabhq/wiki/Migrate-from-SQLite-to-MySQL", see_database_guide ) - check_failed + fix_and_rerun end end @@ -85,7 +85,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "GitLab" ) - check_failed + fix_and_rerun end end @@ -98,7 +98,7 @@ namespace :gitlab do end # omniauth or ldap could have been deleted from the file - unless Gitlab.config.pre_40_config + unless Gitlab.config['git_host'] puts "no".green else puts "yes".red @@ -110,7 +110,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "GitLab" ) - check_failed + fix_and_rerun end end @@ -129,7 +129,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Install Init Script" ) - check_failed + fix_and_rerun end end @@ -155,7 +155,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Install Init Script" ) - check_failed + fix_and_rerun end end @@ -171,7 +171,7 @@ namespace :gitlab do try_fixing_it( "sudo -u gitlab -H bundle exec rake db:migrate" ) - check_failed + fix_and_rerun end end @@ -189,6 +189,8 @@ namespace :gitlab do if project.satellite.exists? puts "yes".green + elsif project.empty_repo? + puts "can't create, repository is empty".magenta else puts "no".red try_fixing_it( @@ -199,7 +201,7 @@ namespace :gitlab do for_more_information( "doc/raketasks/maintenance.md " ) - check_failed + fix_and_rerun end end end @@ -220,7 +222,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "GitLab" ) - check_failed + fix_and_rerun end end @@ -240,7 +242,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "GitLab" ) - check_failed + fix_and_rerun end end end @@ -254,7 +256,7 @@ namespace :gitlab do start_checking "Environment" check_gitlab_in_git_group - check_issue_1056_shell_profile_error + check_issue_1059_shell_profile_error check_gitlab_git_config check_python2_exists check_python2_version @@ -288,7 +290,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "GitLab" ) - check_failed + fix_and_rerun end end @@ -306,16 +308,16 @@ namespace :gitlab do for_more_information( see_installation_guide_section "System Users" ) - check_failed + fix_and_rerun end end # see https://github.com/gitlabhq/gitlabhq/issues/1059 - def check_issue_1056_shell_profile_error + def check_issue_1059_shell_profile_error gitolite_ssh_user = Gitlab.config.gitolite.ssh_user print "Has no \"-e\" in ~#{gitolite_ssh_user}/.profile ... " - profile_file = File.expand_path("~#{Gitlab.config.gitolite.ssh_user}/.profile") + profile_file = File.join(gitolite_home, ".profile") unless File.read(profile_file) =~ /^-e PATH/ puts "yes".green @@ -330,7 +332,7 @@ namespace :gitlab do see_installation_guide_section("Gitolite"), "https://github.com/gitlabhq/gitlabhq/issues/1059" ) - check_failed + fix_and_rerun end end @@ -350,7 +352,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Packages / Dependencies" ) - check_failed + fix_and_rerun end end @@ -376,7 +378,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Packages / Dependencies" ) - check_failed + fix_and_rerun end end end @@ -396,6 +398,7 @@ namespace :gitlab do check_dot_gitolite_user_and_group check_dot_gitolite_permissions check_repo_base_exists + check_repo_base_is_not_symlink check_repo_base_user_and_group check_repo_base_permissions check_can_clone_gitolite_admin @@ -432,7 +435,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end # assumes #check_can_clone_gitolite_admin has been run before @@ -464,7 +467,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun ensure FileUtils.rm_rf("/tmp/gitolite_gitlab_test") end @@ -472,7 +475,7 @@ namespace :gitlab do def check_dot_gitolite_exists print "Config directory exists? ... " - gitolite_config_path = File.expand_path("~#{Gitlab.config.gitolite.ssh_user}/.gitolite") + gitolite_config_path = File.join(gitolite_home, ".gitolite") if File.directory?(gitolite_config_path) puts "yes".green @@ -486,14 +489,14 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end end def check_dot_gitolite_permissions print "Config directory access is drwxr-x---? ... " - gitolite_config_path = File.expand_path("~#{Gitlab.config.gitolite.ssh_user}/.gitolite") + gitolite_config_path = File.join(gitolite_home, ".gitolite") unless File.exists?(gitolite_config_path) puts "can't check because of previous errors".magenta return @@ -503,14 +506,13 @@ namespace :gitlab do puts "yes".green else puts "no".red - puts "#{gitolite_config_path} is not writable".red try_fixing_it( "sudo chmod 750 #{gitolite_config_path}" ) for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end end @@ -518,7 +520,7 @@ namespace :gitlab do gitolite_ssh_user = Gitlab.config.gitolite.ssh_user print "Config directory owned by #{gitolite_ssh_user}:#{gitolite_ssh_user} ... " - gitolite_config_path = File.expand_path("~#{gitolite_ssh_user}/.gitolite") + gitolite_config_path = File.join(gitolite_home, ".gitolite") unless File.exists?(gitolite_config_path) puts "can't check because of previous errors".magenta return @@ -536,13 +538,13 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end end def check_gitolite_is_up_to_date print "Using recommended version ... " - if gitolite_version.try(:start_with?, "v3.04") + if gitolite_version.try(:start_with?, "v3.2") puts "yes".green else puts "no".red @@ -581,7 +583,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end end @@ -610,7 +612,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end end @@ -634,7 +636,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Setup GitLab Hooks" ) - check_failed + fix_and_rerun end end @@ -644,7 +646,6 @@ namespace :gitlab do hook_file = "post-receive" gitolite_hooks_path = File.join(Gitlab.config.gitolite.hooks_path, "common") gitolite_hook_file = File.join(gitolite_hooks_path, hook_file) - gitolite_hook_content = File.read(gitolite_hook_file) gitolite_ssh_user = Gitlab.config.gitolite.ssh_user unless File.exists?(gitolite_hook_file) @@ -652,6 +653,7 @@ namespace :gitlab do return end + gitolite_hook_content = File.read(gitolite_hook_file) gitlab_hook_file = Rails.root.join.join("lib", "hooks", hook_file) gitlab_hook_content = File.read(gitlab_hook_file) @@ -665,7 +667,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Setup GitLab Hooks" ) - check_failed + fix_and_rerun end end @@ -687,7 +689,27 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun + end + end + + def check_repo_base_is_not_symlink + print "Repo base directory is a symlink? ... " + + repo_base_path = Gitlab.config.gitolite.repos_path + unless File.exists?(repo_base_path) + puts "can't check because of previous errors".magenta + return + end + + unless File.symlink?(repo_base_path) + puts "no".green + else + puts "yes".red + try_fixing_it( + "Make sure it's set to the real directory in config/gitlab.yml" + ) + fix_and_rerun end end @@ -711,7 +733,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end end @@ -737,7 +759,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end end @@ -758,7 +780,7 @@ namespace :gitlab do print "#{project.name_with_namespace.yellow} ... " correct_options = options.map do |name, value| - run("git --git-dir=\"#{project.path_to_repo}\" config --get #{name}").try(:chomp) == value + run("git --git-dir=\"#{project.repository.path_to_repo}\" config --get #{name}").try(:chomp) == value end if correct_options.all? @@ -771,7 +793,7 @@ namespace :gitlab do for_more_information( "doc/raketasks/maintenance.md" ) - check_failed + fix_and_rerun end end end @@ -797,7 +819,7 @@ namespace :gitlab do Project.find_each(batch_size: 100) do |project| print "#{project.name_with_namespace.yellow} ... " - project_hook_file = File.join(project.path_to_repo, "hooks", hook_file) + project_hook_file = File.join(project.repository.path_to_repo, "hooks", hook_file) unless File.exists?(project_hook_file) puts "missing".red @@ -807,7 +829,7 @@ namespace :gitlab do for_more_information( "lib/support/rewrite-hooks.sh" ) - check_failed + fix_and_rerun next end @@ -821,7 +843,7 @@ namespace :gitlab do for_more_information( "lib/support/rewrite-hooks.sh" ) - check_failed + fix_and_rerun end end end @@ -849,7 +871,7 @@ namespace :gitlab do namespace :resque do - desc "GITLAB | Check the configuration of Resque" + desc "GITLAB | Check the configuration of Sidekiq" task check: :environment do warn_user_is_not_gitlab start_checking "Resque" @@ -866,7 +888,7 @@ namespace :gitlab do def check_resque_running print "Running? ... " - if run_and_match("ps aux | grep -i resque", /resque-[\d\.]+:.+$/) + if run_and_match("ps aux | grep -i sidekiq", /sidekiq \d\.\d\.\d.+$/) puts "yes".green else puts "no".red @@ -877,9 +899,9 @@ namespace :gitlab do ) for_more_information( see_installation_guide_section("Install Init Script"), - "see log/resque.log for possible errors" + "see log/sidekiq.log for possible errors" ) - check_failed + fix_and_rerun end end end @@ -888,7 +910,7 @@ namespace :gitlab do # Helper methods ########################## - def check_failed + def fix_and_rerun puts " Please #{"fix the error above"} and rerun the checks.".red end @@ -907,29 +929,6 @@ namespace :gitlab do puts "" end - # Runs the given command - # - # Returns nil if the command was not found - # Returns the output of the command otherwise - # - # see also #run_and_match - def run(command) - unless `#{command} 2>/dev/null`.blank? - `#{command}` - end - end - - # Runs the given command and matches the output agains the given pattern - # - # Returns nil if nothing matched - # Retunrs the MatchData if the pattern matched - # - # see also #run - # see also String#match - def run_and_match(command, pattern) - run(command).try(:match, pattern) - end - def see_database_guide "doc/install/databases.md" end @@ -951,18 +950,4 @@ namespace :gitlab do puts " #{step}" end end - - def warn_user_is_not_gitlab - unless @warned_user_not_gitlab - current_user = run("whoami").chomp - unless current_user == "gitlab" - puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}" - puts " You are running as user #{current_user.magenta}, we hope you know what you are doing." - puts " Some tests may pass\/fail for the wrong reason." - puts " For meaningful results you should run this as user #{"gitlab".magenta}." - puts "" - end - @warned_user_not_gitlab = true - end - end end diff --git a/lib/tasks/gitlab/cleanup.rake b/lib/tasks/gitlab/cleanup.rake new file mode 100644 index 00000000000..2a0ffe0f4bd --- /dev/null +++ b/lib/tasks/gitlab/cleanup.rake @@ -0,0 +1,128 @@ +namespace :gitlab do + namespace :cleanup do + desc "GITLAB | Cleanup | Clean gitolite config" + task :config => :environment do + warn_user_is_not_gitlab + + real_repos = Project.all.map(&:path_with_namespace) + real_repos << "gitolite-admin" + real_repos << "@all" + + remove_flag = ENV['REMOVE'] + + puts "Looking for repositories to remove... " + Gitlab::GitoliteConfig.new.apply do |config| + all_repos = [] + garbage_repos = [] + + all_repos = config.conf.repos.keys + garbage_repos = all_repos - real_repos + + garbage_repos.each do |repo_name| + if remove_flag + config.conf.rm_repo(repo_name) + print "to remove...".red + end + + puts repo_name.red + end + end + + unless remove_flag + puts "To cleanup repositories run this command with REMOVE=true".yellow + end + end + + desc "GITLAB | Cleanup | Clean namespaces" + task :dirs => :environment do + warn_user_is_not_gitlab + remove_flag = ENV['REMOVE'] + + + namespaces = Namespace.pluck(:path) + git_base_path = Gitlab.config.gitolite.repos_path + all_dirs = Dir.glob(git_base_path + '/*') + + puts git_base_path.yellow + puts "Looking for directories to remove... " + + all_dirs.reject! do |dir| + # skip if git repo + dir =~ /.git$/ + end + + all_dirs.reject! do |dir| + dir_name = File.basename dir + + # skip if namespace present + namespaces.include?(dir_name) + end + + all_dirs.each do |dir_path| + + if remove_flag + if FileUtils.rm_rf dir_path + puts "Removed...#{dir_path}".red + else + puts "Cannot remove #{dir_path}".red + end + else + puts "Can be removed: #{dir_path}".red + end + end + + unless remove_flag + puts "To cleanup this directories run this command with REMOVE=true".yellow + end + end + + desc "GITLAB | Cleanup | Clean respositories" + task :repos => :environment do + warn_user_is_not_gitlab + remove_flag = ENV['REMOVE'] + + git_base_path = Gitlab.config.gitolite.repos_path + all_dirs = Dir.glob(git_base_path + '/*') + + global_projects = Project.where(namespace_id: nil).pluck(:path) + + puts git_base_path.yellow + puts "Looking for global repos to remove... " + + # skip non git repo + all_dirs.select! do |dir| + dir =~ /.git$/ + end + + # skip existing repos + all_dirs.reject! do |dir| + repo_name = File.basename dir + path = repo_name.gsub(/\.git$/, "") + global_projects.include?(path) + end + + # skip gitolite admin + all_dirs.reject! do |dir| + repo_name = File.basename dir + repo_name == 'gitolite-admin.git' + end + + + all_dirs.each do |dir_path| + if remove_flag + if FileUtils.rm_rf dir_path + puts "Removed...#{dir_path}".red + else + puts "Cannot remove #{dir_path}".red + end + else + puts "Can be removed: #{dir_path}".red + end + end + + unless remove_flag + puts "To cleanup this directories run this command with REMOVE=true".yellow + end + end + end +end diff --git a/lib/tasks/gitlab/enable_automerge.rake b/lib/tasks/gitlab/enable_automerge.rake index ed3d6368a99..e92da81021f 100644 --- a/lib/tasks/gitlab/enable_automerge.rake +++ b/lib/tasks/gitlab/enable_automerge.rake @@ -1,16 +1,42 @@ namespace :gitlab do desc "GITLAB | Enable auto merge" task :enable_automerge => :environment do + warn_user_is_not_gitlab + + puts "Updating repo permissions ..." Gitlab::Gitolite.new.enable_automerge + puts "... #{"done".green}" + puts "" + + print "Creating satellites for ..." + unless Project.count > 0 + puts "skipping, because you have no projects".magenta + next + end + puts "" + + Project.find_each(batch_size: 100) do |project| + print "#{project.name_with_namespace.yellow} ... " - Project.find_each do |project| - if project.repo_exists? && !project.satellite.exists? - puts "Creating satellite for #{project.name}...".green + unless project.repo_exists? + puts "skipping, because the repo is empty".magenta + next + end + + if project.satellite.exists? + puts "exists already".green + else + puts "" project.satellite.create + + print "... " + if $?.success? + puts "created".green + else + puts "error".red + end end end - - puts "Done!".green end namespace :satellites do diff --git a/lib/tasks/gitlab/enable_namespaces.rake b/lib/tasks/gitlab/enable_namespaces.rake index 1be9ba6469d..aa76a2f7d83 100644 --- a/lib/tasks/gitlab/enable_namespaces.rake +++ b/lib/tasks/gitlab/enable_namespaces.rake @@ -1,67 +1,116 @@ namespace :gitlab do desc "GITLAB | Enable usernames and namespaces for user projects" task enable_namespaces: :environment do - print "\nUsernames for users:".yellow + warn_user_is_not_gitlab + migrate_user_namespaces + migrate_groups + migrate_projects + + puts "Rebuild Gitolite ... " + gitolite = Gitlab::Gitolite.new + gitolite.update_repositories(Project.where('namespace_id IS NOT NULL')) + puts "... #{"done".green}" + end + + def migrate_user_namespaces + puts "\nGenerate usernames for users without one: ".blue User.find_each(batch_size: 500) do |user| - next if user.namespace + if user.namespace + print '-'.cyan + next + end - User.transaction do - username = user.email.match(/^[^@]*/)[0] - if user.update_attributes!(username: username) + username = if user.username.present? + # if user already has username filled + user.username + else + build_username(user) + end + + begin + User.transaction do + user.update_attributes!(username: username) print '.'.green - else - print 'F'.red end + rescue + print 'F'.red end end + puts "\nDone" + end + + def build_username(user) + username = nil + + # generate username + username = user.email.match(/^[^@]*/)[0] + username.gsub!("+", ".") + + # return username if no mathes + return username unless User.find_by_username(username) + + # look for same username + (1..10).each do |i| + suffixed_username = "#{username}#{i}" + + return suffixed_username unless User.find_by_username(suffixed_username) + end + end - print "\n\nDirs for groups:".yellow + def migrate_groups + puts "\nCreate directories for groups: ".blue Group.find_each(batch_size: 500) do |group| - if group.ensure_dir_exist - print '.'.green - else + begin + if group.dir_exists? + print '-'.cyan + else + if group.ensure_dir_exist + print '.'.green + else + print 'F'.red + end + end + rescue print 'F'.red end end + puts "\nDone" + end - print "\n\nMove projects from groups under groups dirs:".yellow + def migrate_projects git_path = Gitlab.config.gitolite.repos_path - + puts "\nMove projects in groups into respective directories ... ".blue Project.where('namespace_id IS NOT NULL').find_each(batch_size: 500) do |project| next unless project.group group = project.group - puts "\n" - print " * #{project.name}: " + print "#{project.name_with_namespace.yellow} ... " new_path = File.join(git_path, project.path_with_namespace + '.git') if File.exists?(new_path) - print "ok. already at #{new_path}".cyan + puts "already at #{new_path}".green next end old_path = File.join(git_path, project.path + '.git') unless File.exists?(old_path) - print "missing. not found at #{old_path}".red + puts "couldn't find it at #{old_path}".red next end begin Gitlab::ProjectMover.new(project, '', group.path).execute - print "ok. Moved to #{new_path}".green + puts "moved to #{new_path}".green rescue - print "Failed moving to #{new_path}".red + puts "failed moving to #{new_path}".red end end - print "\n\nRebuild gitolite:".yellow - gitolite = Gitlab::Gitolite.new - gitolite.update_repositories(Project.where('namespace_id IS NOT NULL')) - puts "\n" + puts "\nDone" end end diff --git a/lib/tasks/gitlab/generate_docs.rake b/lib/tasks/gitlab/generate_docs.rake new file mode 100644 index 00000000000..58795fac4af --- /dev/null +++ b/lib/tasks/gitlab/generate_docs.rake @@ -0,0 +1,7 @@ +namespace :gitlab do + desc "GITLAB | Generate sdocs for project" + task generate_docs: :environment do + system("bundle exec sdoc -o doc/code app lib") + end +end + diff --git a/lib/tasks/gitlab/gitolite_rebuild.rake b/lib/tasks/gitlab/gitolite_rebuild.rake index fce10eb5b69..af2a2127ee2 100644 --- a/lib/tasks/gitlab/gitolite_rebuild.rake +++ b/lib/tasks/gitlab/gitolite_rebuild.rake @@ -1,24 +1,27 @@ namespace :gitlab do namespace :gitolite do - desc "GITLAB | Rebuild each project at gitolite config" + desc "GITLAB | Rebuild each project in Gitolite config" task :update_repos => :environment do - puts "Starting Projects" + warn_user_is_not_gitlab + + puts "Rebuilding projects ... " Project.find_each(:batch_size => 100) do |project| - puts "\n=== #{project.name}" + puts "#{project.name_with_namespace.yellow} ... " project.update_repository - puts + puts "... #{"done".green}" end - puts "Done with projects" end - desc "GITLAB | Rebuild each key at gitolite config" + desc "GITLAB | Rebuild each user key in Gitolite config" task :update_keys => :environment do - puts "Starting Key" + warn_user_is_not_gitlab + + puts "Rebuilding keys ... " Key.find_each(:batch_size => 100) do |key| + puts "#{key.identifier.yellow} ... " Gitlab::Gitolite.new.set_key(key.identifier, key.key, key.projects) - print '.' + puts "... #{"done".green}" end - puts "Done with keys" end end end diff --git a/lib/tasks/gitlab/import.rake b/lib/tasks/gitlab/import.rake index 81f66e2e406..4bf9110508e 100644 --- a/lib/tasks/gitlab/import.rake +++ b/lib/tasks/gitlab/import.rake @@ -15,15 +15,23 @@ namespace :gitlab do git_base_path = Gitlab.config.gitolite.repos_path repos_to_import = Dir.glob(git_base_path + '/*') + namespaces = Namespace.pluck(:path) + repos_to_import.each do |repo_path| repo_name = File.basename repo_path + # Skip if group or user + next if namespaces.include?(repo_name) + + # skip if not git repo + next unless repo_name =~ /.git$/ + # skip gitolite admin next if repo_name == 'gitolite-admin.git' path = repo_name.sub(/\.git$/, '') - project = Project.find_by_path(path) + project = Project.find_with_namespace(path) puts "Processing #{repo_name}".yellow @@ -34,8 +42,6 @@ namespace :gitlab do project_params = { :name => path, - :code => path, - :path => path, } project = Project.create_by_user(project_params, user) diff --git a/lib/tasks/gitlab/info.rake b/lib/tasks/gitlab/info.rake index 85458fe2c43..fd3e83e8338 100644 --- a/lib/tasks/gitlab/info.rake +++ b/lib/tasks/gitlab/info.rake @@ -12,7 +12,10 @@ namespace :gitlab do debian_version = File.read('/etc/debian_version') "Debian #{debian_version}" end - os_name.squish! + os_name ||= if File.readable?('/etc/SuSE-release') + File.read('/etc/SuSE-release') + end + os_name.try(:squish!) # check if there is an RVM environment rvm_version = run_and_match("rvm --version", /[\d\.]+/).try(:to_s) @@ -80,31 +83,5 @@ namespace :gitlab do puts "Git:\t\t#{Gitlab.config.git.bin_path}" end - - - # Helper methods - - # Runs the given command and matches the output agains the given pattern - # - # Returns nil if nothing matched - # Retunrs the MatchData if the pattern matched - # - # see also #run - # see also String#match - def run_and_match(command, regexp) - run(command).try(:match, regexp) - end - - # Runs the given command - # - # Returns nil if the command was not found - # Returns the output of the command otherwise - # - # see also #run_and_match - def run(command) - unless `#{command} 2>/dev/null`.blank? - `#{command}` - end - end end end diff --git a/lib/tasks/gitlab/task_helpers.rake b/lib/tasks/gitlab/task_helpers.rake new file mode 100644 index 00000000000..c9635f058ee --- /dev/null +++ b/lib/tasks/gitlab/task_helpers.rake @@ -0,0 +1,39 @@ +namespace :gitlab do + + # Runs the given command and matches the output agains the given pattern + # + # Returns nil if nothing matched + # Retunrs the MatchData if the pattern matched + # + # see also #run + # see also String#match + def run_and_match(command, regexp) + run(command).try(:match, regexp) + end + + # Runs the given command + # + # Returns nil if the command was not found + # Returns the output of the command otherwise + # + # see also #run_and_match + def run(command) + unless `#{command} 2>/dev/null`.blank? + `#{command}` + end + end + + def warn_user_is_not_gitlab + unless @warned_user_not_gitlab + current_user = run("whoami").chomp + unless current_user == "gitlab" + puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}" + puts " You are running as user #{current_user.magenta}, we hope you know what you are doing." + puts " Things may work\/fail for the wrong reasons." + puts " For correct results you should run this as user #{"gitlab".magenta}." + puts "" + end + @warned_user_not_gitlab = true + end + end +end diff --git a/lib/tasks/resque.rake b/lib/tasks/resque.rake deleted file mode 100644 index 0825324a424..00000000000 --- a/lib/tasks/resque.rake +++ /dev/null @@ -1,10 +0,0 @@ -require 'resque/tasks' - -task "resque:setup" => :environment do - Resque.after_fork do - Resque.redis.client.reconnect - end -end - -desc "Alias for resque:work (To run workers on Heroku)" -task "jobs:work" => "resque:work" diff --git a/lib/tasks/sidekiq.rake b/lib/tasks/sidekiq.rake new file mode 100644 index 00000000000..6bbcb3da4bc --- /dev/null +++ b/lib/tasks/sidekiq.rake @@ -0,0 +1,23 @@ +namespace :sidekiq do + desc "GITLAB | Stop sidekiq" + task :stop do + run "bundle exec sidekiqctl stop #{pidfile}" + end + + desc "GITLAB | Start sidekiq" + task :start do + run "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,common,default -e #{rails_env} -P #{pidfile} >> #{root_path}/log/sidekiq.log 2>&1 &" + end + + def root_path + @root_path ||= File.join(File.expand_path(File.dirname(__FILE__)), "../..") + end + + def pidfile + "#{root_path}/tmp/pids/sidekiq.pid" + end + + def rails_env + ENV['RAILS_ENV'] || "production" + end +end diff --git a/lib/tasks/travis.rake b/lib/tasks/travis.rake index e04bfbaf1c0..6b434830803 100644 --- a/lib/tasks/travis.rake +++ b/lib/tasks/travis.rake @@ -1,7 +1,5 @@ -task :travis do - ["rake spinach", "rake spec"].each do |cmd| - puts "Starting to run #{cmd}..." - system("export DISPLAY=:99.0 && bundle exec #{cmd}") - raise "#{cmd} failed!" unless $?.exitstatus == 0 - end -end +desc "Travis run tests" +task :travis => [ + :spinach, + :spec +] |