# GitLab "switch-softwaretype" instance
[buildout]
extends =
  ${gitlab-parameters.cfg:target}
parts =
    switch-softwaretype

# std stuff for slapos instance
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true


[switch-softwaretype]
recipe = slapos.cookbook:switch-softwaretype
gitlab = instance-gitlab.cfg:output
gitlab-export = instance-gitlab-export.cfg:output
RootSoftwareInstance = $${:gitlab}
# TODO -import, -pull-backup


[worker-processes]
recipe = slapos.recipe.build
init =
  import multiprocessing
  cpu_count = multiprocessing.cpu_count()
  # automatically load all available CPUs
  options['unicorn-worker-processes'] = cpu_count + 1
  options['nginx-worker-processes'] = cpu_count


[slap-configuration]
# std stuff to fetch slapos instance parameters
recipe  = slapos.cookbook:slapconfiguration
computer= $${slap-connection:computer-id}
partition=$${slap-connection:partition-id}
url     = $${slap-connection:server-url}
key     = $${slap-connection:key-file}
cert    = $${slap-connection:cert-file}

# autogenerated gitlab instance parameters
<= gitlab-parameters

# adjust/override some default settings:

configuration.unicorn_worker_processes = $${worker-processes:unicorn-worker-processes}
configuration.nginx_worker_processes   = $${worker-processes:nginx-worker-processes}


# gitlab non-native parameters
configuration.icp_license  =


# macro: render instance-*.cfg from instance-*.cfg.in
[instance-cfg]
recipe  = slapos.recipe.template:jinja2
mode    = 0644
output= $${buildout:directory}/$${:_buildout_section_name_}
context =
    import os os
    import pwd pwd

    key bin_directory           buildout:bin-directory
    key eggs_directory          buildout:eggs-directory
    key develop_eggs_directory  buildout:develop-eggs-directory
    raw gitlab_repository_location          ${gitlab-repository:location}
    raw gitlab_shell_repository_location    ${gitlab-shell-repository:location}
    section instance_parameter_dict slap-configuration

# program binaries
    raw bash_bin                    ${bash:location}/bin/bash
    raw bzip2_location              ${bzip2:location}
    raw bundler_4gitlab             ${bundler-4gitlab:bundle}
    raw bundler_1_17_3_dir          ${bundler-4gitlab:bundle1.17.3}
    raw coreutils_location          ${coreutils:location}
    raw curl_bin                    ${curl:location}/bin/curl
    raw dcron_bin                   ${dcron-output:crond}
    raw git                         ${git:location}/bin/git
    raw git_location                ${git:location}
    raw gitaly_location             ${gitaly-repository:location}
    raw gitlab_export               ${gitlab-export:output}
    raw gitlab_workhorse            ${gowork:bin}/gitlab-workhorse
    raw gopath_bin                  ${gowork:bin}
    raw gunzip_bin                  ${gzip:location}/bin/gunzip
    raw grep_location               ${grep:location}
    raw gzip_bin                    ${gzip:location}/bin/gzip
    raw gzip_location               ${gzip:location}
    raw logrotate_bin               ${logrotate:location}/usr/sbin/logrotate
    raw nginx_bin                   ${nginx-output:nginx}
    raw nginx_mime_types            ${nginx-output:mime}
    raw node_bin_location           ${nodejs-8.12.0:location}/bin/
    raw openssl_bin                 ${openssl-output:openssl}
    raw postgresql_location         ${postgresql10:location}
    raw redis_binprefix             ${redis28:location}/bin
    raw ruby_location               ${bundler-4gitlab:ruby-location}
    raw tar_location                ${tar:location}
    raw watcher                     ${watcher:output}
    raw xnice_repository_location   ${xnice-repository:location}
    raw yarn_location               ${yarn:location}

# config files
    raw database_yml_in             ${database.yml.in:target}
    raw gitconfig_in                ${gitconfig.in:target}
    raw monitor_template            ${monitor2-template:output}
    raw gitlab_shell_config_yml_in  ${gitlab-shell-config.yml.in:target}
    raw gitlab_unicorn_startup_in   ${gitlab-unicorn-startup.in:target}
    raw gitlab_yml_in               ${gitlab.yml.in:target}
    raw gitaly_config_toml_in       ${gitaly-config.toml.in:target}
    raw macrolib_cfg_in             ${macrolib.cfg.in:target}
    raw nginx_conf_in               ${nginx.conf.in:target}
    raw nginx_gitlab_http_conf_in   ${nginx-gitlab-http.conf.in:target}
    raw rack_attack_rb_in           ${rack_attack.rb.in:target}
    raw resque_yml_in               ${resque.yml.in:target}
    raw smtp_settings_rb_in         ${smtp_settings.rb.in:target}
    raw gitlab_restore_sh_in        ${template-gitlab-resiliency-restore.sh.in:target}
    raw unicorn_rb_in               ${unicorn.rb.in:target}

    $${:context-extra}
context-extra =

[instance-gitlab.cfg]
<= instance-cfg
url = ${instance-gitlab.cfg.in:target}

[instance-gitlab-export.cfg]
<= instance-cfg
url = ${instance-gitlab-export.cfg.in:target}
context-extra =
    raw instance_gitlab_cfg         $${instance-gitlab.cfg:output}