Skip to content
Snippets Groups Projects
Commit 2f313ca6 authored by Marin Jankovski's avatar Marin Jankovski
Browse files

Add gitlab cookbook

parent fc00e952
No related branches found
No related tags found
No related merge requests found
Showing
with 1189 additions and 0 deletions
site :opscode
metadata
{
"sources": {
"gitlab": {
"path": "."
},
"redisio": {
"locked_version": "1.7.0"
},
"ulimit": {
"locked_version": "0.3.1"
},
"ruby_build": {
"locked_version": "0.8.0"
},
"postgresql": {
"locked_version": "3.1.0"
},
"apt": {
"locked_version": "2.2.1"
},
"build-essential": {
"locked_version": "1.4.2"
},
"openssl": {
"locked_version": "1.1.0"
},
"mysql": {
"locked_version": "3.0.12"
},
"database": {
"locked_version": "1.5.2"
},
"aws": {
"locked_version": "0.101.6"
},
"xfs": {
"locked_version": "1.1.0"
},
"postfix": {
"locked_version": "3.0.2"
},
"yum": {
"locked_version": "2.4.0"
},
"phantomjs": {
"locked_version": "1.0.3"
},
"chocolatey": {
"locked_version": "0.0.5"
},
"powershell": {
"locked_version": "1.1.2"
},
"windows": {
"locked_version": "1.11.0"
},
"chef_handler": {
"locked_version": "1.1.4"
}
}
}
source 'https://rubygems.org'
gem 'berkshelf', "2.0.10"
gem 'foodcritic'
gem 'chefspec', "3.0.1"
GEM
remote: https://rubygems.org/
specs:
activesupport (3.2.15)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
addressable (2.3.5)
akami (1.2.0)
gyoku (>= 0.4.0)
nokogiri (>= 1.4.0)
berkshelf (2.0.10)
activesupport (~> 3.2.0)
addressable (~> 2.3.4)
buff-shell_out (~> 0.1)
chozo (>= 0.6.1)
faraday (>= 0.8.5)
hashie (>= 2.0.2)
minitar (~> 0.5.4)
rbzip2 (~> 0.2.0)
retryable (~> 1.3.3)
ridley (~> 1.5.0)
solve (>= 0.5.0)
thor (~> 0.18.0)
buff-config (0.4.0)
buff-extensions (~> 0.3)
varia_model (~> 0.1)
buff-extensions (0.5.0)
buff-ignore (1.1.0)
buff-ruby_engine (0.1.0)
buff-shell_out (0.1.1)
buff-ruby_engine (~> 0.1.0)
builder (3.2.2)
celluloid (0.14.1)
timers (>= 1.0.0)
celluloid-io (0.14.1)
celluloid (>= 0.14.1)
nio4r (>= 0.4.5)
chef (11.6.2)
erubis (~> 2.7)
highline (~> 1.6, >= 1.6.9)
json (>= 1.4.4, <= 1.7.7)
mixlib-authentication (~> 1.3)
mixlib-cli (~> 1.3)
mixlib-config (~> 1.1, >= 1.1.2)
mixlib-log (~> 1.3)
mixlib-shellout (~> 1.1)
net-ssh (~> 2.6)
net-ssh-multi (~> 1.1.0)
ohai (>= 0.6.0, < 7.0.0)
rest-client (>= 1.0.4, < 1.7.0)
yajl-ruby (~> 1.1)
chefspec (3.0.1)
chef (~> 11.0)
fauxhai (~> 1.1)
rspec (~> 2.14)
chozo (0.6.1)
activesupport (>= 3.2.0)
hashie (>= 2.0.2)
multi_json (>= 1.3.0)
diff-lcs (1.2.4)
erubis (2.7.0)
faraday (0.8.8)
multipart-post (~> 1.2.0)
fauxhai (1.1.1)
httparty
net-ssh
ohai
ffi (1.9.0)
foodcritic (0.2.0)
gssapi (1.0.3)
ffi (>= 1.0.1)
gyoku (1.1.0)
builder (>= 2.1.2)
hashie (2.0.5)
highline (1.6.20)
httparty (0.11.0)
multi_json (~> 1.0)
multi_xml (>= 0.5.2)
httpclient (2.3.4.1)
httpi (0.9.7)
rack
i18n (0.6.5)
ipaddress (0.8.0)
json (1.7.7)
little-plugger (1.1.3)
logging (1.8.1)
little-plugger (>= 1.1.3)
multi_json (>= 1.3.6)
mime-types (2.0)
mini_portile (0.5.2)
minitar (0.5.4)
mixlib-authentication (1.3.0)
mixlib-log
mixlib-cli (1.3.0)
mixlib-config (1.1.2)
mixlib-log (1.6.0)
mixlib-shellout (1.2.0)
multi_json (1.8.2)
multi_xml (0.5.5)
multipart-post (1.2.0)
net-http-persistent (2.9)
net-ssh (2.7.0)
net-ssh-gateway (1.2.0)
net-ssh (>= 2.6.5)
net-ssh-multi (1.1)
net-ssh (>= 2.1.4)
net-ssh-gateway (>= 0.99.0)
nio4r (0.5.0)
nokogiri (1.6.0)
mini_portile (~> 0.5.0)
nori (1.1.5)
ohai (6.18.0)
ipaddress
mixlib-cli
mixlib-config
mixlib-log
mixlib-shellout
systemu
yajl-ruby
rack (1.5.2)
rbzip2 (0.2.0)
rest-client (1.6.7)
mime-types (>= 1.16)
retryable (1.3.3)
ridley (1.5.3)
addressable
buff-config (~> 0.2)
buff-extensions (~> 0.3)
buff-ignore (~> 1.1)
buff-shell_out (~> 0.1)
celluloid (~> 0.14.0)
celluloid-io (~> 0.14.0)
erubis
faraday (>= 0.8.4)
hashie (>= 2.0.2)
json (>= 1.7.7)
mixlib-authentication (>= 1.3.0)
net-http-persistent (>= 2.8)
net-ssh
nio4r (>= 0.5.0)
retryable
solve (>= 0.4.4)
varia_model (~> 0.1)
winrm (~> 1.1.0)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.6)
rspec-expectations (2.14.3)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.4)
rubyntlm (0.1.1)
savon (0.9.5)
akami (~> 1.0)
builder (>= 2.1.2)
gyoku (>= 0.4.0)
httpi (~> 0.9)
nokogiri (>= 1.4.0)
nori (~> 1.0)
wasabi (~> 1.0)
solve (0.8.1)
systemu (2.5.2)
thor (0.18.1)
timers (1.1.0)
uuidtools (2.1.4)
varia_model (0.2.0)
buff-extensions (~> 0.2)
hashie (>= 2.0.2)
wasabi (1.0.0)
nokogiri (>= 1.4.0)
winrm (1.1.3)
gssapi (~> 1.0.0)
httpclient (~> 2.2, >= 2.2.0.2)
logging (~> 1.6, >= 1.6.1)
nokogiri (~> 1.5)
rubyntlm (~> 0.1.1)
savon (= 0.9.5)
uuidtools (~> 2.1.2)
yajl-ruby (1.1.0)
PLATFORMS
ruby
DEPENDENCIES
berkshelf (= 2.0.10)
chefspec (= 3.0.1)
foodcritic
GitLab Cookbook
===============
Chef cookbook with recipes to install GitLab.
* GitLab: 6.2.0
* GitLab Shell: 1.7.1
* Ruby: 2.0.0
* Redis: 2.6.13
* Git: 1.7.12
* Nginx: 1.1.19
* PostgreSQL: 9.1.9
* MySQL: 5.5.31
## Requirements
* [Berkshelf](http://berkshelf.com/)
* [Vagrant](http://www.vagrantup.com/)
### Vagrant Plugin
* [vagrant-berkshelf](https://github.com/RiotGames/vagrant-berkshelf)
* [vagrant-omnibus](https://github.com/schisamo/vagrant-omnibus)
* [vagrant-aws](https://github.com/mitchellh/vagrant-aws)
### Platform:
* Ubuntu (12.04, 12.10)
* CentOS (6.4)
## Attributes
* Package
* User
* GitLab shell
* GitLab shell config
* GitLab hq
* GitLab hq config
* Gems
* Git
## Installation
### Vagrant
#### VirtualBox
```bash
$ gem install berkshelf
$ vagrant plugin install vagrant-berkshelf
$ vagrant plugin install vagrant-omnibus
$ git clone git://github.com/ogom/cookbook-gitlab ./gitlab
$ cd ./gitlab/
$ vagrant up
```
#### Amazon Web Services
Create instance.
```bash
$ gem install berkshelf
$ vagrant plugin install vagrant-berkshelf
$ vagrant plugin install vagrant-omnibus
$ vagrant plugin install vagrant-aws
$ vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box
$ git clone git://github.com/ogom/cookbook-gitlab ./gitlab
$ cd ./gitlab/
$ cp ./example/Vagrantfile_aws ./Vagrantfile
$ vagrant up --provider=aws
```
HostName setting.
```bash
$ vagrant ssh-config | awk '/HostName/ {print $2}'
$ editor ./Vagrantfile
$ vagrant provision
```
### knife-solo
```bash
$ gem install berkshelf
$ gem install knife-solo
$ knife configure
$ knife solo init ./chef-repo
$ cd ./chef-repo/
$ echo 'cookbook "gitlab", github: "ogom/cookbook-gitlab"' >> ./Berksfile
$ berks install --path ./cookbooks
$ knife solo prepare vagrant@127.0.0.1 -p 2222 -i ~/.vagrant.d/insecure_private_key
$ editor ./nodes/127.0.0.1.json
$ knife solo cook vagrant@127.0.0.1 -p 2222 -i ~/.vagrant.d/insecure_private_key --no-chef-check
```
## Usage
Example of node config.
```json
{
"postfix": {
"mail_type": "client",
"myhostname": "mail.example.com",
"mydomain": "example.com",
"myorigin": "mail.example.com",
"smtp_use_tls": "no"
},
"postgresql": {
"password": {
"postgres": "psqlpass"
}
},
"mysql": {
"server_root_password": "rootpass",
"server_repl_password": "replpass",
"server_debian_password": "debianpass"
},
"gitlab": {
"host": "example.com",
"url": "http://example.com/",
"email_from": "gitlab@example.com",
"support_email": "support@example.com",
"database_adapter": "postgresql",
"database_password": "datapass"
},
"run_list":[
"postfix",
"gitlab::initial",
"gitlab::install"
]
}
```
### Database use mysql.
Set `mysql` to `database_adapter`.
```json
{
...
"gitlab": {
"database_adapter": "mysql"
}
}
```
### GitLab Update
Add `gitlab::update` to `run_list`.
```json
{
...
"run_list":[
"gitlab::update",
"gitlab::initial",
"gitlab::install"
]
}
```
## Done!
`http://localhost:8080/` or your server for your first GitLab login.
```
admin@local.host
5iveL!fe
```
## Testing the cookbook
First install the necessary gems
```bash
bundle install
```
To check for syntax errors run foodcritic:
```bash
foodcritic .
```
assuming that you are inside cookbook-gitlab directory.
Run tests with:
```bash
bundle exec rspec
```
## Acknowledgement
This cookbook was based on work by [ogom](https://github.com/ogom/cookbook-gitlab). Thank you ogom!
## Links
* [GitLab Installation](https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md)
* [Qiita Document](http://qiita.com/items/6491a268bfc95d0a5be4)
## License
* MIT
# encoding: utf-8
require 'bundler'
require 'bundler/setup'
require 'berkshelf/thor'
begin
require 'kitchen/thor_tasks'
Kitchen::ThorTasks.new
rescue LoadError
puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI']
end
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
config.vm.hostname = "gitlab-berkshelf"
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "opscode-ubuntu-12.04"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box"
# Assign this VM to a host-only network IP, allowing you to access it
# via the IP. Host-only networks can talk to the host machine as well as
# any other machines on the same network, but cannot be accessed (through this
# network interface) by any external networks.
config.vm.network :private_network, ip: "33.33.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network :public_network
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network :forwarded_port, guest: 3000, host: 3000
config.vm.network :forwarded_port, guest: 80, host: 8080
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
config.vm.provider :virtualbox do |vb|
# Use VBoxManage to customize the VM. For example to change memory:
vb.customize ["modifyvm", :id, "--memory", "1024"]
end
# View the documentation for the provider you're using for more
# information on available options.
# Install the version of Chef by the Vagrant Omnibus
# version is :latest or "11.4.0"
config.omnibus.chef_version = :latest
# The path to the Berksfile to use with Vagrant Berkshelf
# config.berkshelf.berksfile_path = "./Berksfile"
# Enabling the Berkshelf plugin. To enable this globally, add this configuration
# option to your ~/.vagrant.d/Vagrantfile file
config.berkshelf.enabled = true
# An array of symbols representing groups of cookbook described in the Vagrantfile
# to exclusively install and copy to Vagrant's shelf.
# config.berkshelf.only = []
# An array of symbols representing groups of cookbook described in the Vagrantfile
# to skip installing and copying to Vagrant's shelf.
# config.berkshelf.except = []
config.vm.provision :chef_solo do |chef|
chef.json = {
:postfix => {
:mail_type => "client",
:myhostname => "mail.localhost",
:mydomain => "localhost",
:myorigin => "mail.localhost",
:smtp_use_tls => "no"
},
:postgresql => {
:password => {
:postgres => "psqlpass"
}
},
:mysql => {
:server_root_password => "rootpass",
:server_repl_password => "replpass",
:server_debian_password => "debianpass"
},
:gitlab => {
:database_adapter => "mysql",
:database_password => "datapass",
:env => "production"
}
}
chef.run_list = [
"apt",
"postfix",
"gitlab::install"
]
# In case chef-solo run is failing silently
# uncomment the line below to enable debug log level.
# chef.arguments = '-l debug'
end
end
# Package
if platform_family?("rhel")
packages = %w{
libicu-devel
}
else
packages = %w{
build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev
curl openssh-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev python-docutils
logrotate
}
end
default['gitlab']['packages'] = packages
default['gitlab']['ruby'] = "2.0.0-p247"
# GitLab shell
default['gitlab']['shell_repository'] = "https://github.com/gitlabhq/gitlab-shell.git"
default['gitlab']['shell_revision'] = "v1.7.1"
# GitLab hq
default['gitlab']['repository'] = "https://github.com/gitlabhq/gitlabhq.git"
# GitLab shell config
default['gitlab']['url'] = "http://localhost:8080/"
default['gitlab']['redis_path'] = "/usr/local/bin/redis-cli"
default['gitlab']['redis_host'] = "127.0.0.1"
default['gitlab']['redis_port'] = "6379"
default['gitlab']['namespace'] = "resque:gitlab"
# GitLab hq config
default['gitlab']['git_path'] = "/usr/local/bin/git"
default['gitlab']['host'] = "localhost"
default['gitlab']['port'] = "80"
default['gitlab']['email_from'] = "gitlab@localhost"
default['gitlab']['support_email'] = "support@localhost"
# Gems
default['gitlab']['bundle_install'] = "bundle install --path=.bundle --deployment"
# User
default['gitlab']['development']['user'] = "vagrant"
default['gitlab']['development']['group'] = "vagrant"
default['gitlab']['development']['home'] = "/home/vagrant"
# GitLab shell
default['gitlab']['development']['shell_path'] = "/vagrant/gitlab-shell"
# GitLab hq
default['gitlab']['development']['revision'] = "master"
default['gitlab']['development']['path'] = "/vagrant/gitlab"
# GitLab shell config
default['gitlab']['development']['repos_path'] = "/vagrant/repositories"
# GitLab hq config
default['gitlab']['development']['satellites_path'] = "/vagrant/gitlab-satellites"
# Setup environments
default['gitlab']['development']['environments'] = %w{development test}
# Git
default['gitlab']['git']['prefix'] = "/usr/local"
default['gitlab']['git']['version'] = "1.7.12.4"
default['gitlab']['git']['url'] = "https://github.com/git/git/archive/v#{node['gitlab']['git']['version']}.zip"
if platform_family?("rhel")
packages = %w{expat-devel gettext-devel libcurl-devel openssl-devel perl-ExtUtils-MakeMaker zlib-devel}
else
packages = %w{unzip build-essential libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev}
end
default['gitlab']['git']['packages'] = packages
# User
default['gitlab']['production']['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']['production']['group'] = "git"
default['gitlab']['production']['home'] = "/home/git"
# GitLab shell
default['gitlab']['production']['shell_path'] = "/home/git/gitlab-shell"
# GitLab hq
default['gitlab']['production']['revision'] = "6-2-stable"
default['gitlab']['production']['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.
# GitLab shell config
default['gitlab']['production']['repos_path'] = "/home/git/repositories"
# GitLab hq config
default['gitlab']['production']['satellites_path'] = "/home/git/gitlab-satellites"
# Setup environments
default['gitlab']['production']['environments'] = %w{production}
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "dummy"
config.vm.provider :aws do |aws, override|
aws.access_key_id = "YOUR_ACCESS_KEY"
aws.secret_access_key = "YOUR_SECRET_KEY"
aws.keypair_name = "vagrant_aws"
aws.ami = "ami-d0f89fb9"
aws.security_groups = ["vagrant"]
aws.tags = {'Name' => 'GitLab'}
# default is "m1.small".
# aws.instance_type = "t1.micro"
override.ssh.username = "ubuntu"
override.ssh.private_key_path = "~/.ssh/vagrant_aws.pem"
end
config.omnibus.chef_version = :latest
config.berkshelf.enabled = true
config.vm.provision :chef_solo do |chef|
chef.json = {
:postfix => {
:mail_type => "client",
:myhostname => "mail.example.com",
:mydomain => "example.com",
:myorigin => "mail.example.com",
:smtp_use_tls => "no"
},
:postgresql => {
:password => {
:postgres => "psqlpass"
}
},
:mysql => {
:server_root_password => "rootpass",
:server_repl_password => "replpass",
:server_debian_password => "debianpass"
},
:gitlab => {
:host => "example.com",
:url => "http://example.com/",
:email_from => "gitlab@example.com",
:support_email => "support@example.com",
:database_adapter => "postgresql",
:database_password => "datapass"
}
}
chef.run_list = []
end
end
name 'gitlab'
maintainer 'Marin Jankovski'
maintainer_email 'marin@gitlab.com'
license 'MIT'
description 'Installs/Configures GitLab'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.6.2'
recipe "gitlab::initial", "Setting the initial"
recipe "gitlab::install", "Installation"
%w{redisio ruby_build postgresql mysql database postfix yum phantomjs}.each do |dep|
depends dep
end
%w{debian ubuntu centos}.each do |os|
supports os
end
#
# Cookbook Name:: gitlab
# Recipe:: database_mysql
#
mysql = node['mysql']
gitlab = node['gitlab']
# Merge environmental variables
gitlab = Chef::Mixin::DeepMerge.merge(gitlab,gitlab[gitlab['env']])
# 5.Database
include_recipe "mysql::server"
include_recipe "database::mysql"
mysql_connection = {
:host => 'localhost',
:username => 'root',
:password => mysql['server_root_password']
}
## Create a user for GitLab.
mysql_database_user gitlab['user'] do
connection mysql_connection
password gitlab['database_password']
action :create
end
## Create the GitLab database & grant all privileges on database
gitlab['environments'].each do |environment|
mysql_database "gitlabhq_#{environment}" do
connection mysql_connection
action :create
end
mysql_database_user gitlab['user'] do
connection mysql_connection
password gitlab['database_password']
database_name "gitlabhq_#{environment}"
host 'localhost'
privileges ["SELECT", "UPDATE", "INSERT", "DELETE", "CREATE", "DROP", "INDEX", "ALTER", "LOCK TABLES"]
action :grant
end
end
#
# Cookbook Name:: gitlab
# Recipe:: database_postgresql
#
postgresql = node['postgresql']
gitlab = node['gitlab']
# Merge environmental variables
gitlab = Chef::Mixin::DeepMerge.merge(gitlab,gitlab[gitlab['env']])
# 5.Database
include_recipe "postgresql::server"
include_recipe "database::postgresql"
postgresql_connexion = {
:host => 'localhost',
:username => 'postgres',
:password => postgresql['password']['postgres']
}
## Create a user for GitLab.
postgresql_database_user gitlab['user'] do
connection postgresql_connexion
password gitlab['database_password']
action :create
end
## Create the GitLab database & grant all privileges on database
gitlab['environments'].each do |environment|
postgresql_database "gitlabhq_#{environment}" do
connection postgresql_connexion
action :create
end
postgresql_database_user gitlab['user'] do
connection postgresql_connexion
database_name "gitlabhq_#{environment}"
password gitlab['database_password']
action :grant
end
end
#
# Cookbook Name:: gitlab
# Recipe:: gems
#
gitlab = node['gitlab']
# Merge environmental variables
gitlab = Chef::Mixin::DeepMerge.merge(gitlab,gitlab[gitlab['env']])
## Install Gems
gem_package "charlock_holmes" do
version "0.6.9.4"
options "--no-ri --no-rdoc"
end
template File.join(gitlab['home'], ".gemrc") do
source "gemrc.erb"
user gitlab['user']
group gitlab['group']
notifies :run, "execute[bundle install]", :immediately
end
### without
bundle_without = []
case gitlab['database_adapter']
when 'mysql'
bundle_without << 'postgres'
bundle_without << 'aws'
when 'postgresql'
bundle_without << 'mysql'
bundle_without << 'aws'
end
case gitlab['env']
when 'production'
bundle_without << 'development'
bundle_without << 'test'
else
bundle_without << 'production'
end
execute "bundle install" do
command <<-EOS
PATH="/usr/local/bin:$PATH"
#{gitlab['bundle_install']} --without #{bundle_without.join(" ")}
EOS
cwd gitlab['path']
user gitlab['user']
group gitlab['group']
action :nothing
end
#
# Cookbook Name:: gitlab
# Recipe:: git
#
git = node['gitlab']['git']
git['packages'].each do |pkg|
package pkg
end
remote_file "#{Chef::Config['file_cache_path']}/git-#{git['version']}.zip" do
source git['url']
mode 0644
not_if "test -f #{Chef::Config['file_cache_path']}/git-#{git['version']}.zip"
end
execute "Extracting and Building Git #{git['version']} from Source" do
command <<-EOS
unzip -q git-#{git['version']}.zip
cd git-#{git['version']} && make prefix=#{git['prefix']} install
EOS
cwd Chef::Config['file_cache_path']
creates "#{git['prefix']}/bin/git"
not_if "git --version | grep #{git['version']}"
end
#
# Cookbook Name:: gitlab
# Recipe:: gitlab
#
gitlab = node['gitlab']
# Merge environmental variables
gitlab = Chef::Mixin::DeepMerge.merge(gitlab,gitlab[gitlab['env']])
### 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']
})
notifies :run, "bash[git config]", :immediately
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
end
end
### Create directory for satellites
directory gitlab['satellites_path'] do
owner gitlab['user']
group gitlab['group']
end
### Copy the example Unicorn config
remote_file "unicorn.rb" do
path File.join(gitlab['path'], 'config', 'unicorn.rb')
source "file://#{File.join(gitlab['path'], 'config', 'unicorn.rb.example')}"
owner gitlab['user']
group gitlab['group']
end
### Enable Rack attack
remote_file "rack_attack.rb" do
path File.join(gitlab['path'], 'config', 'initializers', 'rack_attack.rb')
source "file://#{File.join(gitlab['path'], 'config', 'initializers', 'rack_attack.rb.example')}"
owner gitlab['user']
group gitlab['group']
mode 0644
notifies :run, "bash[Enable rack attack in application.rb]", :immediately
end
bash "Enable rack attack in application.rb" do
code <<-EOS
sed -i "/# config.middleware.use Rack::Attack/ s/# *//" "#{File.join(gitlab['path'], "config", "application.rb")}"
EOS
user gitlab['user']
group gitlab['group']
action :nothing
end
### Configure Git global settings for git user, useful when editing via web
bash "git config" do
code <<-EOS
git config --global user.name "GitLab"
git config --global user.email "gitlab@#{gitlab['host']}"
git config --global core.autocrlf input
EOS
user gitlab['user']
group gitlab['group']
environment('HOME' => gitlab['home'])
action :nothing
end
## Configure GitLab DB settings
template File.join(gitlab['path'], "config", "database.yml") do
source "database.yml.#{gitlab['database_adapter']}.erb"
user gitlab['user']
group gitlab['group']
variables({
:user => gitlab['user'],
:password => gitlab['database_password']
})
end
### db:setup
gitlab['environments'].each do |environment|
### db:setup
file_setup = File.join(gitlab['home'], ".gitlab_setup_#{environment}")
file_setup_old = File.join(gitlab['home'], ".gitlab_setup")
execute "rake db:setup" do
command <<-EOS
PATH="/usr/local/bin:$PATH"
bundle exec rake db:setup RAILS_ENV=#{environment}
EOS
cwd gitlab['path']
user gitlab['user']
group gitlab['group']
not_if {File.exists?(file_setup) || File.exists?(file_setup_old)}
end
file file_setup do
owner gitlab['user']
group gitlab['group']
action :create
end
### db:migrate
file_migrate = File.join(gitlab['home'], ".gitlab_migrate_#{environment}")
file_migrate_old = File.join(gitlab['home'], ".gitlab_migrate")
execute "rake db:migrate" do
command <<-EOS
PATH="/usr/local/bin:$PATH"
bundle exec rake db:migrate RAILS_ENV=#{environment}
EOS
cwd gitlab['path']
user gitlab['user']
group gitlab['group']
not_if {File.exists?(file_migrate) || File.exists?(file_migrate_old)}
end
file file_migrate do
owner gitlab['user']
group gitlab['group']
action :create
end
### db:seed_fu
file_seed = File.join(gitlab['home'], ".gitlab_seed_#{environment}")
file_seed_old = File.join(gitlab['home'], ".gitlab_seed")
execute "rake db:seed_fu" do
command <<-EOS
PATH="/usr/local/bin:$PATH"
bundle exec rake db:seed_fu RAILS_ENV=#{environment}
EOS
cwd gitlab['path']
user gitlab['user']
group gitlab['group']
not_if {File.exists?(file_seed) || File.exists?(file_seed_old)}
end
file file_seed do
owner gitlab['user']
group gitlab['group']
action :create
end
end
case gitlab['env']
when 'production'
## Setup Init Script
remote_file "gitlab_init" do
path "/etc/init.d/gitlab"
source "file://#{File.join(gitlab['path'], "lib", "support", "init.d", "gitlab")}"
mode 0755
notifies :run, "execute[set gitlab to start on boot]", :immediately
end
# Updates defaults so gitlab can boot on start. As per man pages of update-rc.d runs only if links do not exist
execute "set gitlab to start on boot" do
command "update-rc.d gitlab defaults 21"
action :nothing
end
## Setup logrotate
remote_file "logrotate" do
path "/etc/logrotate.d/gitlab"
source "file://#{File.join(gitlab['path'], "lib", "support", "logrotate", "gitlab")}"
mode 0644
end
else
## For execute javascript test
include_recipe "phantomjs"
end
#
# Cookbook Name:: gitlab
# Recipe:: gitlab_shell
#
gitlab = node['gitlab']
# Merge environmental variables
gitlab = Chef::Mixin::DeepMerge.merge(gitlab,gitlab[gitlab['env']])
## Edit config and replace gitlab_url
template File.join(gitlab['shell_path'], "config.yml") do
source "gitlab_shell.yml.erb"
user gitlab['user']
group gitlab['group']
variables({
:user => gitlab['user'],
:home => gitlab['home'],
:url => gitlab['url'],
:repos_path => gitlab['repos_path'],
:redis_path => gitlab['redis_path'],
:redis_host => gitlab['redis_host'],
:redis_port => gitlab['redis_port'],
:namespace => gitlab['namespace']
})
notifies :run, "execute[gitlab-shell install]", :immediately
end
## Do setup
execute "gitlab-shell install" do
command <<-EOS
PATH="/usr/local/bin:$PATH"
./bin/install
EOS
cwd gitlab['shell_path']
user gitlab['user']
group gitlab['group']
action :nothing
notifies :create, "link[create symlink for gitlab-shell path for development]", :immediately
end
# Symlink gitlab-shell to vagrant home, so that sidekiq can use gitlab shell commands
link "create symlink for gitlab-shell path for development" do
target_file "#{gitlab['home']}/gitlab-shell"
to gitlab['shell_path']
not_if { gitlab['env'] == "production" }
end
#
# Cookbook Name:: gitlab
# Recipe:: initial
#
gitlab = node['gitlab']
# Merge environmental variables
gitlab = Chef::Mixin::DeepMerge.merge(gitlab,gitlab[gitlab['env']])
# 0. Initial Change
directory "/tmp" do
mode 0777
end
# 1. Packages / Dependencies
include_recipe "apt" if platform?("ubuntu", "debian")
include_recipe "yum::epel" if platform?("centos")
include_recipe "gitlab::git"
include_recipe "redisio::install"
include_recipe "redisio::enable"
## Install the required packages.
gitlab['packages'].each do |pkg|
package pkg
end
# 2. Ruby
include_recipe "ruby_build"
## Download and compile it:
ruby_build_ruby gitlab['ruby'] do
prefix_path "/usr/local/"
end
## Install the Bundler Gem:
gem_package "bundler" do
gem_binary "/usr/local/bin/gem"
options "--no-ri --no-rdoc"
end
include_recipe "gitlab::users"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment