Commit c04b563bc187cd4b3719b802ffffa22aec997a9e
Exists in
6-6-stable-ee
and in
1 other branch
Merge branch 'master' of gitlab.com:gitlab-org/omnibus-gitlab into 6-6-stable
Showing
10 changed files
with
236 additions
and
16 deletions
Show diff stats
README.md
... | ... | @@ -98,9 +98,20 @@ Omnibus-gitlab uses four different directories. |
98 | 98 | - `/var/log/gitlab` contains all log data generated by components of |
99 | 99 | omnibus-gitlab. |
100 | 100 | |
101 | +### Storing Git data in an alternative directory | |
102 | + | |
103 | +By default, omnibus-gitlab stores Git repository data in `/var/opt/gitlab/git-data`. | |
104 | +You can change this location by adding the following line to `/etc/gitlab/gitlab.rb`. | |
105 | + | |
106 | +```ruby | |
107 | +git_data_dir "/mnt/nas/git-data" | |
108 | +``` | |
109 | + | |
110 | +Run `sudo gitlab-ctl reconfigure` for the change to take effect. | |
111 | + | |
101 | 112 | ## Building your own package |
102 | 113 | |
103 | 114 | See [the separate build documentation](doc/build.md). |
104 | 115 | |
105 | 116 | [downloads]: https://www.gitlab.com/downloads |
106 | -[CE README]: https://gitlab.com/gitlab-org/gitlab-ce/blob/master/README.md | |
107 | 117 | \ No newline at end of file |
118 | +[CE README]: https://gitlab.com/gitlab-org/gitlab-ce/blob/master/README.md | ... | ... |
... | ... | @@ -0,0 +1,22 @@ |
1 | +diff --git a/lib/backup/manager.rb b/lib/backup/manager.rb | |
2 | +index efaefa4..8f0e38f 100644 | |
3 | +--- a/lib/backup/manager.rb | |
4 | ++++ b/lib/backup/manager.rb | |
5 | +@@ -7,7 +7,7 @@ module Backup | |
6 | + s = {} | |
7 | + s[:db_version] = "#{ActiveRecord::Migrator.current_version}" | |
8 | + s[:backup_created_at] = Time.now | |
9 | +- s[:gitlab_version] = %x{git rev-parse HEAD}.gsub(/\n/,"") | |
10 | ++ s[:gitlab_version] = File.read(Rails.root.join('REVISION')).chomp | |
11 | + s[:tar_version] = %x{tar --version | head -1}.gsub(/\n/,"") | |
12 | + | |
13 | + Dir.chdir(Gitlab.config.backup.path) | |
14 | +@@ -92,7 +92,7 @@ module Backup | |
15 | + Dir.chdir(Rails.root) | |
16 | + | |
17 | + # restoring mismatching backups can lead to unexpected problems | |
18 | +- if settings[:gitlab_version] != %x{git rev-parse HEAD}.gsub(/\n/, "") | |
19 | ++ if settings[:gitlab_version] != File.read(Rails.root.join('REVISION')).chomp | |
20 | + puts "GitLab version mismatch:".red | |
21 | + puts " Your current HEAD differs from the HEAD in the backup!".red | |
22 | + puts " Please switch to the following revision and try again:".red | ... | ... |
... | ... | @@ -0,0 +1,14 @@ |
1 | +diff --git a/lib/backup/repository.rb b/lib/backup/repository.rb | |
2 | +index 20fd5ba..552f7ea 100644 | |
3 | +--- a/lib/backup/repository.rb | |
4 | ++++ b/lib/backup/repository.rb | |
5 | +@@ -72,8 +72,7 @@ module Backup | |
6 | + end | |
7 | + | |
8 | + print 'Put GitLab hooks in repositories dirs'.yellow | |
9 | +- gitlab_shell_user_home = File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}") | |
10 | +- if system("#{gitlab_shell_user_home}/gitlab-shell/support/rewrite-hooks.sh", Gitlab.config.gitlab_shell.repos_path) | |
11 | ++ if system("#{Gitlab.config.gitlab_shell.path}/support/rewrite-hooks.sh", Gitlab.config.gitlab_shell.repos_path) | |
12 | + puts " [DONE]".green | |
13 | + else | |
14 | + puts " [FAILED]".red | ... | ... |
config/patches/gitlab-rails/backup_uploads_realpath.patch
0 → 100644
... | ... | @@ -0,0 +1,24 @@ |
1 | +diff --git a/lib/backup/uploads.rb b/lib/backup/uploads.rb | |
2 | +index e79da7e..e50e1ff 100644 | |
3 | +--- a/lib/backup/uploads.rb | |
4 | ++++ b/lib/backup/uploads.rb | |
5 | +@@ -3,7 +3,7 @@ module Backup | |
6 | + attr_reader :app_uploads_dir, :backup_uploads_dir, :backup_dir | |
7 | + | |
8 | + def initialize | |
9 | +- @app_uploads_dir = Rails.root.join('public', 'uploads') | |
10 | ++ @app_uploads_dir = File.realpath(Rails.root.join('public', 'uploads')) | |
11 | + @backup_dir = Gitlab.config.backup.path | |
12 | + @backup_uploads_dir = File.join(Gitlab.config.backup.path, 'uploads') | |
13 | + end | |
14 | +@@ -21,8 +21,9 @@ module Backup | |
15 | + end | |
16 | + | |
17 | + def backup_existing_uploads_dir | |
18 | ++ timestamped_uploads_path = File.join(app_uploads_dir, '..', "uploads.#{Time.now.to_i}") | |
19 | + if File.exists?(app_uploads_dir) | |
20 | +- FileUtils.mv(app_uploads_dir, Rails.root.join('public', "uploads.#{Time.now.to_i}")) | |
21 | ++ FileUtils.mv(app_uploads_dir, timestamped_uploads_path) | |
22 | + end | |
23 | + end | |
24 | + end | ... | ... |
... | ... | @@ -0,0 +1,126 @@ |
1 | +diff --git a/bin/create-hooks b/bin/create-hooks | |
2 | +new file mode 100755 | |
3 | +index 0000000..d6f07c7 | |
4 | +--- /dev/null | |
5 | ++++ b/bin/create-hooks | |
6 | +@@ -0,0 +1,12 @@ | |
7 | ++#!/usr/bin/env ruby | |
8 | ++ | |
9 | ++# Recreate GitLab hooks in the Git repositories managed by GitLab. | |
10 | ++# | |
11 | ++# This script is used when restoring a GitLab backup. | |
12 | ++ | |
13 | ++require_relative '../lib/gitlab_init' | |
14 | ++require File.join(ROOT_PATH, 'lib', 'gitlab_projects') | |
15 | ++ | |
16 | ++Dir["#{GitlabConfig.new.repos_path}/*/*.git"].each do |repo| | |
17 | ++ GitlabProjects.create_hooks(repo) | |
18 | ++end | |
19 | +diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb | |
20 | +index fec204c..b3ff372 100644 | |
21 | +--- a/lib/gitlab_projects.rb | |
22 | ++++ b/lib/gitlab_projects.rb | |
23 | +@@ -42,6 +42,12 @@ class GitlabProjects | |
24 | + end | |
25 | + end | |
26 | + | |
27 | ++ def self.create_hooks(path) | |
28 | ++ hook = File.join(path, 'hooks', 'update') | |
29 | ++ File.delete(hook) if File.exists?(hook) | |
30 | ++ File.symlink(File.join(ROOT_PATH, 'hooks', 'update'), hook) | |
31 | ++ end | |
32 | ++ | |
33 | + protected | |
34 | + | |
35 | + def create_branch | |
36 | +@@ -74,13 +80,7 @@ class GitlabProjects | |
37 | + $logger.info "Adding project #{@project_name} at <#{full_path}>." | |
38 | + FileUtils.mkdir_p(full_path, mode: 0770) | |
39 | + cmd = %W(git --git-dir=#{full_path} init --bare) | |
40 | +- system(*cmd) && create_hooks(full_path) | |
41 | +- end | |
42 | +- | |
43 | +- def create_hooks(path) | |
44 | +- hook = File.join(path, 'hooks', 'update') | |
45 | +- File.delete(hook) if File.exists?(hook) | |
46 | +- File.symlink(File.join(ROOT_PATH, 'hooks', 'update'), hook) | |
47 | ++ system(*cmd) && self.class.create_hooks(full_path) | |
48 | + end | |
49 | + | |
50 | + def rm_project | |
51 | +@@ -94,7 +94,7 @@ class GitlabProjects | |
52 | + @source = ARGV.shift | |
53 | + $logger.info "Importing project #{@project_name} from <#{@source}> to <#{full_path}>." | |
54 | + cmd = %W(git clone --bare -- #{@source} #{full_path}) | |
55 | +- system(*cmd) && create_hooks(full_path) | |
56 | ++ system(*cmd) && self.class.create_hooks(full_path) | |
57 | + end | |
58 | + | |
59 | + # Move repository from one directory to another | |
60 | +@@ -156,7 +156,7 @@ class GitlabProjects | |
61 | + | |
62 | + $logger.info "Forking project from <#{full_path}> to <#{full_destination_path}>." | |
63 | + cmd = %W(git clone --bare -- #{full_path} #{full_destination_path}) | |
64 | +- system(*cmd) && create_hooks(full_destination_path) | |
65 | ++ system(*cmd) && self.class.create_hooks(full_destination_path) | |
66 | + end | |
67 | + | |
68 | + def update_head | |
69 | +diff --git a/spec/gitlab_projects_spec.rb b/spec/gitlab_projects_spec.rb | |
70 | +index bbe27e2..4341ca5 100644 | |
71 | +--- a/spec/gitlab_projects_spec.rb | |
72 | ++++ b/spec/gitlab_projects_spec.rb | |
73 | +@@ -95,7 +95,7 @@ describe GitlabProjects do | |
74 | + | |
75 | + it "should create a directory" do | |
76 | + gl_projects.stub(system: true) | |
77 | +- gl_projects.stub(create_hooks: true) | |
78 | ++ GitlabProjects.stub(create_hooks: true) | |
79 | + gl_projects.exec | |
80 | + File.exists?(tmp_repo_path).should be_true | |
81 | + end | |
82 | +@@ -103,7 +103,7 @@ describe GitlabProjects do | |
83 | + it "should receive valid cmd" do | |
84 | + valid_cmd = ['git', "--git-dir=#{tmp_repo_path}", 'init', '--bare'] | |
85 | + gl_projects.should_receive(:system).with(*valid_cmd).and_return(true) | |
86 | +- gl_projects.should_receive(:create_hooks).with(tmp_repo_path) | |
87 | ++ GitlabProjects.should_receive(:create_hooks).with(tmp_repo_path) | |
88 | + gl_projects.exec | |
89 | + end | |
90 | + | |
91 | +diff --git a/support/rewrite-hooks.sh b/support/rewrite-hooks.sh | |
92 | +index 3c96b6f..585eaeb 100755 | |
93 | +--- a/support/rewrite-hooks.sh | |
94 | ++++ b/support/rewrite-hooks.sh | |
95 | +@@ -1,28 +1,5 @@ | |
96 | + #!/bin/bash | |
97 | ++# This script is deprecated. Use bin/create-hooks instead. | |
98 | + | |
99 | +-# $1 is an optional argument specifying the location of the repositories directory. | |
100 | +-# Defaults to /home/git/repositories if not provided | |
101 | +- | |
102 | +-home_dir="/home/git" | |
103 | +-src=${1:-"$home_dir/repositories"} | |
104 | +- | |
105 | +-function create_link_in { | |
106 | +- ln -s -f "$home_dir/gitlab-shell/hooks/update" "$1/hooks/update" | |
107 | +-} | |
108 | +- | |
109 | +-for dir in `ls "$src/"` | |
110 | +-do | |
111 | +- if [ -d "$src/$dir" ]; then | |
112 | +- if [[ "$dir" =~ ^.*\.git$ ]] | |
113 | +- then | |
114 | +- create_link_in "$src/$dir" | |
115 | +- else | |
116 | +- for subdir in `ls "$src/$dir/"` | |
117 | +- do | |
118 | +- if [ -d "$src/$dir/$subdir" ] && [[ "$subdir" =~ ^.*\.git$ ]]; then | |
119 | +- create_link_in "$src/$dir/$subdir" | |
120 | +- fi | |
121 | +- done | |
122 | +- fi | |
123 | +- fi | |
124 | +-done | |
125 | ++gitlab_shell_dir="$(cd $(dirname $0) && pwd)/.." | |
126 | ++exec ${gitlab_shell_dir}/bin/create-hooks | ... | ... |
config/software/gitlab-rails.rb
... | ... | @@ -43,6 +43,13 @@ build do |
43 | 43 | # source code to include the Git revision of the code included in the omnibus |
44 | 44 | # build. |
45 | 45 | command "sed -i \"s/.*REVISION.*/REVISION = '$(git log --pretty=format:'%h' -n 1)'/\" config/initializers/2_app.rb" |
46 | + patch :source => "backup_read_REVISION.patch" | |
47 | + command "git rev-parse HEAD > REVISION" | |
48 | + | |
49 | + # The user uploads path is not (yet) configurable in gitlab-rails. As a | |
50 | + # workaround, omnibus-gitlab creates a symlink for public/uploads. This breaks | |
51 | + # the GitLab backup script. | |
52 | + patch :source => "backup_uploads_realpath.patch" | |
46 | 53 | |
47 | 54 | bundle "install --without mysql development test --path=#{install_dir}/embedded/service/gem", :env => env |
48 | 55 | |
... | ... | @@ -55,10 +62,10 @@ build do |
55 | 62 | # database at this point so that is a problem. This bug is fixed in |
56 | 63 | # acts-as-taggable-on 3.0.0 by |
57 | 64 | # https://github.com/mbleigh/acts-as-taggable-on/commit/ad02dc9bb24ec8e1e79e7e35e2d4bb5910a66d8e |
58 | - patch = "#{Omnibus.project_root}/config/patches/acts-as-taggable-on-ad02dc9bb24ec8e1e79e7e35e2d4bb5910a66d8e.diff" | |
65 | + aato_patch = "#{Omnibus.project_root}/config/patches/acts-as-taggable-on-ad02dc9bb24ec8e1e79e7e35e2d4bb5910a66d8e.diff" | |
59 | 66 | # To make this idempotent, we apply the patch (in case this is a first run) or |
60 | 67 | # we revert and re-apply the patch (if this is a second or later run). |
61 | - command "git apply #{patch} || (git apply -R #{patch} && git apply #{patch})", | |
68 | + command "git apply #{aato_patch} || (git apply -R #{aato_patch} && git apply #{aato_patch})", | |
62 | 69 | :cwd => "#{install_dir}/embedded/service/gem/ruby/1.9.1/gems/acts-as-taggable-on-2.4.1" |
63 | 70 | rake "assets:precompile", :env => {"RAILS_ENV" => "production"} |
64 | 71 | # Tear down now that the assets:precompile is done. | ... | ... |
config/software/gitlab-shell.rb
... | ... | @@ -25,6 +25,9 @@ dependency "rsync" |
25 | 25 | source :git => "https://gitlab.com/gitlab-org/gitlab-shell.git" |
26 | 26 | |
27 | 27 | build do |
28 | + # patch gitlab-shell 1.8.0 to correctly create hooks during backup restore | |
29 | + patch :source => "create_hooks.patch" | |
30 | + | |
28 | 31 | command "mkdir -p #{install_dir}/embedded/service/gitlab-shell" |
29 | 32 | command "#{install_dir}/embedded/bin/rsync -a --delete --exclude=.git/*** --exclude=.gitignore ./ #{install_dir}/embedded/service/gitlab-shell/" |
30 | 33 | block do | ... | ... |
files/gitlab-cookbooks/gitlab/attributes/default.rb
... | ... | @@ -44,7 +44,7 @@ default['gitlab']['gitlab-rails']['log_directory'] = "/var/log/gitlab/gitlab-rai |
44 | 44 | default['gitlab']['gitlab-rails']['environment'] = 'production' |
45 | 45 | |
46 | 46 | default['gitlab']['gitlab-rails']['internal_api_url'] = "http://localhost:8080" |
47 | -default['gitlab']['gitlab-rails']['uploads_directory'] = "/var/opt/gitlab/uploads" | |
47 | +default['gitlab']['gitlab-rails']['uploads_directory'] = "/var/opt/gitlab/gitlab-rails/uploads" | |
48 | 48 | default['gitlab']['gitlab-rails']['rate_limit_requests_per_period'] = 10 |
49 | 49 | default['gitlab']['gitlab-rails']['rate_limit_period'] = 60 |
50 | 50 | |
... | ... | @@ -86,10 +86,10 @@ default['gitlab']['gitlab-rails']['ldap_method'] = "ssl" |
86 | 86 | default['gitlab']['gitlab-rails']['ldap_bind_dn'] = "_the_full_dn_of_the_user_you_will_bind_with" |
87 | 87 | default['gitlab']['gitlab-rails']['ldap_password'] = "_the_password_of_the_bind_user" |
88 | 88 | default['gitlab']['gitlab-rails']['ldap_allow_username_or_email_login'] = true |
89 | -default['gitlab']['gitlab-rails']['satellites_path'] = "/var/opt/gitlab/gitlab-satellites" | |
89 | +default['gitlab']['gitlab-rails']['satellites_path'] = "/var/opt/gitlab/git-data/gitlab-satellites" | |
90 | 90 | default['gitlab']['gitlab-rails']['backup_path'] = "tmp/backups" |
91 | 91 | default['gitlab']['gitlab-rails']['gitlab_shell_path'] = "/opt/gitlab/embedded/service/gitlab-shell/" |
92 | -default['gitlab']['gitlab-rails']['gitlab_shell_repos_path'] = "/var/opt/gitlab/repositories" | |
92 | +default['gitlab']['gitlab-rails']['gitlab_shell_repos_path'] = "/var/opt/gitlab/git-data/repositories" | |
93 | 93 | default['gitlab']['gitlab-rails']['gitlab_shell_hooks_path'] = "/opt/gitlab/embedded/service/gitlab-shell/hooks/" |
94 | 94 | default['gitlab']['gitlab-rails']['gitlab_shell_upload_pack'] = true |
95 | 95 | default['gitlab']['gitlab-rails']['gitlab_shell_receive_pack'] = true |
... | ... | @@ -125,6 +125,7 @@ default['gitlab']['sidekiq']['log_directory'] = "/var/log/gitlab/sidekiq" |
125 | 125 | # gitlab-shell |
126 | 126 | ### |
127 | 127 | default['gitlab']['gitlab-shell']['log_directory'] = "/var/log/gitlab/gitlab-shell/" |
128 | +default['gitlab']['gitlab-shell']['git_data_directory'] = "/var/opt/gitlab/git-data" | |
128 | 129 | |
129 | 130 | |
130 | 131 | ### | ... | ... |
files/gitlab-cookbooks/gitlab/libraries/gitlab.rb
... | ... | @@ -31,11 +31,13 @@ module Gitlab |
31 | 31 | postgresql Mash.new |
32 | 32 | redis Mash.new |
33 | 33 | gitlab_rails Mash.new |
34 | + gitlab_shell Mash.new | |
34 | 35 | unicorn Mash.new |
35 | 36 | sidekiq Mash.new |
36 | 37 | nginx Mash.new |
37 | 38 | node nil |
38 | 39 | external_url nil |
40 | + git_data_dir nil | |
39 | 41 | |
40 | 42 | class << self |
41 | 43 | |
... | ... | @@ -103,6 +105,14 @@ module Gitlab |
103 | 105 | Gitlab['gitlab_rails']['gitlab_port'] = uri.port |
104 | 106 | end |
105 | 107 | |
108 | + def parse_git_data_dir | |
109 | + return unless git_data_dir | |
110 | + | |
111 | + Gitlab['gitlab_shell']['git_data_directory'] ||= git_data_dir | |
112 | + Gitlab['gitlab_rails']['gitlab_shell_repos_path'] ||= File.join(git_data_dir, "repositories") | |
113 | + Gitlab['gitlab_rails']['satellites_path'] ||= File.join(git_data_dir, "gitlab-satellites") | |
114 | + end | |
115 | + | |
106 | 116 | def generate_hash |
107 | 117 | results = { "gitlab" => {} } |
108 | 118 | [ |
... | ... | @@ -110,6 +120,7 @@ module Gitlab |
110 | 120 | "user", |
111 | 121 | "redis", |
112 | 122 | "gitlab_rails", |
123 | + "gitlab_shell", | |
113 | 124 | "unicorn", |
114 | 125 | "sidekiq", |
115 | 126 | "nginx", |
... | ... | @@ -125,6 +136,7 @@ module Gitlab |
125 | 136 | def generate_config(node_name) |
126 | 137 | generate_secrets(node_name) |
127 | 138 | parse_external_url |
139 | + parse_git_data_dir | |
128 | 140 | generate_hash |
129 | 141 | end |
130 | 142 | end | ... | ... |
files/gitlab-cookbooks/gitlab/recipes/gitlab-shell.rb
... | ... | @@ -44,16 +44,16 @@ execute "chcon -t ssh_home_t #{ssh_dir}" do |
44 | 44 | only_if "id -Z" |
45 | 45 | end |
46 | 46 | |
47 | -directory log_directory do | |
48 | - owner git_user | |
49 | - mode "0700" | |
50 | - recursive true | |
51 | -end | |
52 | - | |
53 | -directory gitlab_shell_var_dir do | |
54 | - owner git_user | |
55 | - mode '0700' | |
56 | - recursive true | |
47 | +[ | |
48 | + log_directory, | |
49 | + gitlab_shell_var_dir, | |
50 | + node['gitlab']['gitlab-shell']['git_data_directory'] | |
51 | +].each do |dir| | |
52 | + directory dir do | |
53 | + owner git_user | |
54 | + mode "0700" | |
55 | + recursive true | |
56 | + end | |
57 | 57 | end |
58 | 58 | |
59 | 59 | template_symlink File.join(gitlab_shell_var_dir, "config.yml") do | ... | ... |