Commit a03de3da96d994243a51430bdad9362e129c9ec7

Authored by Sytse Sijbrandij
2 parents 1c514868 6e6ca133

Merge branch 'mysql' into 'master'

MySQL support
Makefile
... ... @@ -25,7 +25,7 @@ remove_json:
25 25 find pkg/ -name '*.json' -delete
26 26  
27 27 move_ee_to_secret_dir:
28   - if (git describe | grep -q -w ee); then \
  28 + if support/is_gitlab_ee.sh ; then \
29 29 mv pkg ${SECRET_DIR} \
30 30 && mkdir pkg \
31 31 && mv ${SECRET_DIR} pkg/ \
... ...
README.md
... ... @@ -308,6 +308,56 @@ sudo /opt/gitlab/bin/gitlab-rails console
308 308  
309 309 This will only work after you have run `gitlab-ctl reconfigure` at least once.
310 310  
  311 +## Using omnibus-gitlab with a remote database server
  312 +
  313 +This is an advanced topic. If you do not want to use the built-in Postgres
  314 +server of omnibus-gitlab or if you want to use MySQL (GitLab Enterprise Edition
  315 +only) you can do so as follows.
  316 +
  317 +Important note: if you are connecting omnibus-gitlab to an existing GitLab
  318 +database you should create a backup before attempting this procedure.
  319 +
  320 +### Create a user and database for GitLab
  321 +
  322 +First, set up your database server according to the [upstream GitLab
  323 +instructions](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md#5-database).
  324 +If you want to keep using an existing GitLab database you can skip this step.
  325 +
  326 +### Configure omnibus-gitlab to connect to your remote database server
  327 +
  328 +Next, we add the following settings to `/etc/gitlab/gitlab.rb`.
  329 +
  330 +```ruby
  331 +# Disable the built-in Postgres
  332 +postgresql['enable'] = false
  333 +
  334 +# Fill in the values for database.yml
  335 +gitlab_rails['db_adapter'] = 'mysql2'
  336 +gitlab_rails['db_encoding'] = 'utf8'
  337 +gitlab_rails['db_host'] = '127.0.0.1'
  338 +gitlab_rails['db_port'] = '3306'
  339 +gitlab_rails['db_username'] = 'git'
  340 +gitlab_rails['db_password'] = 'password'
  341 +```
  342 +
  343 +Parameters such as `db_adapter` correspond to `adapter` in `database.yml`; see
  344 +the upstream GitLab examples for [Postgres][database.yml.postgresql] and
  345 +[MySQL][database.yml.mysql]. We remind you that `/etc/gitlab/gitlab.rb` should
  346 +have file permissions `0600` because it contains plaintext passwords.
  347 +
  348 +Run `sudo gitlab-ctl reconfigure` for the change to take effect.
  349 +
  350 +### Seed the database (fresh installs only)
  351 +
  352 +Omnibus-gitlab will not automatically seed your external database. Run the
  353 +following command to import the schema and create the first admin user:
  354 +
  355 +```shell
  356 +sudo gitlab-rake gitlab:setup
  357 +```
  358 +
  359 +This is a destructive command; do not run it on an existing database!
  360 +
311 361 ## Building your own package
312 362  
313 363 See [the separate build documentation](doc/build.md).
... ... @@ -321,3 +371,5 @@ This omnibus installer project is based on the awesome work done by Chef in
321 371 [CE README]: https://gitlab.com/gitlab-org/gitlab-ce/blob/master/README.md
322 372 [omnibus-chef-server]: https://github.com/opscode/omnibus-chef-server
323 373 [gitlab.yml.erb]: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/files/gitlab-cookbooks/gitlab/templates/default/gitlab.yml.erb
  374 +[database.yml.postgresql]: https://gitlab.com/gitlab-org/gitlab-ce/blob/master/config/database.yml.postgresql
  375 +[database.yml.mysql]: https://gitlab.com/gitlab-org/gitlab-ce/blob/master/config/database.yml.mysql
... ...
config/projects/gitlab.rb
... ... @@ -29,7 +29,6 @@ build_iteration 1
29 29 dependency "preparation"
30 30  
31 31 dependency "git"
32   -dependency "postgresql"
33 32 dependency "redis"
34 33 dependency "nginx"
35 34 dependency "gitlab-shell"
... ...
config/software/gitlab-rails.rb
... ... @@ -19,6 +19,8 @@
19 19 name "gitlab-rails"
20 20 default_version "master"
21 21  
  22 +EE = system("#{Omnibus.project_root}/support/is_gitlab_ee.sh")
  23 +
22 24 dependency "ruby"
23 25 dependency "bundler"
24 26 dependency "libxml2"
... ... @@ -27,6 +29,7 @@ dependency "curl"
27 29 dependency "rsync"
28 30 dependency "libicu"
29 31 dependency "postgresql"
  32 +dependency "mysql-client" if EE
30 33  
31 34 source :git => "https://gitlab.com/gitlab-org/gitlab-ce.git"
32 35  
... ... @@ -44,7 +47,9 @@ build do
44 47 # build.
45 48 command "sed -i \"s/.*REVISION.*/REVISION = '$(git log --pretty=format:'%h' -n 1)'/\" config/initializers/2_app.rb"
46 49  
47   - bundle "install --without mysql development test --path=#{install_dir}/embedded/service/gem", :env => env
  50 + bundle_without = %w{development test}
  51 + bundle_without << "mysql" unless EE
  52 + bundle "install --without #{bundle_without.join(" ")} --path=#{install_dir}/embedded/service/gem", :env => env
48 53  
49 54 # In order to precompile the assets, we need to get to a state where rake can
50 55 # load the Rails environment.
... ...
config/software/mysql-client.rb 0 → 100644
... ... @@ -0,0 +1,69 @@
  1 +#
  2 +# Copyright:: Copyright (c) 2013 Robby Dyer
  3 +# Copyright:: Copyright (c) 2014 GitLab.com
  4 +# License:: Apache License, Version 2.0
  5 +#
  6 +# Licensed under the Apache License, Version 2.0 (the "License");
  7 +# you may not use this file except in compliance with the License.
  8 +# You may obtain a copy of the License at
  9 +#
  10 +# http://www.apache.org/licenses/LICENSE-2.0
  11 +#
  12 +# Unless required by applicable law or agreed to in writing, software
  13 +# distributed under the License is distributed on an "AS IS" BASIS,
  14 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 +# See the License for the specific language governing permissions and
  16 +# limitations under the License.
  17 +#
  18 +name "mysql-client"
  19 +default_version "5.5.37"
  20 +
  21 +dependencies [
  22 + "openssl",
  23 + "zlib",
  24 + "ncurses"
  25 + ]
  26 +
  27 +source :url => "http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.37.tar.gz",
  28 + :md5 => "bf1d80c66d4822ec6036300399a33c03"
  29 +
  30 +relative_path "mysql-#{version}"
  31 +
  32 +env = {
  33 + "LDFLAGS" => "-L#{install_dir}/embedded/lib -I#{install_dir}/embedded/include",
  34 + "CFLAGS" => "-L#{install_dir}/embedded/lib -I#{install_dir}/embedded/include",
  35 + "CXXFLAGS" => "-L#{install_dir}/embedded/lib -I#{install_dir}/embedded/include",
  36 + "CPPFLAGS" => "-L#{install_dir}/embedded/lib -I#{install_dir}/embedded/include",
  37 + "LD_RUN_PATH" => "#{install_dir}/embedded/lib",
  38 + "LD_LIBRARY_PATH" => "#{install_dir}/embedded/lib",
  39 + "PATH" => "#{install_dir}/embedded/bin:#{ENV['PATH']}",
  40 +}
  41 +
  42 +# Force CentOS-5 to use gcc/g++ v4.4
  43 +if OHAI.platform =~ /centos/ and OHAI.platform_version =~ /^5/
  44 + env.merge!( {
  45 + "CC" => "gcc44",
  46 + "CXX" => "g++44"
  47 + })
  48 +end
  49 +
  50 +build do
  51 +
  52 + command [
  53 + "cmake",
  54 + "-DCMAKE_SKIP_RPATH=YES",
  55 + "-DCMAKE_INSTALL_PREFIX=#{install_dir}/embedded",
  56 + "-DWITH_SSL=system",
  57 + "-DOPENSSL_INCLUDE_DIR:PATH=#{install_dir}/embedded/include",
  58 + "-DOPENSSL_LIBRARIES:FILEPATH=#{install_dir}/embedded/lib/libssl.so",
  59 + "-DWITH_ZLIB=system",
  60 + "-DZLIB_INCLUDE_DIR:PATH=#{install_dir}/embedded/include",
  61 + "-DZLIB_LIBRARY:FILEPATH=#{install_dir}/embedded/lib/libz.so",
  62 + "-DCRYPTO_LIBRARY:FILEPATH=#{install_dir}/embedded/lib/libcrypto.so",
  63 + ".",
  64 + ].join(" "), :env => env
  65 +
  66 + %w{libmysql client include}.each do |target|
  67 + command "make -j #{max_build_jobs} install", :env => env, :cwd => "#{project_dir}/#{target}"
  68 + end
  69 +end
... ...
files/gitlab-cookbooks/gitlab/attributes/default.rb
... ... @@ -100,6 +100,15 @@ default[&#39;gitlab&#39;][&#39;gitlab-rails&#39;][&#39;git_bin_path&#39;] = &quot;/opt/gitlab/embedded/bin/gi
100 100 default['gitlab']['gitlab-rails']['git_max_size'] = 5242880
101 101 default['gitlab']['gitlab-rails']['git_timeout'] = 10
102 102  
  103 +default['gitlab']['gitlab-rails']['db_adapter'] = "postgresql"
  104 +default['gitlab']['gitlab-rails']['db_encoding'] = "unicode"
  105 +default['gitlab']['gitlab-rails']['db_database'] = "gitlabhq_production"
  106 +default['gitlab']['gitlab-rails']['db_pool'] = 10
  107 +default['gitlab']['gitlab-rails']['db_username'] = "gitlab"
  108 +default['gitlab']['gitlab-rails']['db_password'] = "password"
  109 +default['gitlab']['gitlab-rails']['db_host'] = "localhost"
  110 +default['gitlab']['gitlab-rails']['db_port'] = 6379
  111 +default['gitlab']['gitlab-rails']['db_socket'] = nil
103 112  
104 113 ####
105 114 # Unicorn
... ...
files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb
... ... @@ -53,13 +53,24 @@ template_symlink File.join(gitlab_rails_etc_dir, &quot;secret&quot;) do
53 53 restarts dependent_services
54 54 end
55 55  
  56 +database_attributes = node['gitlab']['gitlab-rails'].to_hash
  57 +if node['gitlab']['postgresql']['enable']
  58 + database_attributes.merge!(
  59 + :db_adapter => "postgresql",
  60 + :db_username => node['gitlab']['postgresql']['sql_user'],
  61 + :db_password => node['gitlab']['postgresql']['sql_password'],
  62 + :db_host => node['gitlab']['postgresql']['listen_address'],
  63 + :db_port => node['gitlab']['postgresql']['port']
  64 + )
  65 +end
  66 +
56 67 template_symlink File.join(gitlab_rails_etc_dir, "database.yml") do
57 68 link_from File.join(gitlab_rails_source_dir, "config/database.yml")
58   - source "database.yml.postgresql.erb"
  69 + source "database.yml.erb"
59 70 owner "root"
60 71 group "root"
61 72 mode "0644"
62   - variables(node['gitlab']['postgresql'].to_hash)
  73 + variables database_attributes
63 74 restarts dependent_services
64 75 end
65 76  
... ...
files/gitlab-cookbooks/gitlab/templates/default/database.yml.erb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +production:
  2 + adapter: <%= @db_adapter %>
  3 + encoding: <%= @db_encoding %>
  4 + database: <%= @db_database %>
  5 + pool: <%= @db_pool %>
  6 + username: "<%= @db_username %>"
  7 + password: "<%= @db_password %>"
  8 + host: <%= @db_host %>
  9 + port: <%= @db_port %>
  10 + socket: <%= @db_socket %>
... ...
files/gitlab-cookbooks/gitlab/templates/default/database.yml.postgresql.erb
... ... @@ -1,49 +0,0 @@
1   -#
2   -# PRODUCTION
3   -#
4   -production:
5   - adapter: postgresql
6   - encoding: unicode
7   - database: gitlabhq_production
8   - pool: 10
9   - username: <%= node['gitlab']['postgresql']['sql_user'] %>
10   - password: "<%= node['gitlab']['postgresql']['sql_password'] %>"
11   - host: <%= node['gitlab']['postgresql']['listen_address'] %>
12   - port: <%= node['gitlab']['postgresql']['port'] %>
13   -# socket: /tmp/postgresql.sock
14   -
15   -#
16   -# Development specific
17   -#
18   -development:
19   - adapter: postgresql
20   - encoding: unicode
21   - database: gitlabhq_development
22   - pool: 5
23   - username: postgres
24   - password:
25   - # socket: /tmp/postgresql.sock
26   -
27   -#
28   -# Staging specific
29   -#
30   -staging:
31   - adapter: postgresql
32   - encoding: unicode
33   - database: gitlabhq_staging
34   - pool: 5
35   - username: postgres
36   - password:
37   - # socket: /tmp/postgresql.sock
38   -
39   -# Warning: The database defined as "test" will be erased and
40   -# re-generated from your development database when you run "rake".
41   -# Do not set this db to the same as development or production.
42   -test: &test
43   - adapter: postgresql
44   - encoding: unicode
45   - database: gitlabhq_test
46   - pool: 5
47   - username: postgres
48   - password:
49   - # socket: /tmp/postgresql.sock
support/is_gitlab_ee.sh 0 → 100755
... ... @@ -0,0 +1,2 @@
  1 +#!/bin/bash
  2 +[[ -n $ee ]] || grep -q '^source.*"git@gitlab.com:subscribers/gitlab-ee.git"' config/software/gitlab-rails.rb
... ...