Commit cf7cec2c authored by Marin Jankovski's avatar Marin Jankovski

Merge branch 'master' of dev.gitlab.org:gitlab/cookbook-gitlab

parents 9aa20c40 c88e933e
......@@ -17,12 +17,23 @@ default['gitlab']['packages'] = packages
default['gitlab']['compile_ruby'] = true
default['gitlab']['ruby'] = "2.0.0-p353" # Latest 2.0 by ruby-build 20131225.1 (Ubuntu)
# User
default['gitlab']['user'] = "git" # Do not change this attribute in production unless you know what you do since some code from the GitLab repo such as init.d script assume it is git.
default['gitlab']['group'] = "git"
default['gitlab']['user_uid'] = nil # Use to specify user id.
default['gitlab']['user_gid'] = nil # Use to specify group id.
default['gitlab']['home'] = "/home/git"
# GitLab hq
default['gitlab']['path'] = "#{node['gitlab']['home']}/gitlab" # Do not change this attribute in production unless you know what you do since some code from the GitLab repo such as init.d assume this path.
default['gitlab']['satellites_path'] = "#{node['gitlab']['home']}/gitlab-satellites"
# GitLab shell
default['gitlab']['shell_repository'] = "https://github.com/gitlabhq/gitlab-shell.git"
# GitLab shell configuration
default['gitlab']['repos_path'] = "/home/git/repositories"
default['gitlab']['shell_path'] = "/home/git/gitlab-shell"
default['gitlab']['repos_path'] = "#{node['gitlab']['home']}/repositories"
default['gitlab']['shell_path'] = "#{node['gitlab']['home']}/gitlab-shell"
default['gitlab']['redis_path'] = "/usr/local/bin/redis-cli"
default['gitlab']['redis_host'] = "127.0.0.1"
default['gitlab']['redis_port'] = "6379"
......@@ -154,17 +165,6 @@ default['postfix']['mydomain'] = "localhost"
default['postfix']['myorigin'] = "mail.localhost"
default['postfix']['smtp_use_tls'] = "no"
# User
default['gitlab']['user'] = "git" # Do not change this attribute in production since some code from the GitLab repo such as init.d script assume it is git.
default['gitlab']['group'] = "git"
default['gitlab']['user_uid'] = nil # Use to specify user id.
default['gitlab']['user_gid'] = nil # Use to specify group id.
default['gitlab']['home'] = "/home/git"
# GitLab hq
default['gitlab']['path'] = "/home/git/gitlab" # Do not change this attribute in production since some code from the GitLab repo such as init.d assume this path.
default['gitlab']['satellites_path'] = "/home/git/gitlab-satellites"
# Unicorn specific configuration
default['gitlab']['unicorn_workers_number'] = 2
default['gitlab']['unicorn_timeout'] = 30
......@@ -224,6 +224,12 @@ default['gitlab']['monitrc']['disk_usage'] = {
:path => "/" # Path on the filesystem to monitor
}
default['gitlab']['monitrc']['redis'] = {
:service_name => "/etc/init.d/redis6379",
:redis_pid_path => "/var/run/redis/6379/redis_6379.pid"
}
# Can be specified if you need to use different alert email in sidekiq monitor config
# If you need only one alert email, specify with https://github.com/phlipper/chef-monit/blob/1.4.0/attributes/default.rb#L27
default['gitlab']['monitrc']['notify_email'] = nil
......
......@@ -63,6 +63,7 @@ template File.join(gitlab['path'], 'config', 'unicorn.rb') do
user gitlab['user']
group gitlab['group']
variables({
:app_root => gitlab['path'],
:unicorn_workers_number => gitlab['unicorn_workers_number'],
:unicorn_timeout => gitlab['unicorn_timeout']
})
......@@ -195,6 +196,15 @@ ruby_block "Copy from example gitlab init config" do
end
end
template "/etc/default/gitlab" do
source "gitlab.default.erb"
mode 0755
variables(
:app_user => node['gitlab']['user'],
:app_root => node['gitlab']['path']
)
end
case gitlab['env']
when 'production'
# Updates defaults so gitlab can boot on start. As per man pages of update-rc.d runs only if links do not exist
......
......@@ -63,3 +63,13 @@ directory "#{gitlab['path']}/bin" do
mode 0755
action :create
end
redis = monitrc['redis']
monit_monitrc "redis" do
variables ({
host: gitlab['redis_host'],
port: gitlab['redis_port'],
service_name: redis['service_name'],
redis_pid_path: redis['redis_pid_path']
})
end
......@@ -6,7 +6,7 @@ describe "gitlab::clone" do
describe "under ubuntu" do
["12.04", "10.04"].each do |version|
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.converge("gitlab::clone", "gitlab::start")
......@@ -22,7 +22,7 @@ describe "gitlab::clone" do
end
describe "in development" do
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "development"
runner.converge("gitlab::clone", "gitlab::start")
......@@ -37,12 +37,30 @@ describe "gitlab::clone" do
)
end
end
describe "when customizing gitlab user home" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::clone", "gitlab::start")
end
it "clones the gitlab repository" do
expect(chef_run).to sync_git('/data/git/gitlab').with(
repository: 'https://github.com/gitlabhq/gitlabhq.git',
revision: '6-8-stable',
user: 'git',
group: 'git'
)
end
end
end
end
describe "under centos" do
["5.8", "6.4"].each do |version|
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.converge("gitlab::clone", "gitlab::start")
......@@ -58,7 +76,7 @@ describe "gitlab::clone" do
end
describe "in development" do
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "development"
runner.converge("gitlab::clone", "gitlab::start")
......@@ -73,6 +91,24 @@ describe "gitlab::clone" do
)
end
end
describe "when customizing gitlab user home" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::clone", "gitlab::start")
end
it "clones the gitlab repository" do
expect(chef_run).to sync_git('/data/git/gitlab').with(
repository: 'https://github.com/gitlabhq/gitlabhq.git',
revision: '6-8-stable',
user: 'git',
group: 'git'
)
end
end
end
end
end
......@@ -95,6 +95,60 @@ describe "gitlab::gems" do
end
end
end
describe "when customizing gitlab user home" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::gems")
end
it 'creates a gemrc from template' do
expect(chef_run).to create_template('/data/git/.gemrc')
end
it 'executes bundle without development and test' do
resource = chef_run.find_resource(:execute, 'bundle install')
expect(resource.cwd).to eq("/data/git/gitlab")
end
describe "when using mysql" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['database_adapter'] = "mysql"
runner.node.set['gitlab']['database_password'] = "datapass"
runner.node.set['mysql']['server_root_password'] = "rootpass"
runner.node.set['mysql']['server_repl_password'] = "replpass"
runner.node.set['mysql']['server_debian_password'] = "debpass"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::gems")
end
it 'executes bundle without postgres' do
resource = chef_run.find_resource(:execute, 'bundle install')
expect(resource.cwd).to eq("/data/git/gitlab")
end
end
describe "when using postgres" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['database_adapter'] = "postgresql"
runner.node.set['gitlab']['database_password'] = "datapass"
runner.node.set['postgresql']['password']['postgres'] = "psqlpass"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::gems")
end
it 'executes bundle without mysql' do
resource = chef_run.find_resource(:execute, 'bundle install')
expect(resource.cwd).to eq("/data/git/gitlab")
end
end
end
end
end
......@@ -189,6 +243,60 @@ describe "gitlab::gems" do
end
end
end
describe "when customizing gitlab user home" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::gems")
end
it 'creates a gemrc from template' do
expect(chef_run).to create_template('/data/git/.gemrc')
end
it 'executes bundle without development and test' do
resource = chef_run.find_resource(:execute, 'bundle install')
expect(resource.cwd).to eq("/data/git/gitlab")
end
describe "when using mysql" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['database_adapter'] = "mysql"
runner.node.set['gitlab']['database_password'] = "datapass"
runner.node.set['mysql']['server_root_password'] = "rootpass"
runner.node.set['mysql']['server_repl_password'] = "replpass"
runner.node.set['mysql']['server_debian_password'] = "debpass"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::gems")
end
it 'executes bundle without postgres' do
resource = chef_run.find_resource(:execute, 'bundle install')
expect(resource.cwd).to eq("/data/git/gitlab")
end
end
describe "when using postgres" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['database_adapter'] = "postgresql"
runner.node.set['gitlab']['database_password'] = "datapass"
runner.node.set['postgresql']['password']['postgres'] = "psqlpass"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::gems")
end
it 'executes bundle without mysql' do
resource = chef_run.find_resource(:execute, 'bundle install')
expect(resource.cwd).to eq("/data/git/gitlab")
end
end
end
end
end
end
......@@ -6,7 +6,7 @@ describe "gitlab::gitlab_shell_clone" do
describe "under ubuntu" do
["12.04", "10.04"].each do |version|
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.converge("gitlab::gitlab_shell_clone")
......@@ -22,7 +22,7 @@ describe "gitlab::gitlab_shell_clone" do
end
describe "in development" do
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "development"
runner.converge("gitlab::gitlab_shell_clone")
......@@ -37,12 +37,25 @@ describe "gitlab::gitlab_shell_clone" do
)
end
end
describe "when customizing gitlab user home" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::gitlab_shell_clone")
end
it "clones the gitlab-shell repository" do
expect(chef_run).to sync_git('/data/git/gitlab-shell')
end
end
end
end
describe "under centos" do
["5.8", "6.4"].each do |version|
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.converge("gitlab::gitlab_shell_clone")
......@@ -58,7 +71,7 @@ describe "gitlab::gitlab_shell_clone" do
end
describe "in development" do
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "development"
runner.converge("gitlab::gitlab_shell_clone")
......@@ -73,6 +86,19 @@ describe "gitlab::gitlab_shell_clone" do
)
end
end
describe "when customizing gitlab user home" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::gitlab_shell_clone")
end
it "clones the gitlab-shell repository" do
expect(chef_run).to sync_git('/data/git/gitlab-shell')
end
end
end
end
end
......@@ -56,6 +56,44 @@ describe "gitlab::gitlab_shell_install" do
it 'does not run a execute to install gitlab shell on its own' do
expect(chef_run).to_not run_execute('gitlab-shell install')
end
describe "when customizing gitlab user home" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::gitlab_shell_install")
end
it 'creates a gitlab shell config' do
expect(chef_run).to create_template('/data/git/gitlab-shell/config.yml').with(
source: 'gitlab_shell.yml.erb',
variables: {
user: "git",
home: "/data/git",
url: "http://localhost:80/",
repos_path: "/data/git/repositories",
redis_path: "/usr/local/bin/redis-cli",
redis_host: "127.0.0.1",
redis_port: "6379",
namespace: "resque:gitlab",
self_signed_cert: false
}
)
end
it 'creates repository directory in the gitlab user home directory' do
expect(chef_run).to create_directory("/data/git/repositories")
end
it 'creates .ssh directory in the gitlab user home directory' do
expect(chef_run).to create_directory("/data/git/.ssh")
end
it 'creates authorized hosts file in .ssh directory' do
expect(chef_run).to create_file_if_missing("/data/git/.ssh/authorized_keys")
end
end
end
end
......@@ -111,6 +149,44 @@ describe "gitlab::gitlab_shell_install" do
it 'does not run a execute to install gitlab shell on its own' do
expect(chef_run).to_not run_execute('gitlab-shell install')
end
describe "when customizing gitlab user home" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::gitlab_shell_install")
end
it 'creates a gitlab shell config' do
expect(chef_run).to create_template('/data/git/gitlab-shell/config.yml').with(
source: 'gitlab_shell.yml.erb',
variables: {
user: "git",
home: "/data/git",
url: "http://localhost:80/",
repos_path: "/data/git/repositories",
redis_path: "/usr/local/bin/redis-cli",
redis_host: "127.0.0.1",
redis_port: "6379",
namespace: "resque:gitlab",
self_signed_cert: false
}
)
end
it 'creates repository directory in the gitlab user home directory' do
expect(chef_run).to create_directory("/data/git/repositories")
end
it 'creates .ssh directory in the gitlab user home directory' do
expect(chef_run).to create_directory("/data/git/.ssh")
end
it 'creates authorized hosts file in .ssh directory' do
expect(chef_run).to create_file_if_missing("/data/git/.ssh/authorized_keys")
end
end
end
end
end
......@@ -94,6 +94,7 @@ describe "gitlab::install" do
expect(chef_run).to create_template('/home/git/gitlab/config/unicorn.rb').with(
source: 'unicorn.rb.erb',
variables: {
app_root: "/home/git/gitlab",
unicorn_workers_number: 2,
unicorn_timeout: 30
}
......@@ -278,6 +279,17 @@ describe "gitlab::install" do
describe "creating gitlab init" do
describe "for production" do
it 'creates gitlab default configuration file' do
expect(chef_run).to create_template('/etc/default/gitlab').with(
source: 'gitlab.default.erb',
mode: 0755,
variables: {
app_user: 'git',
app_root: '/home/git/gitlab'
}
)
end
# TODO Write the test that will check if notification is triggered within the ruby_block
it 'triggers service defaults update' do
expect(chef_run).to run_ruby_block('Copy from example gitlab init config')
......@@ -301,6 +313,105 @@ describe "gitlab::install" do
end
end
end
describe "when customizing gitlab user home" do
# Only test stuff that change when git user home is different
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::start","gitlab::install")
end
it 'creates a gitlab config' do
expect(chef_run).to create_template('/data/git/gitlab/config/database.yml')
end
it 'updates git config' do
resource = chef_run.find_resource(:bash, 'git config')
expect(resource.environment).to eq('HOME' =>"/data/git")
end
it 'creates required directories in the rails root' do
%w{log tmp tmp/pids tmp/sockets public/uploads}.each do |path|
expect(chef_run).to create_directory("/data/git/gitlab/#{path}").with(
user: 'git',
group: 'git',
mode: 0755
)
end
end
it 'creates satellites directory' do
expect(chef_run).to create_directory("/data/git/gitlab-satellites")
end
it 'creates a unicorn config' do
expect(chef_run).to create_template('/data/git/gitlab/config/unicorn.rb')
end
describe "when using mysql" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['database_adapter'] = "mysql"
runner.node.set['gitlab']['database_password'] = "datapass"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::start","gitlab::install")
end
it 'creates a database config' do
expect(chef_run).to create_template('/data/git/gitlab/config/database.yml')
end
end
describe "when using postgresql" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['database_adapter'] = "postgresql"
runner.node.set['gitlab']['database_password'] = "datapass"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::start","gitlab::install")
end
it 'creates a database config' do
expect(chef_run).to create_template('/data/git/gitlab/config/database.yml')
end
end
describe "running database setup, migrations and seed when production" do
it 'runs db setup' do
resource = chef_run.find_resource(:execute, 'rake db:schema:load')
expect(resource.cwd).to eq("/data/git/gitlab")
end
it 'runs db migrate' do
resource = chef_run.find_resource(:execute, 'rake db:migrate')
expect(resource.cwd).to eq("/data/git/gitlab")
end
it 'runs db seed' do
resource = chef_run.find_resource(:execute, 'rake db:seed_fu')
expect(resource.cwd).to eq("/data/git/gitlab")
end
end
describe "creating gitlab init" do
describe "for production" do
it 'creates gitlab default configuration file' do
expect(chef_run).to create_template('/etc/default/gitlab').with(
source: 'gitlab.default.erb',
mode: 0755,
variables: {
app_user: 'git',
app_root: '/data/git/gitlab'
}
)
end
end
end
end
end
end
......@@ -394,6 +505,7 @@ describe "gitlab::install" do
expect(chef_run).to create_template('/home/git/gitlab/config/unicorn.rb').with(
source: 'unicorn.rb.erb',
variables: {
app_root: "/home/git/gitlab",
unicorn_workers_number: 2,
unicorn_timeout: 30
}
......@@ -582,6 +694,17 @@ describe "gitlab::install" do
describe "creating gitlab init" do
describe "for production" do
it 'creates gitlab default configuration file' do
expect(chef_run).to create_template('/etc/default/gitlab').with(
source: 'gitlab.default.erb',
mode: 0755,
variables: {
app_user: 'git',
app_root: '/home/git/gitlab'
}
)
end
# TODO Write the test that will check if notification is triggered within the ruby_block
it 'triggers service defaults update' do
expect(chef_run).to run_ruby_block('Copy from example gitlab init config')
......@@ -605,6 +728,105 @@ describe "gitlab::install" do
end
end
end
describe "when customizing gitlab user home" do
# Only test stuff that change when git user home is different
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::start","gitlab::install")
end
it 'creates a gitlab config' do
expect(chef_run).to create_template('/data/git/gitlab/config/database.yml')
end
it 'updates git config' do
resource = chef_run.find_resource(:bash, 'git config')
expect(resource.environment).to eq('HOME' =>"/data/git")
end
it 'creates required directories in the rails root' do
%w{log tmp tmp/pids tmp/sockets public/uploads}.each do |path|
expect(chef_run).to create_directory("/data/git/gitlab/#{path}").with(
user: 'git',
group: 'git',
mode: 0755
)
end
end
it 'creates satellites directory' do
expect(chef_run).to create_directory("/data/git/gitlab-satellites")
end
it 'creates a unicorn config' do
expect(chef_run).to create_template('/data/git/gitlab/config/unicorn.rb')
end
describe "when using mysql" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['database_adapter'] = "mysql"
runner.node.set['gitlab']['database_password'] = "datapass"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::start","gitlab::install")
end
it 'creates a database config' do
expect(chef_run).to create_template('/data/git/gitlab/config/database.yml')
end
end
describe "when using postgresql" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['database_adapter'] = "postgresql"
runner.node.set['gitlab']['database_password'] = "datapass"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::start","gitlab::install")
end
it 'creates a database config' do
expect(chef_run).to create_template('/data/git/gitlab/config/database.yml')
end
end
describe "running database setup, migrations and seed when production" do
it 'runs db setup' do
resource = chef_run.find_resource(:execute, 'rake db:schema:load')
expect(resource.cwd).to eq("/data/git/gitlab")
end
it 'runs db migrate' do
resource = chef_run.find_resource(:execute, 'rake db:migrate')
expect(resource.cwd).to eq("/data/git/gitlab")
end
it 'runs db seed' do
resource = chef_run.find_resource(:execute, 'rake db:seed_fu')
expect(resource.cwd).to eq("/data/git/gitlab")
end
end
describe "creating gitlab init" do
describe "for production" do
it 'creates gitlab default configuration file' do
expect(chef_run).to create_template('/etc/default/gitlab').with(
source: 'gitlab.default.erb',
mode: 0755,
variables: {
app_user: 'git',
app_root: '/data/git/gitlab'
}
)
end
end
end
end
end
end
end
......@@ -6,7 +6,7 @@ describe "gitlab::nginx" do