2014-09-02 18:07:02 +05:30
|
|
|
namespace :gitlab do
|
|
|
|
namespace :shell do
|
2015-09-11 14:41:01 +05:30
|
|
|
desc "GitLab | Install or upgrade gitlab-shell"
|
2017-08-17 22:00:37 +05:30
|
|
|
task :install, [:repo] => :environment do |t, args|
|
2014-09-02 18:07:02 +05:30
|
|
|
warn_user_is_not_gitlab
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
default_version = Gitlab::Shell.version_required
|
2017-08-17 22:00:37 +05:30
|
|
|
args.with_defaults(repo: 'https://gitlab.com/gitlab-org/gitlab-shell.git')
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
gitlab_url = Gitlab.config.gitlab.url
|
2014-09-02 18:07:02 +05:30
|
|
|
# gitlab-shell requires a / at the end of the url
|
2015-04-26 12:48:37 +05:30
|
|
|
gitlab_url += '/' unless gitlab_url.end_with?('/')
|
2014-09-02 18:07:02 +05:30
|
|
|
target_dir = Gitlab.config.gitlab_shell.path
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
checkout_or_clone_version(version: default_version, repo: args.repo, target_dir: target_dir)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
# Make sure we're on the right tag
|
|
|
|
Dir.chdir(target_dir) do
|
|
|
|
config = {
|
2017-08-17 22:00:37 +05:30
|
|
|
user: Gitlab.config.gitlab.user,
|
2014-09-02 18:07:02 +05:30
|
|
|
gitlab_url: gitlab_url,
|
2017-08-17 22:00:37 +05:30
|
|
|
http_settings: { self_signed_cert: false }.stringify_keys,
|
|
|
|
auth_file: File.join(user_home, ".ssh", "authorized_keys"),
|
2014-09-02 18:07:02 +05:30
|
|
|
redis: {
|
2017-08-17 22:00:37 +05:30
|
|
|
bin: `which redis-cli`.chomp,
|
2014-09-02 18:07:02 +05:30
|
|
|
namespace: "resque:gitlab"
|
|
|
|
}.stringify_keys,
|
|
|
|
log_level: "INFO",
|
|
|
|
audit_usernames: false
|
|
|
|
}.stringify_keys
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
redis_url = URI.parse(ENV['REDIS_URL'] || "redis://localhost:6379")
|
|
|
|
|
|
|
|
if redis_url.scheme == 'unix'
|
|
|
|
config['redis']['socket'] = redis_url.path
|
|
|
|
else
|
|
|
|
config['redis']['host'] = redis_url.host
|
|
|
|
config['redis']['port'] = redis_url.port
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
# Generate config.yml based on existing gitlab settings
|
|
|
|
File.open("config.yml", "w+") {|f| f.puts config.to_yaml}
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
[
|
|
|
|
%w(bin/install) + repository_storage_paths_args,
|
|
|
|
%w(bin/compile)
|
|
|
|
].each do |cmd|
|
|
|
|
unless Kernel.system(*cmd)
|
|
|
|
raise "command failed: #{cmd.join(' ')}"
|
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
# (Re)create hooks
|
|
|
|
Rake::Task['gitlab:shell:create_hooks'].invoke
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
# Required for debian packaging with PKGR: Setup .ssh/environment with
|
|
|
|
# the current PATH, so that the correct ruby version gets loaded
|
|
|
|
# Requires to set "PermitUserEnvironment yes" in sshd config (should not
|
|
|
|
# be an issue since it is more than likely that there are no "normal"
|
|
|
|
# user accounts on a gitlab server). The alternative is for the admin to
|
|
|
|
# install a ruby (1.9.3+) in the global path.
|
2017-08-17 22:00:37 +05:30
|
|
|
File.open(File.join(user_home, ".ssh", "environment"), "w+") do |f|
|
2014-09-02 18:07:02 +05:30
|
|
|
f.puts "PATH=#{ENV['PATH']}"
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
Gitlab::Shell.ensure_secret_token!
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
desc "GitLab | Setup gitlab-shell"
|
2014-09-02 18:07:02 +05:30
|
|
|
task setup: :environment do
|
|
|
|
setup
|
|
|
|
end
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
desc "GitLab | Build missing projects"
|
2014-09-02 18:07:02 +05:30
|
|
|
task build_missing_projects: :environment do
|
|
|
|
Project.find_each(batch_size: 1000) do |project|
|
2015-04-26 12:48:37 +05:30
|
|
|
path_to_repo = project.repository.path_to_repo
|
2016-09-13 17:45:13 +05:30
|
|
|
if File.exist?(path_to_repo)
|
2014-09-02 18:07:02 +05:30
|
|
|
print '-'
|
|
|
|
else
|
2016-08-24 12:49:21 +05:30
|
|
|
if Gitlab::Shell.new.add_repository(project.repository_storage_path,
|
2017-09-10 17:25:29 +05:30
|
|
|
project.disk_path)
|
2014-09-02 18:07:02 +05:30
|
|
|
print '.'
|
|
|
|
else
|
|
|
|
print 'F'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
desc 'Create or repair repository hooks symlink'
|
|
|
|
task create_hooks: :environment do
|
|
|
|
warn_user_is_not_gitlab
|
|
|
|
|
|
|
|
puts 'Creating/Repairing hooks symlinks for all repositories'
|
|
|
|
system(*%W(#{Gitlab.config.gitlab_shell.path}/bin/create-hooks) + repository_storage_paths_args)
|
|
|
|
puts 'done'.color(:green)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
|
|
|
warn_user_is_not_gitlab
|
|
|
|
|
|
|
|
unless ENV['force'] == 'yes'
|
|
|
|
puts "This will rebuild an authorized_keys file."
|
|
|
|
puts "You will lose any data stored in authorized_keys file."
|
|
|
|
ask_to_continue
|
|
|
|
puts ""
|
|
|
|
end
|
|
|
|
|
|
|
|
Gitlab::Shell.new.remove_all_keys
|
|
|
|
|
|
|
|
Gitlab::Shell.new.batch_add_keys do |adder|
|
|
|
|
Key.find_each(batch_size: 1000) do |key|
|
|
|
|
adder.add_key(key.shell_id, key.key)
|
|
|
|
print '.'
|
|
|
|
end
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
puts ""
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
unless $?.success?
|
2016-06-16 23:09:34 +05:30
|
|
|
puts "Failed to add keys...".color(:red)
|
2014-09-02 18:07:02 +05:30
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
rescue Gitlab::TaskAbortedByUserError
|
2016-06-16 23:09:34 +05:30
|
|
|
puts "Quitting...".color(:red)
|
2014-09-02 18:07:02 +05:30
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
end
|