<commit_before>#
# Cookbook Name:: gitlab
# Recipe:: install
#

gitlab = node['gitlab']

### Copy the example GitLab config
template File.join(gitlab['path'], 'config', 'gitlab.yml') do
  source "gitlab.yml.erb"
  user gitlab['user']
  group gitlab['group']
  variables({
    :host => gitlab['host'],
    :port => gitlab['port'],
    :user => gitlab['user'],
    :email_from => gitlab['email_from'],
    :support_email => gitlab['support_email'],
    :satellites_path => gitlab['satellites_path'],
    :repos_path => gitlab['repos_path'],
    :shell_path => gitlab['shell_path'],
    :signup_enabled => gitlab['signup_enabled'],
    :projects_limit => gitlab['projects_limit'],
    :oauth_enabled => gitlab['oauth_enabled'],
    :oauth_block_auto_created_users => gitlab['oauth_block_auto_created_users'],
    :oauth_allow_single_sign_on => gitlab['oauth_allow_single_sign_on'],
    :oauth_providers => gitlab['oauth_providers'],
    :google_analytics_id => gitlab['extra']['google_analytics_id'],
    :sign_in_text => gitlab['extra']['sign_in_text'],
    :default_projects_features => gitlab['default_projects_features'],
    :gravatar => gitlab['gravatar'],
    :ldap_config => gitlab['ldap'],
    :ssh_port => gitlab['ssh_port'],
  })
  notifies :run, "bash[git config]", :immediately
  notifies :reload, "service[gitlab]"
end

### Make sure GitLab can write to the log/ and tmp/ directories
### Create directories for sockets/pids
### Create public/uploads directory otherwise backup will fail
%w{log tmp tmp/pids tmp/sockets public/uploads}.each do |path|
  directory File.join(gitlab['path'], path) do
    owner gitlab['user']
    group gitlab['group']
    mode 0755
    not_if { File.exist?(File.join(gitlab['path'], path)) }
  end
end

### Create directory for satellites
directory gitlab['satellites_path'] do
  owner gitlab['user']
  group gitlab['group']
  not_if { File.exist?(gitlab['satellites_path']) }
end

### Unicorn config
template File.join(gitlab['path'], 'config', 'unicorn.rb') do
  source "unicorn.rb.erb"
  user gitlab['user']
  group gitlab['group']
  variables({
    :unicorn_workers_number => gitlab['unicorn_workers_number'],
    :unicorn_timeout => gitlab['unicorn_timeout']
  })
  notifies :reload, "service[gitlab]"
end

### Enable Rack attack
# Creating the file this way for the following reasons
# 1. Chef 11.4.0 must be used to keep support for AWS OpsWorks
# 2. Using file resource is not an option because it is ran at compilation time<commit_msg>Update satellites permission.<commit_after>#
# Cookbook Name:: gitlab
# Recipe:: install
#

gitlab = node['gitlab']

### Copy the example GitLab config
template File.join(gitlab['path'], 'config', 'gitlab.yml') do
  source "gitlab.yml.erb"
  user gitlab['user']
  group gitlab['group']
  variables({
    :host => gitlab['host'],
    :port => gitlab['port'],
    :user => gitlab['user'],
    :email_from => gitlab['email_from'],
    :support_email => gitlab['support_email'],
    :satellites_path => gitlab['satellites_path'],
    :repos_path => gitlab['repos_path'],
    :shell_path => gitlab['shell_path'],
    :signup_enabled => gitlab['signup_enabled'],
    :projects_limit => gitlab['projects_limit'],
    :oauth_enabled => gitlab['oauth_enabled'],
    :oauth_block_auto_created_users => gitlab['oauth_block_auto_created_users'],
    :oauth_allow_single_sign_on => gitlab['oauth_allow_single_sign_on'],
    :oauth_providers => gitlab['oauth_providers'],
    :google_analytics_id => gitlab['extra']['google_analytics_id'],
    :sign_in_text => gitlab['extra']['sign_in_text'],
    :default_projects_features => gitlab['default_projects_features'],
    :gravatar => gitlab['gravatar'],
    :ldap_config => gitlab['ldap'],
    :ssh_port => gitlab['ssh_port'],
  })
  notifies :run, "bash[git config]", :immediately
  notifies :reload, "service[gitlab]"
end

### Make sure GitLab can write to the log/ and tmp/ directories
### Create directories for sockets/pids
### Create public/uploads directory otherwise backup will fail
%w{log tmp tmp/pids tmp/sockets public/uploads}.each do |path|
  directory File.join(gitlab['path'], path) do
    owner gitlab['user']
    group gitlab['group']
    mode 0755
    not_if { File.exist?(File.join(gitlab['path'], path)) }
  end
end

### Create directory for satellites
directory gitlab['satellites_path'] do
  owner gitlab['user']
  group gitlab['group']
  mode 0750
  not_if { File.exist?(gitlab['satellites_path']) }
end

### Unicorn config
template File.join(gitlab['path'], 'config', 'unicorn.rb') do
  source "unicorn.rb.erb"
  user gitlab['user']
  group gitlab['group']
  variables({
    :unicorn_workers_number => gitlab['unicorn_workers_number'],
    :unicorn_timeout => gitlab['unicorn_timeout']
  })
  notifies :reload, "service[gitlab]"
end

### Enable Rack attack
# Creating the file this way for the following reasons
# 1. Chef 11.4.0 must be used to keep support for AWS OpsWorks
# 2. Using file resource is not an option because it is ran at compilation time
{'fraction_non_alphanumeric': 0.14905962384953983, 'fraction_numerical': 0.004801920768307323, 'mean_word_length': 5.126225490196078, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1311285', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1621, 'n_words': 389}