# GitLab software-release
[buildout]
extends =
    ../../stack/slapos.cfg
    ../../component/ruby/buildout.cfg
    ../../component/golang/buildout.cfg
    ../../component/postgresql/buildout.cfg
    ../../component/redis/buildout.cfg
    ../../component/cmake/buildout.cfg
    ../../component/icu/buildout.cfg
    ../../component/pkgconfig/buildout.cfg
    ../../component/nodejs/buildout.cfg
    ../../component/openssl/buildout.cfg
    ../../component/nginx/buildout.cfg

#   for instance
    ../../component/coreutils/buildout.cfg
    ../../component/bash/buildout.cfg
    ../../component/grep/buildout.cfg
    ../../component/bzip2/buildout.cfg
    ../../component/curl/buildout.cfg
    ../../component/tar/buildout.cfg
    ../../component/gzip/buildout.cfg
    ../../component/dcron/buildout.cfg
    ../../component/logrotate/buildout.cfg

parts =
    ruby2.1
    golang16
    git
    postgresql92
    redis28
    cmake
    icu
    pkgconfig
    nginx-output

    python-4gitlab
    gitlab-shell/vendor
    gitlab/vendor/bundle
    gitlab-workhorse
    git-backup

#   for instance
    instance.cfg

# TODO stop using slapos.cookbook-develop once 571d6514 gets into released
# slapos.cookbook egg
    slapos-cookbook-develop

    slapos-cookbook
    eggs

    bash
    curl
    watcher
    gitlab-export
    gzip
    dcron-output
    logrotate

[slapos.cookbook-repository]
revision = 571d6514f7290e8faa9439c4b86aa2f6c87df261

[git]
# TODO stop using custom git revision once git 2.11 is supported by Gitlab
url = https://www.kernel.org/pub/software/scm/git/git-2.10.2.tar.xz
md5sum = 3cd1dca37be60668f482545716923b72

############################
#   Software compilation   #
############################

# python with eggs, that will be used in gitlab
[python-4gitlab]
# NOTE cannot use zc.recipe.egg - github-markup invoks `python2 -S` and
# interpreter generated by zc.recipe.egg cannot handle that.
recipe  = z3c.recipe.scripts
# NOTE github-markup invokes it as `python2`, that's why we are naming it this way
# https://github.com/github/markup/blob/5393ae93/lib/github/markups.rb#L36
interpreter = python2
eggs    =
    docutils

# rubygemsrecipe with fixed url and this way pinned rubygems version
[rubygemsrecipe]
recipe  = rubygemsrecipe
url     = https://rubygems.org/rubygems/rubygems-2.5.2.zip


# bundler, that we'll use to
# - install gems for gitlab
# - run gitlab services / jobs  (via `bundle exec ...`)
[bundler-4gitlab]
<= rubygemsrecipe
ruby-location = ${ruby2.1:location}
ruby-executable = ${:ruby-location}/bin/ruby
gems    = bundler==1.11.2

# bin installed here
bundle  = ${buildout:bin-directory}/bundle

# install together with dependencies of gitlab, which we cannot specify using
#   --with-... gem option
# ( reason: rubygemsrecipe hardcodes PATH inside generated bin/* and it is
#   impossible to adjust it later )
#
# bundle exec <smth>                ; <smth> starts with `#!/usr/bin/env ruby` as rubygems
# Rugged needs: cmake, pkgconfig
# execjs needs: nodejs
# rails needs db client program on path: psql
# gitlab wants to check redis version via running: redis-cli
# gitlab wants git to be really on path ( it uses git from abspath defined in
#   gitlab.yml, but there are not all cases like this, e.g. in
#   https://gitlab.com/gitlab-org/gitlab_git/blob/2f0d3c1a/lib/gitlab_git/repository.rb#L259 )
# gitlab (via github-markup) wants to convert rst -> html via running: python2 (with docutils egg)
# (python-4gitlab puts interpreter into ${buildout:bin-directory})
environment =
  PATH    = ${:ruby-location}/bin:${cmake:location}/bin:${pkgconfig:location}/bin:${nodejs:location}/bin:${postgresql92:location}/bin:${redis28:location}/bin:${git:location}/bin:${buildout:bin-directory}:%(PATH)s


# gitlab, gitlab-shell & gitlab-workhorse checked out as git repositories
# pinned to exact commit
[git-repository]
recipe  = slapos.recipe.build:gitclone
git-executable = ${git:location}/bin/git

[gitlab-repository]
<= git-repository
#repository = https://gitlab.com/gitlab-org/gitlab-ce.git
repository = https://lab.nexedi.com/nexedi/gitlab-ce.git
# 8.8.X + NXD patches:
revision = v8.8.9-10-g967afbdc3a2d2bcc58ed31ca50d5293fa2a2e9ed
location = ${buildout:parts-directory}/gitlab

[gitlab-shell-repository]
<= git-repository
#repository = https://gitlab.com/gitlab-org/gitlab-shell.git
repository = https://lab.nexedi.com/nexedi/gitlab-shell.git
# gitlab 8.8 wants gitlab-shell 2.7.2
# 2.7.2 + NXD patches
revision = v2.6.10-50-gfbca95be784816349abc5930324659151eca50d1
location = ${buildout:parts-directory}/gitlab-shell

[gitlab-workhorse-repository]
<= git-repository
#repository = https://gitlab.com/gitlab-org/gitlab-workhorse.git
repository = https://lab.nexedi.com/nexedi/gitlab-workhorse.git
# gitlab 8.8 wants gitlab-workhorse 0.7.1
# 0.7.1 + NXD patches
revision = v0.7.1-5-gd23a3247829fc3200e3dc784dcd57b5a0febac48
location = ${buildout:parts-directory}/gitlab-workhorse



# build needed-by-gitlab gems via bundler
[gitlab/vendor/bundle]
recipe  = slapos.recipe.cmmi
path    = ${gitlab-repository:location}
bundle  = ${bundler-4gitlab:bundle}

configure-command = cd ${:path} &&
    ${:bundle} config --local build.charlock_holmes --with-icu-dir=${icu:location}  &&
    ${:bundle} config --local build.pg  --with-pg-config=${postgresql92:location}/bin/pg_config

make-binary =
make-targets= cd ${:path} &&
    ${:bundle} install --deployment  --without development test  mysql kerberos

# directories and repositories required by gitlab-backup
[gopath]
directory = ${buildout:directory}/go.work
src	= ${:directory}/src
bin	= ${:directory}/bin

[go-git-repository]
<= git-repository
repository = https://${:go.importpath}.git
location = ${gopath:src}/${:go.importpath}

[git2go-repository]
<= go-git-repository
go.importpath = github.com/libgit2/git2go
# branch 'next' is required by git-backup
revision = next-g53594d7581617dbae7bb5960b4ac5f0ff513c184

[git-backup-repository]
<= go-git-repository
go.importpath = lab.nexedi.com/kirr/git-backup
revision = 3ba6cf73ba224c40f67f1fb87c855b915eb91f58


[git-backup]
# install git2go, git-backup, gitlab-backup in <gopath>/bin
recipe  = slapos.recipe.cmmi
path    = ${git-backup-repository:location}
configure-command = :
make-binary =
make-targets= cd ${git2go-repository:location}
              && git submodule update --init
              && make install
              && install -d ${gopath:bin}
              && go install ${git-backup-repository:go.importpath}
              && cp -a ${git-backup-repository:location}/contrib/gitlab-backup ${gopath:bin}
environment =
  PATH=${cmake:location}/bin:${pkgconfig:location}/bin:${git:location}/bin:${golang16:location}/bin:${buildout:bin-directory}:%(PATH)s
  GOPATH=${gopath:directory}

[xnice-repository]
# to get kirr's misc repo containing xnice script for executing processes
# with lower priority (used for backup script inside the cron)
<= git-repository
repository = https://lab.nexedi.com/kirr/misc.git
revision =  4073572ea700bf1b115f3a135aebebe5b3b824e4
location = ${buildout:parts-directory}/misc

# build needed-by-gitlab-shell gems via bundler
# ( there is not vendor/ dir in gitlab-shell, so to avoid having buildout error
#   on mkdir vendor/bundle, this part name is just /vendor )
[gitlab-shell/vendor]
recipe  = slapos.recipe.cmmi
path    = ${gitlab-shell-repository:location}
bundle  = ${bundler-4gitlab:bundle}

configure-command = true
make-binary =
make-targets= cd ${:path} &&
    ${:bundle} install --deployment  --without development test


# build gitlab-workhorse
[gitlab-workhorse]
recipe  = slapos.recipe.cmmi
path    = ${gitlab-workhorse-repository:location}

configure-command = :
make-targets= ${:_buildout_section_name_}

environment =
  PATH=${golang16:location}/bin:%(PATH)s


###############################
#   Trampoline for instance   #
###############################

# eggs for instance.cfg
[eggs]
recipe  = zc.recipe.egg
eggs    =
    plone.recipe.command
    cns.recipe.symlink


[instance.cfg]
recipe  = slapos.recipe.template
url     = ${:_profile_base_location_}/instance.cfg.in
output  = ${buildout:directory}/instance.cfg
md5sum  = 2329ddc4934e900785aa669adc214c23

# macro: download a shell script and put it rendered into <software>/bin/
[binsh]
recipe  = slapos.recipe.template:jinja2
template= ${:_profile_base_location_}/${:_buildout_section_name_}.in
rendered= ${buildout:bin-directory}/${:_buildout_section_name_}
mode    = 0755
context =
    section bash    bash

[watcher]
<= binsh
md5sum  = 90690e1351637f20ff2df57a6c3e85b4

[gitlab-export]
<= binsh
md5sum  = a7b32680e80f34276f0a32a5e22dad50



# macro: download a file named as section name
#
#   [filename]
#   <= download-file
#   md5sum = ...
[download-file]
recipe  = slapos.recipe.build:download
url     = ${:_profile_base_location_}/${:_buildout_section_name_}
destination = ${buildout:directory}/${:_buildout_section_name_}

# like download-file, but download from template/<filename>
[download-template]
<= download-file
url     = ${:_profile_base_location_}/template/${:_buildout_section_name_}


[database.yml.in]
<= download-template
md5sum  = 61d1d04b9347b3168a1ad7676e4681ef

[gitconfig.in]
<= download-template
md5sum  = eb1230fee50067924ba89f4dc6e82fa9

[gitlab-parameters.cfg]
<= download-file
md5sum  = a74670934ec0190cc212d1f3468c11ed

[gitlab-shell-config.yml.in]
<= download-template
md5sum  = 58c09b1e609f903e483a76fe9e57366c

[gitlab-unicorn-startup.in]
<= download-file
md5sum  = a9cb347f60aad3465932fd36cd4fe25d

[gitlab.yml.in]
<= download-template
md5sum  = 176939a6428a7aca4767a36421b0af2b

[instance-gitlab.cfg.in]
<= download-file
md5sum  = b05fad928ffbb689b4415837525c62d1

[instance-gitlab-export.cfg.in]
<= download-file
md5sum  = 00bd4ddf75a40a9d18d8243289f68ee9

[macrolib.cfg.in]
<= download-file
md5sum  = a56a44e96f65f5ed20211bb6a54279f4

[nginx-gitlab-http.conf.in]
<= download-template
md5sum  = a11b50d2ff2b1fa842ba4aa20041e2fe

[nginx.conf.in]
<= download-template
md5sum  = 1374f38ab6f295b850d45ea0019ec05d

[rack_attack.rb.in]
<= download-template
md5sum  = 7d0e6dc6b826f6df6b20d8574a29e2f8

[resque.yml.in]
<= download-template
md5sum  = 7c89a730889e3224548d9abe51a2d719

[smtp_settings.rb.in]
<= download-template
md5sum  = c67ea492e17f774d0e18f1217338a55f

[unicorn.rb.in]
<= download-template
md5sum  = 83921db1835d9e81cbbe808631cc40a9


[versions]
cns.recipe.symlink = 0.2.3
docutils = 0.12
plone.recipe.command = 1.1
rubygemsrecipe  = 0.2.2
slapos.recipe.template = 2.9
z3c.recipe.scripts = 1.0.1
