Commit 8cfbe8ab authored by Douwe Maan's avatar Douwe Maan

Merge branch 'ci-use-gitaly-embedded-hooks' into 'master'

Prepare test suite for switch to Gitaly-embedded Git hooks

See merge request gitlab-org/gitlab-ce!25423
parents 1b10b77b 078f11a6
...@@ -662,7 +662,6 @@ production: &base ...@@ -662,7 +662,6 @@ production: &base
## GitLab Shell settings ## GitLab Shell settings
gitlab_shell: gitlab_shell:
path: /home/git/gitlab-shell/ path: /home/git/gitlab-shell/
hooks_path: /home/git/gitlab-shell/hooks/
# File that contains the secret key for verifying access for gitlab-shell. # File that contains the secret key for verifying access for gitlab-shell.
# Default is '.gitlab_shell_secret' relative to Rails.root (i.e. root of the GitLab app). # Default is '.gitlab_shell_secret' relative to Rails.root (i.e. root of the GitLab app).
...@@ -820,7 +819,6 @@ test: ...@@ -820,7 +819,6 @@ test:
path: tmp/tests/backups path: tmp/tests/backups
gitlab_shell: gitlab_shell:
path: tmp/tests/gitlab-shell/ path: tmp/tests/gitlab-shell/
hooks_path: tmp/tests/gitlab-shell/hooks/
issues_tracker: issues_tracker:
redmine: redmine:
title: "Redmine" title: "Redmine"
......
...@@ -337,7 +337,7 @@ Settings['sidekiq']['log_format'] ||= 'default' ...@@ -337,7 +337,7 @@ Settings['sidekiq']['log_format'] ||= 'default'
# #
Settings['gitlab_shell'] ||= Settingslogic.new({}) Settings['gitlab_shell'] ||= Settingslogic.new({})
Settings.gitlab_shell['path'] = Settings.absolute(Settings.gitlab_shell['path'] || Settings.gitlab['user_home'] + '/gitlab-shell/') Settings.gitlab_shell['path'] = Settings.absolute(Settings.gitlab_shell['path'] || Settings.gitlab['user_home'] + '/gitlab-shell/')
Settings.gitlab_shell['hooks_path'] = Settings.absolute(Settings.gitlab_shell['hooks_path'] || Settings.gitlab['user_home'] + '/gitlab-shell/hooks/') Settings.gitlab_shell['hooks_path'] = :deprecated_use_gitlab_shell_path_instead
Settings.gitlab_shell['secret_file'] ||= Rails.root.join('.gitlab_shell_secret') Settings.gitlab_shell['secret_file'] ||= Rails.root.join('.gitlab_shell_secret')
Settings.gitlab_shell['receive_pack'] = true if Settings.gitlab_shell['receive_pack'].nil? Settings.gitlab_shell['receive_pack'] = true if Settings.gitlab_shell['receive_pack'].nil?
Settings.gitlab_shell['upload_pack'] = true if Settings.gitlab_shell['upload_pack'].nil? Settings.gitlab_shell['upload_pack'] = true if Settings.gitlab_shell['upload_pack'].nil?
......
...@@ -340,16 +340,16 @@ module Gitlab ...@@ -340,16 +340,16 @@ module Gitlab
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def hooks_path
File.join(gitlab_shell_path, 'hooks')
end
protected protected
def gitlab_shell_path def gitlab_shell_path
File.expand_path(Gitlab.config.gitlab_shell.path) File.expand_path(Gitlab.config.gitlab_shell.path)
end end
def gitlab_shell_hooks_path
File.expand_path(Gitlab.config.gitlab_shell.hooks_path)
end
def gitlab_shell_user_home def gitlab_shell_user_home
File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}") File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}")
end end
......
...@@ -58,7 +58,7 @@ namespace :gitlab do ...@@ -58,7 +58,7 @@ namespace :gitlab do
puts "Omniauth Providers: #{omniauth_providers.join(', ')}" if Gitlab::Auth.omniauth_enabled? puts "Omniauth Providers: #{omniauth_providers.join(', ')}" if Gitlab::Auth.omniauth_enabled?
# check Gitolite version # check Gitolite version
gitlab_shell_version_file = "#{Gitlab.config.gitlab_shell.hooks_path}/../VERSION" gitlab_shell_version_file = "#{Gitlab.config.gitlab_shell.path}/VERSION"
if File.readable?(gitlab_shell_version_file) if File.readable?(gitlab_shell_version_file)
gitlab_shell_version = File.read(gitlab_shell_version_file) gitlab_shell_version = File.read(gitlab_shell_version_file)
end end
...@@ -72,7 +72,7 @@ namespace :gitlab do ...@@ -72,7 +72,7 @@ namespace :gitlab do
puts "- #{name}: \t#{repository_storage.legacy_disk_path}" puts "- #{name}: \t#{repository_storage.legacy_disk_path}"
end end
end end
puts "Hooks:\t\t#{Gitlab.config.gitlab_shell.hooks_path}" puts "GitLab Shell path:\t\t#{Gitlab.config.gitlab_shell.path}"
puts "Git:\t\t#{Gitlab.config.git.bin_path}" puts "Git:\t\t#{Gitlab.config.git.bin_path}"
end end
end end
......
...@@ -31,7 +31,7 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -31,7 +31,7 @@ describe Gitlab::Git::Repository, :seed_helper do
describe '.create_hooks' do describe '.create_hooks' do
let(:repo_path) { File.join(storage_path, 'hook-test.git') } let(:repo_path) { File.join(storage_path, 'hook-test.git') }
let(:hooks_dir) { File.join(repo_path, 'hooks') } let(:hooks_dir) { File.join(repo_path, 'hooks') }
let(:target_hooks_dir) { Gitlab.config.gitlab_shell.hooks_path } let(:target_hooks_dir) { Gitlab::Shell.new.hooks_path }
let(:existing_target) { File.join(repo_path, 'foobar') } let(:existing_target) { File.join(repo_path, 'foobar') }
before do before do
...@@ -1945,7 +1945,7 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -1945,7 +1945,7 @@ describe Gitlab::Git::Repository, :seed_helper do
imported_repo.create_from_bundle(valid_bundle_path) imported_repo.create_from_bundle(valid_bundle_path)
hooks_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access { File.join(imported_repo.path, 'hooks') } hooks_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access { File.join(imported_repo.path, 'hooks') }
expect(File.readlink(hooks_path)).to eq(Gitlab.config.gitlab_shell.hooks_path) expect(File.readlink(hooks_path)).to eq(Gitlab::Shell.new.hooks_path)
end end
it 'raises an error if the bundle is an attempted malicious payload' do it 'raises an error if the bundle is an attempted malicious payload' do
......
...@@ -393,7 +393,6 @@ describe Gitlab::Shell do ...@@ -393,7 +393,6 @@ describe Gitlab::Shell do
before do before do
allow(Gitlab.config.gitlab_shell).to receive(:path).and_return(gitlab_shell_path) allow(Gitlab.config.gitlab_shell).to receive(:path).and_return(gitlab_shell_path)
allow(Gitlab.config.gitlab_shell).to receive(:hooks_path).and_return(gitlab_shell_hooks_path)
allow(Gitlab.config.gitlab_shell).to receive(:git_timeout).and_return(800) allow(Gitlab.config.gitlab_shell).to receive(:git_timeout).and_return(800)
end end
......
...@@ -147,12 +147,15 @@ module TestEnv ...@@ -147,12 +147,15 @@ module TestEnv
version: Gitlab::Shell.version_required, version: Gitlab::Shell.version_required,
task: 'gitlab:shell:install') task: 'gitlab:shell:install')
create_fake_git_hooks # gitlab-shell hooks don't work in our test environment because they try to make internal API calls
sabotage_gitlab_shell_hooks
end end
def create_fake_git_hooks def sabotage_gitlab_shell_hooks
# gitlab-shell hooks don't work in our test environment because they try to make internal API calls create_fake_git_hooks(Gitlab::Shell.new.hooks_path)
hooks_dir = File.join(Gitlab.config.gitlab_shell.path, 'hooks') end
def create_fake_git_hooks(hooks_dir)
%w[pre-receive post-receive update].each do |hook| %w[pre-receive post-receive update].each do |hook|
File.open(File.join(hooks_dir, hook), 'w', 0755) { |f| f.puts '#!/bin/sh' } File.open(File.join(hooks_dir, hook), 'w', 0755) { |f| f.puts '#!/bin/sh' }
end end
...@@ -169,6 +172,7 @@ module TestEnv ...@@ -169,6 +172,7 @@ module TestEnv
task: "gitlab:gitaly:install[#{install_gitaly_args}]") do task: "gitlab:gitaly:install[#{install_gitaly_args}]") do
Gitlab::SetupHelper.create_gitaly_configuration(gitaly_dir, { 'default' => repos_path }, force: true) Gitlab::SetupHelper.create_gitaly_configuration(gitaly_dir, { 'default' => repos_path }, force: true)
create_fake_git_hooks(File.join(gitaly_dir, 'ruby/git-hooks'))
start_gitaly(gitaly_dir) start_gitaly(gitaly_dir)
end end
end end
......
...@@ -8,7 +8,7 @@ describe 'gitlab:shell rake tasks' do ...@@ -8,7 +8,7 @@ describe 'gitlab:shell rake tasks' do
end end
after do after do
TestEnv.create_fake_git_hooks TestEnv.sabotage_gitlab_shell_hooks
end end
describe 'install task' do describe 'install task' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment