diff options
author | Sebastian Ziebell <sebastian.ziebell@asquera.de> | 2013-02-12 10:17:57 +0100 |
---|---|---|
committer | Sebastian Ziebell <sebastian.ziebell@asquera.de> | 2013-02-12 10:17:57 +0100 |
commit | 449380265ad3276512d4de7d03e06854d9f1a536 (patch) | |
tree | cc8554ab4eaf326261e91f842da9e5aba71683ef /lib | |
parent | 56b3223945637d25394b001c880626f9a4a5b9e0 (diff) | |
parent | 644f8819af5d06deedb4420e8ad45637b96c9676 (diff) | |
download | gitlab-ce-449380265ad3276512d4de7d03e06854d9f1a536.tar.gz |
Merge branch 'master' into fixes/api
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/backend/shell.rb | 13 | ||||
-rw-r--r-- | lib/gitlab/project_mover.rb | 4 | ||||
-rw-r--r-- | lib/gitolited.rb | 4 | ||||
-rw-r--r-- | lib/tasks/gitlab/backup.rake | 2 | ||||
-rw-r--r-- | lib/tasks/gitlab/check.rake | 367 | ||||
-rw-r--r-- | lib/tasks/gitlab/cleanup.rake | 44 | ||||
-rw-r--r-- | lib/tasks/gitlab/enable_automerge.rake | 17 | ||||
-rw-r--r-- | lib/tasks/gitlab/enable_namespaces.rake | 7 | ||||
-rw-r--r-- | lib/tasks/gitlab/gitolite_rebuild.rake | 27 | ||||
-rw-r--r-- | lib/tasks/gitlab/import.rake | 3 | ||||
-rw-r--r-- | lib/tasks/gitlab/info.rake | 16 | ||||
-rw-r--r-- | lib/tasks/gitlab/setup.rake | 1 | ||||
-rw-r--r-- | lib/tasks/gitlab/shell.rake | 20 | ||||
-rw-r--r-- | lib/tasks/sidekiq.rake | 2 |
14 files changed, 93 insertions, 434 deletions
diff --git a/lib/gitlab/backend/shell.rb b/lib/gitlab/backend/shell.rb index 50ebfc5b07c..85fa5bda055 100644 --- a/lib/gitlab/backend/shell.rb +++ b/lib/gitlab/backend/shell.rb @@ -13,6 +13,17 @@ module Gitlab system("/home/git/gitlab-shell/bin/gitlab-projects add-project #{name}.git") end + # Import repository + # + # name - project path with namespace + # + # Ex. + # import_repository("gitlab/gitlab-ci", "https://github.com/randx/six.git") + # + def import_repository(name, url) + system("/home/git/gitlab-shell/bin/gitlab-projects import-project #{name}.git #{url}") + end + # Remove repository from file system # # name - project path with namespace @@ -44,7 +55,7 @@ module Gitlab def url_to_repo path - Gitlab.config.gitolite.ssh_path_prefix + "#{path}.git" + Gitlab.config.gitlab_shell.ssh_path_prefix + "#{path}.git" end end end diff --git a/lib/gitlab/project_mover.rb b/lib/gitlab/project_mover.rb index 207e585f572..e21f45c6564 100644 --- a/lib/gitlab/project_mover.rb +++ b/lib/gitlab/project_mover.rb @@ -15,10 +15,10 @@ module Gitlab def execute # Create new dir if missing - new_dir_path = File.join(Gitlab.config.gitolite.repos_path, new_dir) + new_dir_path = File.join(Gitlab.config.gitlab_shell.repos_path, new_dir) FileUtils.mkdir( new_dir_path, mode: 0770 ) unless File.exists?(new_dir_path) - old_path = File.join(Gitlab.config.gitolite.repos_path, old_dir, "#{project.path}.git") + old_path = File.join(Gitlab.config.gitlab_shell.repos_path, old_dir, "#{project.path}.git") new_path = File.join(new_dir_path, "#{project.path}.git") if File.exists? new_path diff --git a/lib/gitolited.rb b/lib/gitolited.rb index 4911a473f05..a7fc4148106 100644 --- a/lib/gitolited.rb +++ b/lib/gitolited.rb @@ -1,11 +1,11 @@ # == Gitolited mixin # -# Provide a shortcut to Gitlab::Gitolite instance by gitolite +# Provide a shortcut to Gitlab::Shell instance by gitlab_shell # # Used by Project, UsersProject, etc # module Gitolited - def gitolite + def gitlab_shell Gitlab::Shell.new end end diff --git a/lib/tasks/gitlab/backup.rake b/lib/tasks/gitlab/backup.rake index ae2b1bb793f..214ce720e7a 100644 --- a/lib/tasks/gitlab/backup.rake +++ b/lib/tasks/gitlab/backup.rake @@ -144,7 +144,7 @@ namespace :gitlab do task :restore => :environment do backup_path_repo = File.join(Gitlab.config.backup.path, "repositories") - repos_path = Gitlab.config.gitolite.repos_path + repos_path = Gitlab.config.gitlab_shell.repos_path puts "Restoring repositories ... " diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index b54e63acfbc..4e252f026bc 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -1,7 +1,7 @@ namespace :gitlab do desc "GITLAB | Check the configuration of GitLab and its environment" task check: %w{gitlab:env:check - gitlab:gitolite:check + gitlab:gitlab_shell:check gitlab:sidekiq:check gitlab:app:check} @@ -255,7 +255,6 @@ namespace :gitlab do warn_user_is_not_gitlab start_checking "Environment" - check_gitlab_in_git_group check_issue_1059_shell_profile_error check_gitlab_git_config check_python2_exists @@ -295,31 +294,12 @@ namespace :gitlab do end end - def check_gitlab_in_git_group - gitlab_user = Gitlab.config.gitlab.user - gitolite_owner_group = Gitlab.config.gitolite.owner_group - print "#{gitlab_user} user is in #{gitolite_owner_group} group? ... " - - if run_and_match("id -rnG", /^#{gitolite_owner_group}\W|\W#{gitolite_owner_group}\W|\W#{gitolite_owner_group}$/) - puts "yes".green - else - puts "no".red - try_fixing_it( - "sudo usermod -a -G #{gitolite_owner_group} #{gitlab_user}" - ) - for_more_information( - see_installation_guide_section "System Users" - ) - fix_and_rerun - end - end - # see https://github.com/gitlabhq/gitlabhq/issues/1059 def check_issue_1059_shell_profile_error - gitolite_ssh_user = Gitlab.config.gitolite.ssh_user - print "Has no \"-e\" in ~#{gitolite_ssh_user}/.profile ... " + gitlab_shell_ssh_user = Gitlab.config.gitlab_shell.ssh_user + print "Has no \"-e\" in ~#{gitlab_shell_ssh_user}/.profile ... " - profile_file = File.join(gitolite_user_home, ".profile") + profile_file = File.join(gitlab_shell_user_home, ".profile") unless File.read(profile_file) =~ /^-e PATH/ puts "yes".green @@ -387,28 +367,18 @@ namespace :gitlab do - namespace :gitolite do + namespace :gitlab_shell do desc "GITLAB | Check the configuration of Gitolite" task check: :environment do warn_user_is_not_gitlab start_checking "Gitolite" - check_gitolite_is_up_to_date - check_gitoliterc_repo_umask - check_gitoliterc_git_config_keys - check_dot_gitolite_exists - 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 - check_can_commit_to_gitolite_admin - check_post_receive_hook_exists check_post_receive_hook_is_up_to_date check_repos_post_receive_hooks_is_link - check_repos_git_config finished_checking "Gitolite" end @@ -417,254 +387,30 @@ namespace :gitlab do # Checks ######################## - def check_can_clone_gitolite_admin - print "Can clone gitolite-admin? ... " - - test_path = "/tmp/gitlab_gitolite_admin_test" - FileUtils.rm_rf(test_path) - `git clone -q #{Gitlab.config.gitolite.admin_uri} #{test_path}` - raise unless $?.success? - - puts "yes".green - rescue - puts "no".red - try_fixing_it( - "Make sure the \"admin_uri\" is set correctly in config/gitlab.yml", - "Try cloning it yourself with:", - " git clone -q #{Gitlab.config.gitolite.admin_uri} /tmp/gitolite-admin", - "Make sure Gitolite is installed correctly." - ) - for_more_information( - see_installation_guide_section "Gitolite" - ) - fix_and_rerun - end - - # assumes #check_can_clone_gitolite_admin has been run before - def check_can_commit_to_gitolite_admin - print "Can commit to gitolite-admin? ... " - - test_path = "/tmp/gitlab_gitolite_admin_test" - unless File.exists?(test_path) - puts "can't check because of previous errors".magenta - return - end - - Dir.chdir(test_path) do - `touch foo && git add foo && git commit -qm foo` - raise unless $?.success? - end - - puts "yes".green - rescue - puts "no".red - try_fixing_it( - "Try committing to it yourself with:", - " git clone -q #{Gitlab.config.gitolite.admin_uri} /tmp/gitolite-admin", - " touch foo", - " git add foo", - " git commit -m \"foo\"", - "Make sure Gitolite is installed correctly." - ) - for_more_information( - see_installation_guide_section "Gitolite" - ) - fix_and_rerun - ensure - FileUtils.rm_rf("/tmp/gitolite_gitlab_test") - end - - def check_dot_gitolite_exists - print "Config directory exists? ... " - - gitolite_config_path = File.join(gitolite_user_home, ".gitolite") - - if File.directory?(gitolite_config_path) - puts "yes".green - else - puts "no".red - puts "#{gitolite_config_path} is missing".red - try_fixing_it( - "This should have been created when setting up Gitolite.", - "Make sure Gitolite is installed correctly." - ) - for_more_information( - see_installation_guide_section "Gitolite" - ) - fix_and_rerun - end - end - - def check_dot_gitolite_permissions - print "Config directory access is drwxr-x---? ... " - - gitolite_config_path = File.join(gitolite_user_home, ".gitolite") - unless File.exists?(gitolite_config_path) - puts "can't check because of previous errors".magenta - return - end - - if File.stat(gitolite_config_path).mode.to_s(8).ends_with?("750") - puts "yes".green - else - puts "no".red - try_fixing_it( - "sudo chmod 750 #{gitolite_config_path}" - ) - for_more_information( - see_installation_guide_section "Gitolite" - ) - fix_and_rerun - end - end - - def check_dot_gitolite_user_and_group - gitolite_ssh_user = Gitlab.config.gitolite.ssh_user - gitolite_owner_group = Gitlab.config.gitolite.owner_group - print "Config directory owned by #{gitolite_ssh_user}:#{gitolite_owner_group} ... " - - gitolite_config_path = File.join(gitolite_user_home, ".gitolite") - unless File.exists?(gitolite_config_path) - puts "can't check because of previous errors".magenta - return - end - - if File.stat(gitolite_config_path).uid == uid_for(gitolite_ssh_user) && - File.stat(gitolite_config_path).gid == gid_for(gitolite_owner_group) - puts "yes".green - else - puts "no".red - try_fixing_it( - "sudo chown -R #{gitolite_ssh_user}:#{gitolite_owner_group} #{gitolite_config_path}" - ) - for_more_information( - see_installation_guide_section "Gitolite" - ) - fix_and_rerun - end - end - - def check_gitolite_is_up_to_date - print "Using recommended version ... " - if gitolite_version.try(:start_with?, "v3.2") - puts "yes".green - else - puts "no".red - try_fixing_it( - "We strongly recommend using the version pointed out in the installation guide." - ) - for_more_information( - see_installation_guide_section "Gitolite" - ) - # this is not a "hard" failure - end - end - - def check_gitoliterc_git_config_keys - gitoliterc_path = File.join(gitolite_user_home, ".gitolite.rc") - - print "Allow all Git config keys in .gitolite.rc ... " - option_name = if has_gitolite3? - # see https://github.com/sitaramc/gitolite/blob/v3.04/src/lib/Gitolite/Rc.pm#L329 - "GIT_CONFIG_KEYS" - else - # assume older version - # see https://github.com/sitaramc/gitolite/blob/v2.3/conf/example.gitolite.rc#L49 - "\\$GL_GITCONFIG_KEYS" - end - option_value = ".*" - if open(gitoliterc_path).grep(/#{option_name}\s*=[>]?\s*["']#{option_value}["']/).any? - puts "yes".green - else - puts "no".red - try_fixing_it( - "Open #{gitoliterc_path}", - "Find the \"#{option_name}\" option", - "Change its value to \".*\"" - ) - for_more_information( - see_installation_guide_section "Gitolite" - ) - fix_and_rerun - end - end - - def check_gitoliterc_repo_umask - gitoliterc_path = File.join(gitolite_user_home, ".gitolite.rc") - - print "Repo umask is 0007 in .gitolite.rc? ... " - option_name = if has_gitolite3? - # see https://github.com/sitaramc/gitolite/blob/v3.04/src/lib/Gitolite/Rc.pm#L328 - "UMASK" - else - # assume older version - # see https://github.com/sitaramc/gitolite/blob/v2.3/conf/example.gitolite.rc#L32 - "\\$REPO_UMASK" - end - option_value = "0007" - if open(gitoliterc_path).grep(/#{option_name}\s*=[>]?\s*#{option_value}/).any? - puts "yes".green - else - puts "no".red - try_fixing_it( - "Open #{gitoliterc_path}", - "Find the \"#{option_name}\" option", - "Change its value to \"0007\"" - ) - for_more_information( - see_installation_guide_section "Gitolite" - ) - fix_and_rerun - end - end - - def check_post_receive_hook_exists - print "post-receive hook exists? ... " - - 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_ssh_user = Gitlab.config.gitolite.ssh_user - - gitlab_hook_file = Rails.root.join.join("lib", "hooks", hook_file) - - if File.exists?(gitolite_hook_file) - puts "yes".green - else - puts "no".red - try_fixing_it( - "sudo -u #{gitolite_ssh_user} cp #{gitlab_hook_file} #{gitolite_hook_file}" - ) - for_more_information( - see_installation_guide_section "Setup GitLab Hooks" - ) - fix_and_rerun - end - end def check_post_receive_hook_is_up_to_date print "post-receive hook up-to-date? ... " 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_ssh_user = Gitlab.config.gitolite.ssh_user + gitlab_shell_hooks_path = File.join(Gitlab.config.gitlab_shell.hooks_path, "common") + gitlab_shell_hook_file = File.join(gitlab_shell_hooks_path, hook_file) + gitlab_shell_ssh_user = Gitlab.config.gitlab_shell.ssh_user - unless File.exists?(gitolite_hook_file) + unless File.exists?(gitlab_shell_hook_file) puts "can't check because of previous errors".magenta return end - gitolite_hook_content = File.read(gitolite_hook_file) + gitlab_shell_hook_content = File.read(gitlab_shell_hook_file) gitlab_hook_file = Rails.root.join.join("lib", "hooks", hook_file) gitlab_hook_content = File.read(gitlab_hook_file) - if gitolite_hook_content == gitlab_hook_content + if gitlab_shell_hook_content == gitlab_hook_content puts "yes".green else puts "no".red try_fixing_it( - "sudo -u #{gitolite_ssh_user} cp #{gitlab_hook_file} #{gitolite_hook_file}" + "sudo -u #{gitlab_shell_ssh_user} cp #{gitlab_hook_file} #{gitlab_shell_hook_file}" ) for_more_information( see_installation_guide_section "Setup GitLab Hooks" @@ -676,7 +422,7 @@ namespace :gitlab do def check_repo_base_exists print "Repo base directory exists? ... " - repo_base_path = Gitlab.config.gitolite.repos_path + repo_base_path = Gitlab.config.gitlab_shell.repos_path if File.exists?(repo_base_path) puts "yes".green @@ -698,7 +444,7 @@ namespace :gitlab do def check_repo_base_is_not_symlink print "Repo base directory is a symlink? ... " - repo_base_path = Gitlab.config.gitolite.repos_path + repo_base_path = Gitlab.config.gitlab_shell.repos_path unless File.exists?(repo_base_path) puts "can't check because of previous errors".magenta return @@ -718,7 +464,7 @@ namespace :gitlab do def check_repo_base_permissions print "Repo base access is drwxrws---? ... " - repo_base_path = Gitlab.config.gitolite.repos_path + repo_base_path = Gitlab.config.gitlab_shell.repos_path unless File.exists?(repo_base_path) puts "can't check because of previous errors".magenta return @@ -741,23 +487,23 @@ namespace :gitlab do end def check_repo_base_user_and_group - gitolite_ssh_user = Gitlab.config.gitolite.ssh_user - gitolite_owner_group = Gitlab.config.gitolite.owner_group - print "Repo base owned by #{gitolite_ssh_user}:#{gitolite_owner_group}? ... " + gitlab_shell_ssh_user = Gitlab.config.gitlab_shell.ssh_user + gitlab_shell_owner_group = Gitlab.config.gitlab_shell.owner_group + print "Repo base owned by #{gitlab_shell_ssh_user}:#{gitlab_shell_owner_group}? ... " - repo_base_path = Gitlab.config.gitolite.repos_path + repo_base_path = Gitlab.config.gitlab_shell.repos_path unless File.exists?(repo_base_path) puts "can't check because of previous errors".magenta return end - if File.stat(repo_base_path).uid == uid_for(gitolite_ssh_user) && - File.stat(repo_base_path).gid == gid_for(gitolite_owner_group) + if File.stat(repo_base_path).uid == uid_for(gitlab_shell_ssh_user) && + File.stat(repo_base_path).gid == gid_for(gitlab_shell_owner_group) puts "yes".green else puts "no".red try_fixing_it( - "sudo chown -R #{gitolite_ssh_user}:#{gitolite_owner_group} #{repo_base_path}" + "sudo chown -R #{gitlab_shell_ssh_user}:#{gitlab_shell_owner_group} #{repo_base_path}" ) for_more_information( see_installation_guide_section "Gitolite" @@ -766,54 +512,15 @@ namespace :gitlab do end end - def check_repos_git_config - print "Git config in repos: ... " - - unless Project.count > 0 - puts "can't check, you have no projects".magenta - return - end - puts "" - - options = { - "core.sharedRepository" => "0660", - } - - Project.find_each(batch_size: 100) do |project| - print "#{project.name_with_namespace.yellow} ... " - - if project.empty_repo? - puts "repository is empty".magenta - else - correct_options = options.map do |name, value| - run("git --git-dir=\"#{project.repository.path_to_repo}\" config --get #{name}").try(:chomp) == value - end - - if correct_options.all? - puts "ok".green - else - puts "wrong or missing".red - try_fixing_it( - sudo_gitlab("bundle exec rake gitlab:gitolite:update_repos RAILS_ENV=production") - ) - for_more_information( - "doc/raketasks/maintenance.md" - ) - fix_and_rerun - end - end - end - end - def check_repos_post_receive_hooks_is_link print "post-receive hooks in repos are links: ... " 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_ssh_user = Gitlab.config.gitolite.ssh_user + gitlab_shell_hooks_path = File.join(Gitlab.config.gitlab_shell.hooks_path, "common") + gitlab_shell_hook_file = File.join(gitlab_shell_hooks_path, hook_file) + gitlab_shell_ssh_user = Gitlab.config.gitlab_shell.ssh_user - unless File.exists?(gitolite_hook_file) + unless File.exists?(gitlab_shell_hook_file) puts "can't check because of previous errors".magenta return end @@ -835,7 +542,7 @@ namespace :gitlab do unless File.exists?(project_hook_file) puts "missing".red try_fixing_it( - "sudo -u #{gitolite_ssh_user} ln -sf #{gitolite_hook_file} #{project_hook_file}" + "sudo -u #{gitlab_shell_ssh_user} ln -sf #{gitlab_shell_hook_file} #{project_hook_file}" ) for_more_information( "lib/support/rewrite-hooks.sh" @@ -845,12 +552,12 @@ namespace :gitlab do end if File.lstat(project_hook_file).symlink? && - File.realpath(project_hook_file) == File.realpath(gitolite_hook_file) + File.realpath(project_hook_file) == File.realpath(gitlab_shell_hook_file) puts "ok".green else puts "not a link to Gitolite's hook".red try_fixing_it( - "sudo -u #{gitolite_ssh_user} ln -sf #{gitolite_hook_file} #{project_hook_file}" + "sudo -u #{gitlab_shell_ssh_user} ln -sf #{gitlab_shell_hook_file} #{project_hook_file}" ) for_more_information( "lib/support/rewrite-hooks.sh" @@ -865,19 +572,19 @@ namespace :gitlab do # Helper methods ######################## - def gitolite_user_home - File.expand_path("~#{Gitlab.config.gitolite.ssh_user}") + def gitlab_shell_user_home + File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}") end - def gitolite_version - gitolite_version_file = "#{gitolite_user_home}/gitolite/src/VERSION" - if File.readable?(gitolite_version_file) - File.read(gitolite_version_file) + def gitlab_shell_version + gitlab_shell_version_file = "#{gitlab_shell_user_home}/gitlab_shell/src/VERSION" + if File.readable?(gitlab_shell_version_file) + File.read(gitlab_shell_version_file) end end - def has_gitolite3? - gitolite_version.try(:start_with?, "v3.") + def has_gitlab_shell3? + gitlab_shell_version.try(:start_with?, "v3.") end end diff --git a/lib/tasks/gitlab/cleanup.rake b/lib/tasks/gitlab/cleanup.rake index 2a0ffe0f4bd..d8ee56e5523 100644 --- a/lib/tasks/gitlab/cleanup.rake +++ b/lib/tasks/gitlab/cleanup.rake @@ -1,38 +1,5 @@ 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 @@ -40,7 +7,7 @@ namespace :gitlab do namespaces = Namespace.pluck(:path) - git_base_path = Gitlab.config.gitolite.repos_path + git_base_path = Gitlab.config.gitlab_shell.repos_path all_dirs = Dir.glob(git_base_path + '/*') puts git_base_path.yellow @@ -81,7 +48,7 @@ namespace :gitlab do warn_user_is_not_gitlab remove_flag = ENV['REMOVE'] - git_base_path = Gitlab.config.gitolite.repos_path + git_base_path = Gitlab.config.gitlab_shell.repos_path all_dirs = Dir.glob(git_base_path + '/*') global_projects = Project.where(namespace_id: nil).pluck(:path) @@ -101,13 +68,6 @@ namespace :gitlab do 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 diff --git a/lib/tasks/gitlab/enable_automerge.rake b/lib/tasks/gitlab/enable_automerge.rake index a89c6eaa5c4..6822e5cf1ad 100644 --- a/lib/tasks/gitlab/enable_automerge.rake +++ b/lib/tasks/gitlab/enable_automerge.rake @@ -1,12 +1,18 @@ namespace :gitlab do - desc "GITLAB | Enable auto merge" - task :enable_automerge => :environment do + namespace :satellites do + desc "GITLAB | Create satellite repos" + task create: :environment do + create_satellites + end + end + + def create_satellites warn_user_is_not_gitlab print "Creating satellites for ..." unless Project.count > 0 puts "skipping, because you have no projects".magenta - next + return end puts "" @@ -33,9 +39,4 @@ namespace :gitlab do end end end - - namespace :satellites do - desc "GITLAB | Create satellite repos" - task create: 'gitlab:enable_automerge' - end end diff --git a/lib/tasks/gitlab/enable_namespaces.rake b/lib/tasks/gitlab/enable_namespaces.rake index aa76a2f7d83..a33639a0013 100644 --- a/lib/tasks/gitlab/enable_namespaces.rake +++ b/lib/tasks/gitlab/enable_namespaces.rake @@ -6,11 +6,6 @@ namespace :gitlab do 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 @@ -80,7 +75,7 @@ namespace :gitlab do end def migrate_projects - git_path = Gitlab.config.gitolite.repos_path + git_path = Gitlab.config.gitlab_shell.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 diff --git a/lib/tasks/gitlab/gitolite_rebuild.rake b/lib/tasks/gitlab/gitolite_rebuild.rake deleted file mode 100644 index af2a2127ee2..00000000000 --- a/lib/tasks/gitlab/gitolite_rebuild.rake +++ /dev/null @@ -1,27 +0,0 @@ -namespace :gitlab do - namespace :gitolite do - desc "GITLAB | Rebuild each project in Gitolite config" - task :update_repos => :environment do - warn_user_is_not_gitlab - - puts "Rebuilding projects ... " - Project.find_each(:batch_size => 100) do |project| - puts "#{project.name_with_namespace.yellow} ... " - project.update_repository - puts "... #{"done".green}" - end - end - - desc "GITLAB | Rebuild each user key in Gitolite config" - task :update_keys => :environment do - 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) - puts "... #{"done".green}" - end - end - end -end diff --git a/lib/tasks/gitlab/import.rake b/lib/tasks/gitlab/import.rake index 0ca652faa74..bddbd7ef855 100644 --- a/lib/tasks/gitlab/import.rake +++ b/lib/tasks/gitlab/import.rake @@ -12,7 +12,7 @@ namespace :gitlab do desc "GITLAB | Import bare repositories from git_host -> base_path into GitLab project instance" task :repos => :environment do - git_base_path = Gitlab.config.gitolite.repos_path + git_base_path = Gitlab.config.gitlab_shell.repos_path repos_to_import = Dir.glob(git_base_path + '/*') namespaces = Namespace.pluck(:path) @@ -26,7 +26,6 @@ namespace :gitlab do # 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$/, '') diff --git a/lib/tasks/gitlab/info.rake b/lib/tasks/gitlab/info.rake index b325bcc333d..c44016ef6e8 100644 --- a/lib/tasks/gitlab/info.rake +++ b/lib/tasks/gitlab/info.rake @@ -54,18 +54,16 @@ namespace :gitlab do # check Gitolite version - gitolite_version_file = "#{Gitlab.config.gitolite.repos_path}/../gitolite/src/VERSION" - if File.readable?(gitolite_version_file) - gitolite_version = File.read(gitolite_version_file) + gitlab_shell_version_file = "#{Gitlab.config.gitlab_shell.repos_path}/../gitlab-shell/VERSION" + if File.readable?(gitlab_shell_version_file) + gitlab_shell_version = File.read(gitlab_shell_version_file) end puts "" - puts "Gitolite information".yellow - puts "Version:\t#{gitolite_version || "unknown".red}" - puts "Admin URI:\t#{Gitlab.config.gitolite.admin_uri}" - puts "Admin Key:\t#{Gitlab.config.gitolite.admin_key}" - puts "Repositories:\t#{Gitlab.config.gitolite.repos_path}" - puts "Hooks:\t\t#{Gitlab.config.gitolite.hooks_path}" + puts "GitLab Shell".yellow + puts "Version:\t#{gitlab_shell_version || "unknown".red}" + puts "Repositories:\t#{Gitlab.config.gitlab_shell.repos_path}" + puts "Hooks:\t\t#{Gitlab.config.gitlab_shell.hooks_path}" puts "Git:\t\t#{Gitlab.config.git.bin_path}" end diff --git a/lib/tasks/gitlab/setup.rake b/lib/tasks/gitlab/setup.rake index 5699e5d6188..bc0742564d0 100644 --- a/lib/tasks/gitlab/setup.rake +++ b/lib/tasks/gitlab/setup.rake @@ -14,7 +14,6 @@ namespace :gitlab do 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 diff --git a/lib/tasks/gitlab/shell.rake b/lib/tasks/gitlab/shell.rake index 25713482ed8..0ab8df1d094 100644 --- a/lib/tasks/gitlab/shell.rake +++ b/lib/tasks/gitlab/shell.rake @@ -1,9 +1,25 @@ namespace :gitlab do namespace :shell do desc "GITLAB | Setup gitlab-shell" - task :setup => :environment do + task setup: :environment do setup end + + desc "GITLAB | Build missing projects" + task build_missing_projects: :environment do + Project.find_each(batch_size: 1000) do |project| + path_to_repo = File.join(Gitlab.config.gitlab_shell.repos_path, "#{project.path_with_namespace}.git") + if File.exists?(path_to_repo) + print '-' + else + if Gitlab::Shell.new.add_repository(project.path_with_namespace) + print '.' + else + print 'F' + end + end + end + end end def setup @@ -16,7 +32,7 @@ namespace :gitlab do system("echo '# Managed by gitlab-shell' > /home/git/.ssh/authorized_keys") - Key.find_each(:batch_size => 1000) do |key| + Key.find_each(batch_size: 1000) do |key| if Gitlab::Shell.new.add_key(key.shell_id, key.key) print '.' else diff --git a/lib/tasks/sidekiq.rake b/lib/tasks/sidekiq.rake index e4eb0e6776f..67e8daafec7 100644 --- a/lib/tasks/sidekiq.rake +++ b/lib/tasks/sidekiq.rake @@ -6,7 +6,7 @@ namespace :sidekiq do desc "GITLAB | Start sidekiq" task :start do - run "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,gitolite,common,default -e #{Rails.env} -P #{pidfile} >> #{Rails.root.join("log", "sidekiq.log")} 2>&1 &" + run "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,gitlab_shell,common,default -e #{Rails.env} -P #{pidfile} >> #{Rails.root.join("log", "sidekiq.log")} 2>&1 &" end def pidfile |