instance-gitlab.cfg.in 24.3 KB
Newer Older
1
# GitLab instance
2 3 4 5
# NOTE instance/software layout is inspired by gitlab omnibus
# NOTE all services are interconnected via unix sockets - because of easier
#      security and performance reasons (unix has 2x less latency and more
#      throughput compared to tcp over loopback).
6
[buildout]
7 8
extends =
  {{ monitor_template }}
9 10
parts =
    directory
11
    publish-instance-info
12

13 14
#   gitlab-<prog>
# ? mailroom
15
{% set gitlab_progv = 'rails rake unicorn sidekiq unicorn-startup' .split() %}
16 17 18 19
{% for prog in gitlab_progv %}
    gitlab-{{ prog }}
{% endfor %}

20 21
    gitconfig

22 23 24
    gitlab-work
    gitlab-shell-work

25
    service-gitlab-workhorse
26
    service-unicorn
27
    service-sidekiq
28

29
    service-nginx
30
    service-postgresql
Kirill Smelkov's avatar
Kirill Smelkov committed
31
    service-redis
32
    promise-redis
33

34 35 36 37
    service-gitaly
    cron-service
    cron-entry-logrotate
    logrotate-entry-cron
38

39 40
    on-reinstantiate

41 42 43 44 45 46 47 48 49 50 51
# std stuff for slapos instance
eggs-directory = {{ eggs_directory }}
develop-eggs-directory = {{ develop_eggs_directory }}
offline = true


##################################
#   GitLab instance parameters   #
##################################

[instance-parameter]
52 53 54 55 56 57 58 59
{#- There are dangerous keys like recipe, etc #}
{#- XXX: Some other approach would be useful #}
{%- set DROP_KEY_LIST = ['recipe', '__buildout_signature__', 'computer', 'partition', 'url', 'key', 'cert'] %}
{%- for key, value in instance_parameter_dict.iteritems() -%}
{%-   if key not in DROP_KEY_LIST %}
{{ key }} = {{ value }}
{%-   endif -%}
{%- endfor %}
60

61 62


63
# for convenience
64 65 66 67
[external-url]
recipe  = slapos.cookbook:urlparse
url     = ${instance-parameter:configuration.external_url}

68
[backend-info]
69 70 71 72 73
host    = ${instance-parameter:ipv6-random}
port    = 7777
# whether to use http or https - determined by external url
url     = ${external-url:scheme}://[${:host}]:${:port}

74 75 76 77
# current slapuserX
user    = {{ pwd.getpwuid(os.getuid())[0] }}


78 79 80 81 82
[publish-instance-info]
recipe  = slapos.cookbook:publish
backend_url = ${backend-info:url}


83

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
#############################
#   GitLab instance setup   #
#############################

# 1. directories
[directory]
recipe  = slapos.cookbook:mkdirectory
home    = ${buildout:directory}
bin     = ${:home}/bin
etc     = ${:home}/etc
var     = ${:home}/var
log     = ${:var}/log
run     = ${:var}/run
srv     = ${:home}/srv
# slapos startup/service/promise scripts live here:
startup = ${:etc}/run
service = ${:etc}/service
101
promise.slow = ${:etc}/promise.slow
102

103 104 105 106 107 108 109 110 111 112
# gitlab: etc/ log/ ...
[gitlab-dir]
recipe  = slapos.cookbook:mkdirectory
etc     = ${directory:etc}/gitlab
log     = ${directory:log}/gitlab

var     = ${directory:var}/gitlab
tmp     = ${:var}/tmp
uploads = ${:var}/uploads
assets  = ${:var}/assets
113 114 115 116
shared  = ${:var}/shared
artifacts = ${:shared}/artifacts
lfs-objects = ${:shared}/lfs-objects
builds  = ${:var}/builds
117
backup  = ${directory:var}/backup
118 119
public  = ${:var}/public
pages   = ${:shared}/pages
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139

[gitlab-repo-dir]
recipe  = slapos.cookbook:mkdirectory
repositories    = ${directory:var}/repositories
# gitlab wants it to be drwxrws---
# FIXME setting such mode with :mkdirectory is not possible, because mkdir(2)
# does & 0777 and also there is umask. So we workaround:
[gitlab-repo-xdir]
recipe  = plone.recipe.command
stop-on-error = yes
repositories = ${gitlab-repo-dir:repositories}
command = chmod 02770 ${:repositories}

[gitlab]
etc     = ${gitlab-dir:etc}
log     = ${gitlab-dir:log}
var     = ${gitlab-dir:var}
tmp     = ${gitlab-dir:tmp}
uploads = ${gitlab-dir:uploads}
assets  = ${gitlab-dir:assets}
140 141 142 143
shared  = ${gitlab-dir:shared}
artifacts = ${gitlab-dir:artifacts}
lfs-objects = ${gitlab-dir:lfs-objects}
builds  = ${gitlab-dir:builds}
144 145
backup  = ${gitlab-dir:backup}
repositories = ${gitlab-repo-xdir:repositories}
146 147
public  = ${gitlab-dir:public}
pages   = ${gitlab-dir:shared}/pages
148 149 150 151 152 153 154


# gitlab-shell: etc/ log/ gitlab_shell_secret ...
[gitlab-shell-dir]
recipe  = slapos.cookbook:mkdirectory
etc     = ${directory:etc}/gitlab-shell
log     = ${directory:log}/gitlab-shell
155

156 157 158 159
[gitlab-shell]
etc     = ${gitlab-shell-dir:etc}
log     = ${gitlab-shell-dir:log}
secret  = ${secrets:secrets}/gitlab_shell_secret
160
hook    =
161 162


163 164 165 166 167 168
# place to keep all secrets
[secrets]
recipe  = slapos.cookbook:mkdirectory
secrets = ${directory:var}/secrets
mode    = 0700

169 170 171 172 173 174 175 176 177 178 179 180 181
[gitaly-dir]
recipe  = slapos.cookbook:mkdirectory
gitaly  = ${directory:var}/gitaly
sockets = ${:gitaly}/sockets
internal = ${:sockets}/internal
log     = ${directory:log}/gitaly

[gitaly]
socket  = ${gitaly-dir:sockets}/gitaly.socket
log     = ${gitaly-dir:log}
location = {{ gitaly_location }}
pid     = ${directory:run}/gitaly.pid
internal_socket = ${gitaly-dir:internal}
182

183 184 185 186 187
# 2. configuration files
[etc-template]
recipe  = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
mode    = 0640
188 189
import-list =
    rawfile macrolib.cfg.in     {{ macrolib_cfg_in }}
190 191 192
context =
    raw     autogenerated       # This file was autogenerated. (DO NOT EDIT - changes will be lost)
    section instance_parameter  instance-parameter
193
    section backend_info        backend-info
194
    import  urlparse            urlparse
195
    raw     git                 {{ git }}
196 197 198 199 200
    ${:context-extra}
context-extra =

[gitlab-etc-template]
<= etc-template
201
output= ${gitlab:etc}/${:_buildout_section_name_}
202

203 204
[nginx-etc-template]
<= etc-template
205
output= ${nginx:etc}/${:_buildout_section_name_}
206

207 208 209

[database.yml]
<= gitlab-etc-template
210
url = {{ database_yml_in }}
211 212
context-extra =
    section pgsql                   service-postgresql
213

214 215
[gitconfig]
<= etc-template
216
url = {{ gitconfig_in }}
217
# NOTE put directly into $HOME/ - this way git will pick it up
218
output= ${directory:home}/.${:_buildout_section_name_}
219

220 221
[gitlab-shell-config.yml]
<= etc-template
222 223
url = {{ gitlab_shell_config_yml_in }}
output= ${gitlab-shell:etc}/config.yml
224 225 226 227
context-extra =
    import  urllib                  urllib
    section gitlab                  gitlab
    section gitlab_shell            gitlab-shell
228
    section gitlab_shell_work       gitlab-shell-work
229 230 231
    section unicorn                 unicorn
    section service_redis           service-redis
    raw     redis_binprefix         {{ redis_binprefix }}
232 233 234

[gitlab.yml]
<= gitlab-etc-template
235
url = {{ gitlab_yml_in }}
236
context-extra =
237
    import  urllib                  urllib
238 239 240
    section gitlab                  gitlab
    section gitlab_shell            gitlab-shell
    section gitlab_shell_work       gitlab-shell-work
241
    section gitaly                  gitaly
242

243 244
[nginx.conf]
<= nginx-etc-template
245
url = {{ nginx_conf_in }}
246 247
context-extra =
    section directory               directory
248
    section gitlab_workhorse        gitlab-workhorse
249
    raw     nginx_mime_types        {{ nginx_mime_types }}
250
    raw     nginx_gitlab_http_conf  ${nginx-gitlab-http.conf:output}
251 252 253

[nginx-gitlab-http.conf]
<= nginx-etc-template
254
url = {{ nginx_gitlab_http_conf_in }}
255 256 257 258
context-extra =
    section nginx                   nginx
    section gitlab_work             gitlab-work
    section gitlab_workhorse        gitlab-workhorse
259

260 261
[gitaly-config.toml]
<= etc-template
262 263
url = {{ gitaly_config_toml_in }}
output= ${directory:etc}/${:_buildout_section_name_}
264 265 266 267 268 269
context-extra =
    import  urllib                  urllib
    section gitlab                  gitlab
    section gitlab_shell_work       gitlab-shell-work
    section gitaly                  gitaly

270 271
[rack_attack.rb]
<= gitlab-etc-template
272
url = {{ rack_attack_rb_in }}
273 274 275

[resque.yml]
<= gitlab-etc-template
276
url = {{ resque_yml_in }}
277 278
context-extra =
    section redis                   service-redis
279 280 281

[smtp_settings.rb]
<= gitlab-etc-template
282
url = {{ smtp_settings_rb_in }}
283 284
# contains smtp password
mode    = 0600
285 286 287

[unicorn.rb]
<= gitlab-etc-template
288
url = {{ unicorn_rb_in }}
289 290 291 292
context-extra =
    section unicorn                 unicorn
    section directory               directory
    section gitlab_work             gitlab-work
293 294 295 296



# 3. bin/
297 298 299 300
#   gitlab-<prog>
[gitlab-bin]
recipe  = slapos.cookbook:wrapper
wrapper-path = ${directory:bin}/${:_buildout_section_name_}
301
# NOTE $HOME needed to pick gitconfig
302
environment  =
303
    PATH = {{ node_bin_location }}:{{ gopath_bin }}:{{ yarn_location }}/bin:/usr/local/bin:/usr/bin:/bin
304
    BUNDLE_GEMFILE = {{ gitlab_repository_location }}/Gemfile
305
    HOME = ${directory:home}
306
    RAILS_ENV = production
307
    SIDEKIQ_MEMORY_KILLER_MAX_RSS = ${instance-parameter:configuration.sidekiq_memory_killer_max_rss}
308 309 310 311 312 313 314 315 316 317 318 319

command-line =
    {{ bundler_4gitlab }} exec sh -c
    'cd ${gitlab-work:location} && ${:prog} "$@"' ${:prog}

{% for prog in gitlab_progv %}
[gitlab-{{ prog }}]
<= gitlab-bin
prog    = {{ prog }}
{% endfor %}


320 321 322
[gitlab-unicorn-startup]
recipe  = slapos.recipe.template:jinja2
mode    = 0755
323 324
url = {{ gitlab_unicorn_startup_in }}
output= ${directory:bin}/${:_buildout_section_name_}
325 326 327 328 329 330 331 332 333 334 335
context =
    raw     bash_bin                {{ bash_bin }}
    raw     gitlab_rake             ${gitlab-rake:wrapper-path}
    raw     gitlab_unicorn          ${gitlab-unicorn:wrapper-path}
    raw     psql_bin                {{ postgresql_location }}/bin/psql
    section pgsql                   service-postgresql
    raw     log_dir                 ${gitlab:log}
    section unicorn_rb              unicorn.rb
    section gitlab_work             gitlab-work


336
# 4. gitlab- & gitlab-shell- work directories
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
#
# Gitlab/Rails operation is tightened that config/ lives inside code, which goes
# against having ability to create several instances configured differently
# from 1 SR.
#
# One possibility to overcome this could be to make another Gitlab root
# symbolically linked to original SR _and_ several configuration files
# symbolically linked to instance place. Unfortunately this does not work -
# Ruby determines realpath on module import and Gitlab and Rails lookup config
# files relative to imported modules.
#
# we clone cloned gitlab and add proper links to vendor/bundle and instance
# config files.
# XXX there is no need for full clone - we only need worktree checkout (a-la `git
# worktree add`, but without creating files in original clone)
#
# This way Gitlab/Rails still think they work in 1 code / 1 instance way,
# and we can reuse SR.
# XXX better do such tricks with bind mounting, but that requires user namespaces

[work-base]
recipe  = plone.recipe.command
stop-on-error = yes
location = ${directory:home}/${:_buildout_section_name_}
command =
# make sure we start from well-defined empty state
# (needed e.g. if previous install failed in the middle)
    rm -rf ${:location}  &&
# init work repository and add `software` remote pointing to main repo in SR software/...
    {{ git }} init ${:location}  &&
    cd ${:location}  &&
    {{ git }} remote add software ${:software}  &&
    ${:update-command}

update-command =
    cd ${:location}  &&
    {{ git }} fetch software  &&
    {{ git }} reset --hard `cd ${:software} && {{ git }} rev-parse HEAD`  &&
    ${:tune-command}


378
# NOTE there is no need to link/create .gitlab_shell_secret - we set path to it
379 380 381 382 383
# in gitlab & gitlab-shell configs, and gitlab creates it on its first start
[gitlab-work]
<= work-base
software = {{ gitlab_repository_location }}
tune-command =
384 385 386 387
# Initialise secrets
    if [ ! -s "${secrets:secrets}/gitlab_secrets.yml" ]; then
      cp config/secrets.yml.example ${secrets:secrets}/gitlab_secrets.yml;
    fi
388
# secret* tmp/ log/ shared/ builds/ node_modules/
389
    rm -f .secret  &&
390
    rm -rf log tmp shared builds node_modules  &&
391 392 393
    ln -sf ${secrets:secrets}/gitlab_rails_secret .secret  &&
    ln -sf ${gitlab:log} log  &&
    ln -sf ${gitlab:tmp} tmp  &&
394 395
    ln -sf ${gitlab:shared} shared  &&
    ln -sf ${gitlab:builds} builds  &&
396
    ln -sf {{ gitlab_repository_location }}/node_modules node_modules &&
397
    ln -sf ${gitlab-workhorse:secret} .gitlab_workhorse_secret
398 399
# config/
    cd config  &&
400 401 402 403
    ln -sf ${unicorn.rb:output} unicorn.rb  &&
    ln -sf ${gitlab.yml:output} gitlab.yml  &&
    ln -sf ${database.yml:output} database.yml  &&
    ln -sf ${resque.yml:output} resque.yml  &&
404
    ln -sf ${secrets:secrets}/gitlab_secrets.yml secrets.yml  &&
405 406
# config/initializers/
    cd initializers  &&
407 408
    ln -sf ${rack_attack.rb:output} rack_attack.rb  &&
    ln -sf ${smtp_settings.rb:output} smtp_settings.rb  &&
409
# public/
410
    cd ../../public  &&
411 412 413 414 415 416 417 418 419 420 421 422
    rm -rf uploads assets  &&
    ln -sf ${gitlab:uploads} uploads  &&
    ln -sf ${gitlab:assets} assets  &&
    true


# ----//---- for gitlab-shell
[gitlab-shell-work]
<= work-base
software = {{ gitlab_shell_repository_location }}

tune-command =
423
    ln -sf ${gitlab-shell-config.yml:output}   config.yml  &&
424 425 426 427
    true



428
# 5. services
429

430 431
# [promise-<something>] to check <something> by url
[promise-byurl]
432
<= monitor-promise-base
433
promise = check_command_execute
434
name   = ${:_buildout_section_name_}.py
435
config-http-code   = 200
436

437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465


#####################
#   Postgresql db   #
#####################

# XXX gitlab-omnibus also tunes:
# - shared_buffers
# - work_mem
# - checkpoint_*
# - effective_check_size
# - lc_* en_US.UTF-8 -> C  (?)
[service-postgresql]
recipe  = slapos.cookbook:postgres
bin     = {{ postgresql_location }}/bin
services= ${directory:service}

dbname  = gitlabhq_production
# NOTE db name must match to what was used in KVM on lab.nexedi.com (restore script grants access to this user)
superuser = gitlab-psql
# no password - pgsql will listen only on unix sockets (see below) thus access
# is protected with filesystem-level permissions.
# ( besides, if we use slapos.cookbook:generate.password and do `password = ...`
#   the password is stored in plain text in .installed and thus becomes insecure )
password=

pgdata-directory = ${directory:srv}/postgresql

# empty addresses - listen only on unix socket
466 467
ipv4    =
ipv6    =
468 469 470 471 472 473
port    =

depend  =
    ${promise-postgresql:recipe}

[promise-postgresql]
474
<= monitor-promise-base
475
promise = check_command_execute
476 477
name = promise-postgresql.py
config-command =
478 479 480 481
    {{ postgresql_location }}/bin/psql \
        -h ${service-postgresql:pgdata-directory} \
        -U ${service-postgresql:superuser} \
        -d ${service-postgresql:dbname} \
482 483 484 485 486 487
        -c '\q'

# postgresql logs to stdout/stderr - logs are handled by slapos not us
# [logrotate-entry-postgresql]


Kirill Smelkov's avatar
Kirill Smelkov committed
488 489 490 491 492 493 494 495 496 497 498 499
#############
#   Redis   #
#############
[redis]
recipe  = slapos.cookbook:mkdirectory
srv     = ${directory:srv}/redis
log     = ${directory:log}/redis


[service-redis]
recipe  = slapos.cookbook:redis.server
wrapper = ${directory:service}/redis
500 501 502 503 504 505 506 507
promise-wrapper = ${directory:bin}/redis-promise

server-dir  = ${redis:srv}
config-file = ${directory:etc}/redis.conf
log-file    = ${redis:log}/redis.log
pid-file    = ${directory:run}/redis.pid
use-passwd  = false
unixsocket  = ${:server-dir}/redis.socket
Kirill Smelkov's avatar
Kirill Smelkov committed
508 509 510 511
# port = 0 means "don't listen on TCP at all" - listen only on unix socket
ipv6    = ::1
port    = 0

512 513
server-bin  = {{ redis_binprefix }}/redis-server
cli-bin  = {{ redis_binprefix }}/redis-cli
Kirill Smelkov's avatar
Kirill Smelkov committed
514 515 516
depend  =
    ${logrotate-entry-redis:recipe}

517 518
[promise-redis]
<= monitor-promise-base
519
promise = check_command_execute
520
name = promise-redis.py
521
config-command = ${service-redis:promise-wrapper}
Kirill Smelkov's avatar
Kirill Smelkov committed
522 523

[logrotate-entry-redis]
524
<= logrotate-entry-base
Kirill Smelkov's avatar
Kirill Smelkov committed
525
log     = ${redis:log}/*.log
526
name = redis
Kirill Smelkov's avatar
Kirill Smelkov committed
527 528


529 530 531 532 533 534
########################
#   gitlab-workhorse   #
########################
[gitlab-workhorse-dir]
recipe  = slapos.cookbook:mkdirectory
srv     = ${directory:srv}/gitlab-workhorse
535
log     = ${directory:log}/workhorse
536 537 538 539

[gitlab-workhorse]
srv     = ${gitlab-workhorse-dir:srv}
socket  = ${gitlab-workhorse:srv}/gitlab-workhorse.socket
540 541
log     = ${gitlab-workhorse-dir:log}/gitlab-workhorse.log
secret  = ${secrets:secrets}/gitlab_workhorse_secret
542 543 544 545 546 547 548 549

[service-gitlab-workhorse]
recipe  = slapos.cookbook:wrapper
wrapper-path    = ${directory:service}/gitlab-workhorse
command-line    = {{ gitlab_workhorse }}
    -listenNetwork unix
    -listenAddr ${gitlab-workhorse:socket}
    -authSocket ${unicorn:socket}
550
    -documentRoot ${gitlab-work:location}/public
551 552
    -secretPath ${gitlab-workhorse:secret}
    -logFile ${gitlab-workhorse:log}
553 554 555 556 557 558
# NOTE for profiling
#   -pprofListenAddr ...

# NOTE environment for:
#   - git to be available on path
#   - ruby to be available on path  (gitlab-workhorse -> gitlab-shell -> hooks  on push)
559
#   - gitconfig be found from ~/.gitconfig
560
environment =
561
    PATH={{ git_location }}/bin:{{ ruby_location }}/bin:{{ gzip_location }}/bin:{{ bzip2_location}}/bin
562
    HOME=${directory:home}
563 564 565

depend  =
    ${promise-gitlab-workhorse:recipe}
566
    ${logrotate-entry-gitlab-workhorse:recipe}
567 568 569 570


[promise-gitlab-workhorse]
<= promise-byurl
571 572
# http://localhost/users/statics.css will not redirect to /users/sign_in anymore because of this commit:
#  https://lab.nexedi.com/nexedi/gitlab-workhorse/commit/c81f109a62fecf2a847fb17ceed012b380dab49f#c1215002e6d745f05eaaf9ee1dad7752e85d866f_318_331
573
config-command     = {{ curl_bin }} --unix-socket ${gitlab-workhorse:socket}  http://localhost/users/sign_in
574 575 576 577 578 579


# gitlab-workhorse logs to stdout/stderr - logs are handled by slapos not us
# [logrotate-entry-gitlab-workhorse]


580 581 582 583 584 585 586 587 588 589 590 591 592
######################
#   unicorn worker   #
######################
[unicorn-dir]
recipe  = slapos.cookbook:mkdirectory
srv     = ${directory:srv}/unicorn
log     = ${directory:log}/unicorn

[unicorn]
srv     = ${unicorn-dir:srv}
log     = ${unicorn-dir:log}
socket  = ${:srv}/unicorn.socket

593 594 595
[service-unicorn]
recipe  = slapos.cookbook:wrapper
wrapper-path    = ${directory:service}/unicorn
596 597 598
# NOTE we perform db setup / migrations as part of unicorn startup.
# Those operations require PG and Redis to be up and running already, that's
# why we do it here. See gitlab-unicorn-startup for details.
599
command-line    = ${gitlab-unicorn-startup:output}
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614

depend  =
    ${promise-unicorn:recipe}
    ${promise-gitlab-app:recipe}
    ${promise-gitlab-shell:recipe}

    ${logrotate-entry-unicorn:recipe}
# gitlab is a service "run" under unicorn
# gitlab-shell is called by gitlab
# -> associate their logs rotation to here
    ${logrotate-entry-gitlab:recipe}


[promise-unicorn]
<= promise-byurl
615
config-command = {{ curl_bin }} --unix-socket ${unicorn:socket}  http://localhost/
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637

[promise-rakebase]
recipe  = slapos.cookbook:wrapper
# FIXME gitlab-rake is too slow to load and promise timeouts
# that's why we instantiate to <promise>.slow/ (and this way promises are not run)
wrapper-path    = !py!'${directory:promise.slow}/' + '${:_buildout_section_name_}'[8:]
rake    = ${gitlab-rake:wrapper-path}


[promise-gitlab-app]
<= promise-rakebase
command-line    = ${:rake} gitlab:app:check

[promise-gitlab-shell]
<= promise-rakebase
command-line    = ${:rake} gitlab:gitlab_shell:check

# very slow
# rake gitlab:repo:check        (fsck all repos)


[logrotate-entry-unicorn]
638
<= logrotate-entry-base
639
log     = ${unicorn:log}/*.log
640
name    = unicorn 
641 642

[logrotate-entry-gitlab]
643
<= logrotate-entry-base
644
log     = ${gitlab:log}/*.log
645
name    = gitlab
646 647

[logrotate-entry-gitlab-shell]
648
<= logrotate-entry-base
649
log     = ${gitlab-shell:log}/*.log
650
name    = gitlab-shell
651

652 653 654 655
[logrotate-entry-gitlab-workhorse]
<= logrotate-entry-base
log     = ${gitlab-workhorse-dir:log}//*.log
name    = gitlab-shell
656

657 658 659 660 661 662 663 664 665 666 667 668 669
#######################################
#   sidekiq background jobs manager   #
#######################################
[sidekiq-dir]
recipe  = slapos.cookbook:mkdirectory
log     = ${directory:log}/sidekiq

[sidekiq]
log     = ${sidekiq-dir:log}

# NOTE see queue list here:
# https://gitlab.com/gitlab-org/gitlab-ce/blob/master/Procfile
# https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-run.erb
670
# (last updated for omnibus-gitlab 8.8.9+ce.0-g25376053)
671 672 673 674
[service-sidekiq]
recipe  = slapos.cookbook:wrapper
wrapper-path    = ${directory:service}/sidekiq
command-line    =
675 676 677 678 679
# NOTE Sidekiq memory killer makes sidekiq processes to exit, or if exit request
# not handled in time, to be SIGKILL terminated, and relies on managing service
# to restart it. In slapos we don't have mechanism to set autorestart=true, nor
# bang/watchdog currently work with slapproxy, so we do the monitoring ourselves.
    {{ watcher }} 0,SIGKILL
680 681 682

    ${gitlab-sidekiq:wrapper-path}
# XXX -q runner ?  (present in gitlab-ce/Procfile  but not in omnibus)
683
# XXX -q pages -q elasticsearch ?  (present in omnibus but not in gitlab-ce -- those features are gitlab-ee only)
684 685 686 687 688 689 690
# XXX -P ?  (pidfile)
    -e production
    -r ${gitlab-work:location}
    -t ${instance-parameter:configuration.sidekiq_shutdown_timeout}
    -c ${instance-parameter:configuration.sidekiq_concurrency}
    -L ${sidekiq:log}/sidekiq.log

691
    -C ${gitlab-work:location}/config/sidekiq_queues.yml
692 693 694 695 696 697 698 699 700 701

depend  =
    ${promise-sidekiq:recipe}
    ${logrotate-entry-sidekiq:recipe}

[promise-sidekiq]
<= promise-rakebase
command-line    = ${:rake} gitlab:sidekiq:check

[logrotate-entry-sidekiq]
702
<= logrotate-entry-base
703
log     = ${sidekiq:log}/*.log
704
name    = sidekiq
705 706


707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
######################
#   Nginx frontend   #
######################

# srv/nginx/ prefix  +  etc/ log/ ...
[nginx-dir]
recipe  = slapos.cookbook:mkdirectory
srv     = ${directory:srv}/nginx
etc     = ${directory:etc}/nginx
log     = ${directory:log}/nginx

[nginx-ssl-dir]
recipe  = slapos.cookbook:mkdirectory
ssl     = ${nginx-dir:etc}/ssl
# contains https key
mode    = 0700

# self-signed certificate for https
[nginx-generate-certificate]
# NOTE there is slapos.cookbook:certificate_authority.request but it requires
# to start whole service and has up to 60 seconds latency to generate
# certificate. We only need to run 1 command to do it...
recipe  = plone.recipe.command
stop-on-error   = true
cert_file   = ${nginx-ssl-dir:ssl}/gitlab_backend.crt
key_file    = ${nginx-ssl-dir:ssl}/gitlab_backend.key

command =
    test -e ${:key_file} || \
        {{ openssl_bin }} req -newkey rsa -batch -new -x509 -days 3650 -nodes   \
        -keyout ${:key_file} -out ${:cert_file}
update-command = ${:command}


[nginx]
srv     = ${nginx-dir:srv}
etc     = ${nginx-dir:etc}
log     = ${nginx-dir:log}
ssl     = ${nginx-ssl-dir:ssl}

cert_file   = ${nginx-generate-certificate:cert_file}
key_file    = ${nginx-generate-certificate:key_file}


[nginx-symlinks]
# (nginx wants <prefix>/logs to be there from start - else it issues alarm to the log)
recipe  = cns.recipe.symlink
symlink = ${nginx:log}  = ${nginx:srv}/logs

[service-nginx]
recipe  = slapos.cookbook:wrapper
wrapper-path    = ${directory:service}/nginx
759
command-line    = {{ nginx_bin }} -p ${nginx:srv} -c ${nginx.conf:output}
760 761 762 763 764 765 766 767
depend  =
    ${nginx-symlinks:recipe}
    ${promise-nginx:recipe}
    ${logrotate-entry-nginx:recipe}


[promise-nginx]
<= promise-byurl
768 769
# XXX this depends on gitlab-workhorse being up
#     (nginx is configured to proxy all requests to gitlab-workhorse)
770
config-url     = ${backend-info:url}/users/sign_in
771
promise = check_url_available
772 773

[logrotate-entry-nginx]
774
<= logrotate-entry-base
775
log     = ${nginx:log}/*.log
776
name    = nginx
777 778 779 780 781 782 783 784 785

# base entry for clients who registers to cron
[cron-entry]
recipe  = slapos.cookbook:cron.d
# name  = <section-name>.strip_prefix('cron-entry-')
# XXX len() is not available in !py! - 11 hardcoded
name    = !py!'${:_buildout_section_name_}' [11:]
# NOTE _not_ ${service-cron:cron-entries}  - though the value is the same we do
# not want service-cron to be instantiated just if a cron-entry is registered.
786
cron-entries = ${cron:cron-entries}
787 788


789 790 791
######################
#   gitaly worker    #
######################
792

793 794 795 796 797
# https://docs.gitlab.com/ee/install/installation.html
[service-gitaly]
recipe  = slapos.cookbook:wrapper
wrapper-path    = ${directory:service}/gitaly
#command-line    = ${gitlab-work:location}/bin/daemon_with_pidfile ${gitaly:pid}
798
command-line    = {{ gitaly_location }}/gitaly ${gitaly-config.toml:output}
799

800 801
environment =
    PATH={{ bundler_1_17_3_dir }}:{{ ruby_location }}/bin:/bin:/usr/bin
802 803 804 805 806 807 808 809 810 811 812 813 814 815


# 6. on-reinstantiate actions

# NOTE here we only recompile assets. Other on-reinstantiate actions, which
# require pg and redis running, are performed as part of unicorn service -
# right before its startup (see gitlab-unicorn-startup).
[on-reinstantiate]
recipe  = plone.recipe.command
stop-on-error   = true
rake    = ${gitlab-rake:wrapper-path}
# run command on every reinstantiation
update-command = ${:command}

816 817
# https://gitlab.com/gitlab-org/gitlab-foss/issues/38457
# we need to manually install ajv@^4.0.0 with yarn to fix the bug 'yarn check failed!'
818
command =
819
    ${:rake} gitlab:assets:clean  &&
820 821 822 823 824
    ${:rake} gettext:compile RAILS_ENV=production &&
    cd ${gitlab-work:location} &&
    PATH={{ node_bin_location }}:$PATH {{ yarn_location }}/bin/yarn add ajv@^4.11.2 &&
    PATH={{ node_bin_location }}:$PATH {{ yarn_location }}/bin/yarn install --production --pure-lockfile &&
    ${:rake} gitlab:assets:compile NODE_ENV=production NODE_OPTIONS="--max_old_space_size=4096" &&
825
    true
826 827 828


# Promise, gitlab can connect to gitaly:
829
# sudo gitlab-rake gitlab:tcp_check[GITALY_SERVER_IP,GITALY_LISTEN_PORT]