Commit 75a6bdb7 authored by ogom's avatar ogom

release 0.1.0

parents
.vagrant
Berksfile.lock
*~
*#
.#*
\#*#
.*.sw[a-z]
*.un~
/cookbooks
# Bundler
Gemfile.lock
bin/*
.bundle/*
.kitchen/
.kitchen.local.yml
---
driver_plugin: vagrant
driver_config:
require_chef_omnibus: true
platforms:
- name: ubuntu-12.04
driver_config:
box: opscode-ubuntu-12.04
box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box
- name: ubuntu-10.04
driver_config:
box: opscode-ubuntu-10.04
box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-10.04_provisionerless.box
- name: centos-6.4
driver_config:
box: opscode-centos-6.4
box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box
- name: centos-5.9
driver_config:
box: opscode-centos-5.9
box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_centos-5.9_provisionerless.box
suites:
- name: default
run_list: []
attributes: {}
site :opscode
metadata
source 'https://rubygems.org'
gem 'berkshelf'
gem 'test-kitchen', :group => :integration
gem 'kitchen-vagrant', :group => :integration
GitLab Cookbook
===============
Chef to install The GitLab.
* GitLab: 5.2.1
* GitLab Shell: 1.5.0
* Ruby: 1.9
* Redis: 2.6
* Git: 1.7.12
## Requirements
* [Berkshelf](http://berkshelf.com/)
* [Vagrant](http://www.vagrantup.com/)
* [vagrant-berkshelf](https://github.com/RiotGames/vagrant-berkshelf)
### Platform:
* Ubuntu (12.04, 12.10)
## Attributes
* Package
* User
* GitLab shell
* GitLab shell config
* GitLab hq
* GitLab hq config
* Gems
* Git
## Installation
### Vagrant
```bash
$ gem install berkshelf
$ vagrant plugin install vagrant-berkshelf
$ git clone git://github.com/ogom/cookbook-gitlab ./gitlab
$ cd ./gitlab/
$ vi ./Vagrantfile
$ vagrant up
$ vagrant ssh
vagrant$ sudo apt-get install -y curl
vagrant$ curl -L https://www.opscode.com/chef/install.sh | sudo bash
vagrant$ exit
$ vagrant reload
```
### 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
$ vi ./nodes/127.0.0.1.json
$ knife solo cook vagrant@127.0.0.1 -p 2222 -i ~/.vagrant.d/insecure_private_key
```
## Usage
Example of node config.
```json
{
"postfix": {
"mail_type": "client",
"myhostname": "mail.example.info",
"mydomain": "example.info",
"myorigin": "mail.example.info",
"smtp_use_tls": "no"
},
"postgresql": {
"password": {
"postgres": "psqlpass"
}
},
"gitlab": {
"host": "gl.example.info",
"url": "http://gl.example.info/",
"email_from": "gitlab@example.info",
"support_email": "support@example.info",
"database_password": "datapass"
},
"run_list":[
"postfix",
"gitlab::initial",
"gitlab::install"
]
}
```
## Done!
`http://localhost:8080/` or your server for your first GitLab login.
```
admin@local.host
5iveL!fe
```
## Links
* [GitLab Installation](https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md)
* [Generating SSH Keys](https://help.github.com/articles/generating-ssh-keys)
## 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: 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.
config.ssh.max_tries = 40
config.ssh.timeout = 120
# 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"
}
},
:gitlab => {
:database_password => "datapass"
}
}
chef.run_list = [
"postfix",
"gitlab::initial",
"gitlab::install"
]
end
end
# Package
default['gitlab']['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
}
default['gitlab']['ruby'] = "1.9.3-p392"
# User
default['gitlab']['user'] = "git"
default['gitlab']['group'] = "git"
default['gitlab']['home'] = "/home/git"
# GitLab shell
default['gitlab']['shell_repository'] = "git://github.com/gitlabhq/gitlab-shell.git"
default['gitlab']['shell_revision'] = "v1.5.0"
default['gitlab']['shell_path'] = "/home/git/gitlab-shell"
# GitLab hq
default['gitlab']['repository'] = "git://github.com/gitlabhq/gitlabhq.git"
default['gitlab']['revision'] = "v5.2.1"
default['gitlab']['path'] = "/home/git/gitlab"
# GitLab shell config
default['gitlab']['url'] = "http://localhost/"
default['gitlab']['repos_path'] = "/home/git/repositories"
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']['satellites_path'] = "/home/git/gitlab-satellites"
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 --without development test mysql"
# 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"
default['gitlab']['git']['packages'] = %w{unzip libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev}
name 'gitlab'
maintainer 'ogom'
maintainer_email 'ogom@outlook.com'
license 'MIT'
description 'Installs/Configures GitLab'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.1.0'
recipe "gitlab::initial", "Setting the initial"
recipe "gitlab::install", "Installation"
%w{redisio ruby_build postgresql database postfix}.each do |dep|
depends dep
end
%w{debian ubuntu}.each do |os|
supports os
end
#
# Cookbook Name:: gitlab
# Recipe:: database
#
postgresql = node['postgresql']
gitlab = node['gitlab']
# 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 production database & grant all privileges on database
postgresql_database "gitlabhq_production" do
connection postgresql_connexion
action :create
end
postgresql_database_user gitlab['user'] do
connection postgresql_connexion
database_name "gitlabhq_production"
password gitlab['database_password']
action :grant
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 00644
not_if "test -f #{Chef::Config['file_cache_path']}/git-#{git['version']}.zip"
end
execute "Extracting and Building Git #{git['version']} from Source" do
cwd Chef::Config['file_cache_path']
command <<-EOS
unzip -q git-#{git['version']}.zip
cd git-#{git['version']} && make prefix=#{git['prefix']} install
EOS
creates "#{git['prefix']}/bin/git"
not_if "git --version | grep #{git['version']}"
end
#
# Cookbook Name:: gitlab
# Recipe:: gitlab
#
gitlab = node['gitlab']
# 6. GitLab
## Clone the Source
git gitlab['path'] do
repository gitlab['repository']
revision gitlab['revision']
user gitlab['user']
group gitlab['group']
action :sync
end
## Configure it
### 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']
})
end
### Make sure GitLab can write to the log/ and tmp/ directories
%w{log tmp}.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
### Create directories for sockets/pids and make sure GitLab can write to them
%w{tmp/pids tmp/sockets}.each do |path|
directory File.join(gitlab['path'], path) do
owner gitlab['user']
group gitlab['group']
mode 0755
end
end
### Create public/uploads directory otherwise backup will fail
%w{public/uploads}.each do |path|
directory File.join(gitlab['path'], path) do
owner gitlab['user']
group gitlab['group']
mode 0755
end
end
### Copy the example Puma config
template File.join(gitlab['path'], "config", "puma.rb") do
source "puma.rb.erb"
user gitlab['user']
group gitlab['group']
variables({
:path => gitlab['path']
})
end
### Configure Git global settings for git user, useful when editing via web
bash "git config" do
code 'git config --global user.name "GitLab" && git config --global user.email "gitlab@localhost"'
user gitlab['user']
group gitlab['group']
environment('HOME' => gitlab['home'])
end
## Configure GitLab DB settings
template File.join(gitlab['path'], "config", "database.yml") do
source "database.yml.erb"
user gitlab['user']
group gitlab['group']
variables({
:password => gitlab['database_password']
})
end
## 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
execute "bundle install" do
command "sudo -u #{gitlab['user']} -H #{gitlab['bundle_install']}"
cwd gitlab['path']
action :nothing
end
execute "rake db:setup" do
command "sudo -u #{gitlab['user']} -H bundle exec rake db:setup RAILS_ENV=production"
cwd gitlab['path']
not_if {File.exists?(File.join(gitlab['home'], ".gitlab_setup"))}
end
file File.join(gitlab['home'], ".gitlab_setup") do
owner gitlab['user']
group gitlab['group']
action :create
end
execute "rake db:seed_fu" do
command "sudo -u #{gitlab['user']} -H bundle exec rake db:seed_fu RAILS_ENV=production"
cwd gitlab['path']
user "root"
not_if {File.exists?(File.join(gitlab['home'], ".gitlab_seed"))}
end
file File.join(gitlab['home'], ".gitlab_seed") do
owner gitlab['user']
group gitlab['group']
action :create
end
# Install Init Script
template "/etc/init.d/gitlab" do
source "initd.erb"
mode 0755
variables({
:path => gitlab['path'],
:user => gitlab['user']
})
end
## Start Your GitLab Instance
service "gitlab" do
supports :start => true, :stop => true, :restart => true, :status => true
action :start
action << :enable
end
#
# Cookbook Name:: gitlab
# Recipe:: gitlab_shell
#
gitlab = node['gitlab']
# 4. GitLab shell
## Clone gitlab shell
git gitlab['shell_path'] do
repository gitlab['shell_repository']
revision gitlab['shell_revision']
user gitlab['user']
group gitlab['group']
action :sync
end
## 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']
notifies :run, "execute[gitlab-shell install]", :immediately
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']
})
end
## Do setup
execute "gitlab-shell install" do
command "./bin/install"
cwd gitlab['shell_path']
user gitlab['user']
group gitlab['group']
action :nothing
end
#
# Cookbook Name:: gitlab
# Recipe:: initial
#
gitlab = node['gitlab']
# 0. Initial Change
directory "/tmp" do
mode 0777
end
# 1. Packages / Dependencies
include_recipe "apt"
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
# 3. System Users
## Create user for Gitlab.
user gitlab['user'] do
comment "GitLab"
home gitlab['home']
shell "/bin/bash"
supports :manage_home => true
end
user gitlab['user'] do
action :lock
end
#
# Cookbook Name:: gitlab
# Recipe:: install
#
include_recipe "gitlab::gitlab_shell"
include_recipe "gitlab::database"
include_recipe "gitlab::gitlab"
include_recipe "gitlab::nginx"
#
# Cookbook Name:: gitlab
# Recipe:: nginx
#
gitlab = node['gitlab']
# 7. Nginx
## Installation
package "nginx" do
action :install
end
## Site Configuration
template "/etc/nginx/sites-available/gitlab" do
source "nginx.erb"
mode 0644
variables({
:path => gitlab['path'],
:host => gitlab['host'],
:port => gitlab['port']
})
end
link "/etc/nginx/sites-enabled/gitlab" do
to "/etc/nginx/sites-available/gitlab"
end
file "/etc/nginx/sites-enabled/default" do
action :delete
end
## Restart
service "nginx" do
action :restart
end
#
# PRODUCTION
#
production:
adapter: postgresql
encoding: unicode
database: gitlabhq_production
pool: 5
username: git
password: <%= @password %>
# host: localhost
# port: 5432
# socket: /tmp/postgresql.sock
#
# Development specific
#
development:
adapter: postgresql
encoding: unicode
database: gitlabhq_development
pool: 5
username: postgres
password: <%= @password %>
# socket: /tmp/postgresql.sock
#
# Staging specific
#
staging:
adapter: postgresql