Commit 301c4068e13c838368fa2f5d9e2e9af2b2124c23
1 parent
fead9678
Exists in
spb-stable
and in
2 other branches
Add rake task to install or upgrade gitlab-shell installation.
Showing
1 changed file
with
58 additions
and
0 deletions
Show diff stats
lib/tasks/gitlab/shell.rake
| 1 | namespace :gitlab do | 1 | namespace :gitlab do |
| 2 | namespace :shell do | 2 | namespace :shell do |
| 3 | + desc "GITLAB | Install or upgrade gitlab-shell" | ||
| 4 | + task :install, [:tag, :repo] => :environment do |t, args| | ||
| 5 | + warn_user_is_not_gitlab | ||
| 6 | + | ||
| 7 | + args.with_defaults(tag: "v1.9.1", repo: "https://gitlab.com/gitlab-org/gitlab-shell.git") | ||
| 8 | + | ||
| 9 | + user = Settings.gitlab.user | ||
| 10 | + home_dir = Settings.gitlab.user_home | ||
| 11 | + gitlab_url = Settings.gitlab.url | ||
| 12 | + # gitlab-shell requires a / at the end of the url | ||
| 13 | + gitlab_url += "/" unless gitlab_url.match(/\/$/) | ||
| 14 | + target_dir = File.join(home_dir, "gitlab-shell") | ||
| 15 | + | ||
| 16 | + # Clone if needed | ||
| 17 | + unless File.directory?(target_dir) | ||
| 18 | + sh "git clone '#{args.repo}' '#{target_dir}'" | ||
| 19 | + end | ||
| 20 | + | ||
| 21 | + # Make sure we're on the right tag | ||
| 22 | + Dir.chdir(target_dir) do | ||
| 23 | + sh "git fetch origin && git reset --hard $(git describe #{args.tag} || git describe origin/#{args.tag})" | ||
| 24 | + | ||
| 25 | + redis_url = URI.parse(ENV['REDIS_URL'] || "redis://localhost:6379") | ||
| 26 | + | ||
| 27 | + config = { | ||
| 28 | + user: user, | ||
| 29 | + gitlab_url: gitlab_url, | ||
| 30 | + http_settings: {self_signed_cert: false}, | ||
| 31 | + repos_path: File.join(home_dir, "repositories"), | ||
| 32 | + auth_file: File.join(home_dir, ".ssh", "authorized_keys"), | ||
| 33 | + redis: { | ||
| 34 | + bin: %x{which redis-cli}.chomp, | ||
| 35 | + host: redis_url.host, | ||
| 36 | + port: redis_url.port, | ||
| 37 | + namespace: "resque:gitlab" | ||
| 38 | + }, | ||
| 39 | + log_level: "INFO", | ||
| 40 | + audit_usernames: false | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + # Generate config.yml based on existing gitlab settings | ||
| 44 | + File.open("config.yml", "w+") {|f| f.puts config.to_yaml} | ||
| 45 | + | ||
| 46 | + # Launch installation process | ||
| 47 | + sh "bin/install" | ||
| 48 | + end | ||
| 49 | + | ||
| 50 | + # Required for debian packaging with PKGR: Setup .ssh/environment with | ||
| 51 | + # the current PATH, so that the correct ruby version gets loaded | ||
| 52 | + # Requires to set "PermitUserEnvironment yes" in sshd config (should not | ||
| 53 | + # be an issue since it is more than likely that there are no "normal" | ||
| 54 | + # user accounts on a gitlab server). The alternative is for the admin to | ||
| 55 | + # install a ruby (1.9.3+) in the global path. | ||
| 56 | + File.open(File.join(home_dir, ".ssh", "environment"), "w+") do |f| | ||
| 57 | + f.puts "PATH=#{ENV['PATH']}" | ||
| 58 | + end | ||
| 59 | + end | ||
| 60 | + | ||
| 3 | desc "GITLAB | Setup gitlab-shell" | 61 | desc "GITLAB | Setup gitlab-shell" |
| 4 | task setup: :environment do | 62 | task setup: :environment do |
| 5 | setup | 63 | setup |