2013-02-07 08:06:39 +00:00
|
|
|
namespace :gitlab do
|
|
|
|
namespace :shell do
|
2015-06-23 14:52:40 +00:00
|
|
|
desc "GitLab | Install or upgrade gitlab-shell"
|
2014-04-05 19:31:07 +00:00
|
|
|
task :install, [:tag, :repo] => :environment do |t, args|
|
|
|
|
warn_user_is_not_gitlab
|
|
|
|
|
2014-11-05 16:14:22 +00:00
|
|
|
default_version = Gitlab::Shell.version_required
|
2014-07-31 20:05:30 +00:00
|
|
|
args.with_defaults(tag: 'v' + default_version, repo: "https://gitlab.com/gitlab-org/gitlab-shell.git")
|
2014-04-05 19:31:07 +00:00
|
|
|
|
2014-10-10 09:06:08 +00:00
|
|
|
user = Gitlab.config.gitlab.user
|
|
|
|
home_dir = Rails.env.test? ? Rails.root.join('tmp/tests') : Gitlab.config.gitlab.user_home
|
|
|
|
gitlab_url = Gitlab.config.gitlab.url
|
2014-04-05 19:31:07 +00:00
|
|
|
# gitlab-shell requires a / at the end of the url
|
2014-10-18 20:36:00 +00:00
|
|
|
gitlab_url += '/' unless gitlab_url.end_with?('/')
|
2014-05-02 10:46:32 +00:00
|
|
|
target_dir = Gitlab.config.gitlab_shell.path
|
2014-04-05 19:31:07 +00:00
|
|
|
|
|
|
|
# Clone if needed
|
|
|
|
unless File.directory?(target_dir)
|
2015-11-03 22:10:38 +00:00
|
|
|
system(*%W(#{Gitlab.config.git.bin_path} clone -- #{args.repo} #{target_dir}))
|
2014-04-05 19:31:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Make sure we're on the right tag
|
|
|
|
Dir.chdir(target_dir) do
|
2014-09-22 17:46:57 +00:00
|
|
|
# First try to checkout without fetching
|
|
|
|
# to avoid stalling tests if the Internet is down.
|
2014-12-12 09:17:07 +00:00
|
|
|
reseted = reset_to_commit(args)
|
2014-12-11 12:17:43 +00:00
|
|
|
|
2014-12-12 09:17:07 +00:00
|
|
|
unless reseted
|
2015-11-03 22:10:38 +00:00
|
|
|
system(*%W(#{Gitlab.config.git.bin_path} fetch origin))
|
2014-12-11 12:17:43 +00:00
|
|
|
reset_to_commit(args)
|
|
|
|
end
|
2014-04-05 19:31:07 +00:00
|
|
|
|
|
|
|
config = {
|
|
|
|
user: user,
|
|
|
|
gitlab_url: gitlab_url,
|
2014-05-02 11:13:45 +00:00
|
|
|
http_settings: {self_signed_cert: false}.stringify_keys,
|
2014-04-05 19:31:07 +00:00
|
|
|
auth_file: File.join(home_dir, ".ssh", "authorized_keys"),
|
|
|
|
redis: {
|
|
|
|
bin: %x{which redis-cli}.chomp,
|
|
|
|
namespace: "resque:gitlab"
|
2014-05-02 11:13:45 +00:00
|
|
|
}.stringify_keys,
|
2014-11-18 15:14:36 +00:00
|
|
|
log_level: "INFO",
|
2014-04-05 19:31:07 +00:00
|
|
|
audit_usernames: false
|
2014-05-02 10:46:32 +00:00
|
|
|
}.stringify_keys
|
2014-04-05 19:31:07 +00:00
|
|
|
|
2014-09-22 13:02:46 +00:00
|
|
|
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-04-05 19:31:07 +00:00
|
|
|
# Generate config.yml based on existing gitlab settings
|
|
|
|
File.open("config.yml", "w+") {|f| f.puts config.to_yaml}
|
|
|
|
|
|
|
|
# Launch installation process
|
2016-06-22 21:04:51 +00:00
|
|
|
system(*%W(bin/install) + repository_storage_paths_args)
|
2015-06-03 13:01:13 +00:00
|
|
|
|
|
|
|
# (Re)create hooks
|
2016-06-22 21:04:51 +00:00
|
|
|
system(*%W(bin/create-hooks) + repository_storage_paths_args)
|
2014-04-05 19:31:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
File.open(File.join(home_dir, ".ssh", "environment"), "w+") do |f|
|
|
|
|
f.puts "PATH=#{ENV['PATH']}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-23 14:52:40 +00:00
|
|
|
desc "GitLab | Setup gitlab-shell"
|
2013-02-09 10:30:49 +00:00
|
|
|
task setup: :environment do
|
2013-02-07 08:06:39 +00:00
|
|
|
setup
|
|
|
|
end
|
2013-02-09 10:30:49 +00:00
|
|
|
|
2015-06-23 14:52:40 +00:00
|
|
|
desc "GitLab | Build missing projects"
|
2013-02-09 10:30:49 +00:00
|
|
|
task build_missing_projects: :environment do
|
|
|
|
Project.find_each(batch_size: 1000) do |project|
|
2014-11-05 16:51:08 +00:00
|
|
|
path_to_repo = project.repository.path_to_repo
|
2013-02-09 10:30:49 +00:00
|
|
|
if File.exists?(path_to_repo)
|
|
|
|
print '-'
|
|
|
|
else
|
2016-06-22 21:04:51 +00:00
|
|
|
if Gitlab::Shell.new.add_repository(project.repository_storage_path,
|
|
|
|
project.path_with_namespace)
|
2013-02-09 10:30:49 +00:00
|
|
|
print '.'
|
|
|
|
else
|
|
|
|
print 'F'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-02-07 08:06:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
|
|
|
warn_user_is_not_gitlab
|
|
|
|
|
2013-05-29 19:19:23 +00:00
|
|
|
unless ENV['force'] == 'yes'
|
|
|
|
puts "This will rebuild an authorized_keys file."
|
2013-07-18 10:55:01 +00:00
|
|
|
puts "You will lose any data stored in authorized_keys file."
|
2013-05-29 19:19:23 +00:00
|
|
|
ask_to_continue
|
|
|
|
puts ""
|
|
|
|
end
|
2013-02-07 08:06:39 +00:00
|
|
|
|
2013-07-18 10:55:01 +00:00
|
|
|
Gitlab::Shell.new.remove_all_keys
|
2013-02-07 08:06:39 +00:00
|
|
|
|
2014-03-13 17:32:30 +00:00
|
|
|
Gitlab::Shell.new.batch_add_keys do |adder|
|
|
|
|
Key.find_each(batch_size: 1000) do |key|
|
|
|
|
adder.add_key(key.shell_id, key.key)
|
2013-02-07 08:06:39 +00:00
|
|
|
print '.'
|
|
|
|
end
|
|
|
|
end
|
2015-03-20 17:43:52 +00:00
|
|
|
puts ""
|
2013-02-07 08:06:39 +00:00
|
|
|
|
2014-03-13 17:32:30 +00:00
|
|
|
unless $?.success?
|
2016-06-01 22:37:15 +00:00
|
|
|
puts "Failed to add keys...".color(:red)
|
2014-03-13 17:32:30 +00:00
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
2013-02-07 08:06:39 +00:00
|
|
|
rescue Gitlab::TaskAbortedByUserError
|
2016-06-01 22:37:15 +00:00
|
|
|
puts "Quitting...".color(:red)
|
2013-02-07 08:06:39 +00:00
|
|
|
exit 1
|
|
|
|
end
|
2014-12-11 12:17:43 +00:00
|
|
|
|
|
|
|
def reset_to_commit(args)
|
2015-11-03 22:10:38 +00:00
|
|
|
tag, status = Gitlab::Popen.popen(%W(#{Gitlab.config.git.bin_path} describe -- #{args.tag}))
|
2014-12-11 12:17:43 +00:00
|
|
|
|
2014-12-12 09:17:07 +00:00
|
|
|
unless status.zero?
|
2015-11-03 22:10:38 +00:00
|
|
|
tag, status = Gitlab::Popen.popen(%W(#{Gitlab.config.git.bin_path} describe -- origin/#{args.tag}))
|
2014-12-11 12:17:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
tag = tag.strip
|
2015-11-03 22:10:38 +00:00
|
|
|
system(*%W(#{Gitlab.config.git.bin_path} reset --hard #{tag}))
|
2014-12-11 12:17:43 +00:00
|
|
|
end
|
2013-02-07 08:06:39 +00:00
|
|
|
end
|