Commit c5eba169cdcf0d66cd7c6b34dace639a08949dd9
1 parent
c8ba5c2d
Exists in
master
and in
4 other branches
Cleanup service tasks
Showing
2 changed files
with
128 additions
and
33 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,128 @@ |
| 1 | +namespace :gitlab do | |
| 2 | + namespace :cleanup do | |
| 3 | + desc "GITLAB | Cleanup | Clean gitolite config" | |
| 4 | + task :config => :environment do | |
| 5 | + warn_user_is_not_gitlab | |
| 6 | + | |
| 7 | + real_repos = Project.all.map(&:path_with_namespace) | |
| 8 | + real_repos << "gitolite-admin" | |
| 9 | + real_repos << "@all" | |
| 10 | + | |
| 11 | + remove_flag = ENV['REMOVE'] | |
| 12 | + | |
| 13 | + puts "Looking for repositories to remove... " | |
| 14 | + Gitlab::GitoliteConfig.new.apply do |config| | |
| 15 | + all_repos = [] | |
| 16 | + garbage_repos = [] | |
| 17 | + | |
| 18 | + all_repos = config.conf.repos.keys | |
| 19 | + garbage_repos = all_repos - real_repos | |
| 20 | + | |
| 21 | + garbage_repos.each do |repo_name| | |
| 22 | + if remove_flag | |
| 23 | + config.conf.rm_repo(repo_name) | |
| 24 | + print "to remove...".red | |
| 25 | + end | |
| 26 | + | |
| 27 | + puts repo_name.red | |
| 28 | + end | |
| 29 | + end | |
| 30 | + | |
| 31 | + unless remove_flag | |
| 32 | + puts "To cleanup repositories run this command with REMOVE=true".yellow | |
| 33 | + end | |
| 34 | + end | |
| 35 | + | |
| 36 | + desc "GITLAB | Cleanup | Clean namespaces" | |
| 37 | + task :dirs => :environment do | |
| 38 | + warn_user_is_not_gitlab | |
| 39 | + remove_flag = ENV['REMOVE'] | |
| 40 | + | |
| 41 | + | |
| 42 | + namespaces = Namespace.pluck(:path) | |
| 43 | + git_base_path = Gitlab.config.gitolite.repos_path | |
| 44 | + all_dirs = Dir.glob(git_base_path + '/*') | |
| 45 | + | |
| 46 | + puts git_base_path.yellow | |
| 47 | + puts "Looking for directories to remove... " | |
| 48 | + | |
| 49 | + all_dirs.reject! do |dir| | |
| 50 | + # skip if git repo | |
| 51 | + dir =~ /.git$/ | |
| 52 | + end | |
| 53 | + | |
| 54 | + all_dirs.reject! do |dir| | |
| 55 | + dir_name = File.basename dir | |
| 56 | + | |
| 57 | + # skip if namespace present | |
| 58 | + namespaces.include?(dir_name) | |
| 59 | + end | |
| 60 | + | |
| 61 | + all_dirs.each do |dir_path| | |
| 62 | + | |
| 63 | + if remove_flag | |
| 64 | + if FileUtils.rm_rf dir_path | |
| 65 | + puts "Removed...#{dir_path}".red | |
| 66 | + else | |
| 67 | + puts "Cannot remove #{dir_path}".red | |
| 68 | + end | |
| 69 | + else | |
| 70 | + puts "Can be removed: #{dir_path}".red | |
| 71 | + end | |
| 72 | + end | |
| 73 | + | |
| 74 | + unless remove_flag | |
| 75 | + puts "To cleanup this directories run this command with REMOVE=true".yellow | |
| 76 | + end | |
| 77 | + end | |
| 78 | + | |
| 79 | + desc "GITLAB | Cleanup | Clean respositories" | |
| 80 | + task :repos => :environment do | |
| 81 | + warn_user_is_not_gitlab | |
| 82 | + remove_flag = ENV['REMOVE'] | |
| 83 | + | |
| 84 | + git_base_path = Gitlab.config.gitolite.repos_path | |
| 85 | + all_dirs = Dir.glob(git_base_path + '/*') | |
| 86 | + | |
| 87 | + global_projects = Project.where(namespace_id: nil).pluck(:path) | |
| 88 | + | |
| 89 | + puts git_base_path.yellow | |
| 90 | + puts "Looking for global repos to remove... " | |
| 91 | + | |
| 92 | + # skip non git repo | |
| 93 | + all_dirs.select! do |dir| | |
| 94 | + dir =~ /.git$/ | |
| 95 | + end | |
| 96 | + | |
| 97 | + # skip existing repos | |
| 98 | + all_dirs.reject! do |dir| | |
| 99 | + repo_name = File.basename dir | |
| 100 | + path = repo_name.gsub(/\.git$/, "") | |
| 101 | + global_projects.include?(path) | |
| 102 | + end | |
| 103 | + | |
| 104 | + # skip gitolite admin | |
| 105 | + all_dirs.reject! do |dir| | |
| 106 | + repo_name = File.basename dir | |
| 107 | + repo_name == 'gitolite-admin.git' | |
| 108 | + end | |
| 109 | + | |
| 110 | + | |
| 111 | + all_dirs.each do |dir_path| | |
| 112 | + if remove_flag | |
| 113 | + if FileUtils.rm_rf dir_path | |
| 114 | + puts "Removed...#{dir_path}".red | |
| 115 | + else | |
| 116 | + puts "Cannot remove #{dir_path}".red | |
| 117 | + end | |
| 118 | + else | |
| 119 | + puts "Can be removed: #{dir_path}".red | |
| 120 | + end | |
| 121 | + end | |
| 122 | + | |
| 123 | + unless remove_flag | |
| 124 | + puts "To cleanup this directories run this command with REMOVE=true".yellow | |
| 125 | + end | |
| 126 | + end | |
| 127 | + end | |
| 128 | +end | ... | ... |
lib/tasks/gitlab/gitolite_rebuild.rake
| ... | ... | @@ -23,38 +23,5 @@ namespace :gitlab do |
| 23 | 23 | puts "... #{"done".green}" |
| 24 | 24 | end |
| 25 | 25 | end |
| 26 | - | |
| 27 | - desc "GITLAB | Cleanup gitolite config" | |
| 28 | - task :cleanup => :environment do | |
| 29 | - warn_user_is_not_gitlab | |
| 30 | - | |
| 31 | - real_repos = Project.all.map(&:path_with_namespace) | |
| 32 | - real_repos << "gitolite-admin" | |
| 33 | - real_repos << "@all" | |
| 34 | - | |
| 35 | - remove_flag = ENV['REMOVE'] | |
| 36 | - | |
| 37 | - puts "Looking for repositories to remove... " | |
| 38 | - Gitlab::GitoliteConfig.new.apply do |config| | |
| 39 | - all_repos = [] | |
| 40 | - garbage_repos = [] | |
| 41 | - | |
| 42 | - all_repos = config.conf.repos.keys | |
| 43 | - garbage_repos = all_repos - real_repos | |
| 44 | - | |
| 45 | - garbage_repos.each do |repo_name| | |
| 46 | - if remove_flag | |
| 47 | - config.conf.rm_repo(repo_name) | |
| 48 | - print "to remove...".red | |
| 49 | - end | |
| 50 | - | |
| 51 | - puts repo_name.red | |
| 52 | - end | |
| 53 | - end | |
| 54 | - | |
| 55 | - unless remove_flag | |
| 56 | - puts "To cleanup repositories run this command with REMOVE=true".yellow | |
| 57 | - end | |
| 58 | - end | |
| 59 | 26 | end |
| 60 | 27 | end | ... | ... |