<commit_before>{%- set root_dir = salt['pillar.get']('gitlab:lookup:root_dir', '/home/git') %}
{%- set sockets_dir = salt['pillar.get']('gitlab:lookup:sockets_dir', root_dir ~ '/var/sockets') %}
{%- set lib_dir = salt['pillar.get']('gitlab:lookup:lib_dir', root_dir ~ '/libraries') %}

{%- set gitaly_dir = lib_dir ~ "/gitaly" %}

{%- if salt['pillar.get']('gitlab:archives:enabled', false) %}
    {%- set gitaly_dir_content = gitaly_dir ~ '/' ~ salt['pillar.get']('gitlab:archives:sources:gitaly:content') %}
{%- else %}
    {%- set gitaly_dir_content = gitaly_dir %}
{%- endif %}

{%- if salt['pillar.get']('gitlab:archives:enabled', false) %}
gitaly-fetcher:
  archive.extracted:
    - name: {{ gitaly_dir }}
    - source: {{ salt['pillar.get']('gitlab:archives:sources:gitaly:source') }}
    - source_hash: md5={{ salt['pillar.get']('gitlab:archives:sources:gitaly:md5') }}
    - archive_format: tar
    - if_missing: {{ gitaly_dir_content }}
    - keep: True

gitaly-chown:
  file.directory:
    - name: {{ gitaly_dir }}
    - user: git
    - group: git
    - recurse:
      - user
    - onchanges:
      - archive: gitaly-fetcher
{%- else %}
gitaly-fetcher:
  git.latest:
    - name: https://gitlab.com/gitlab-org/gitaly.git
    - rev: {{ salt['pillar.get']('gitlab:gitaly_version') }}
    - target: {{ gitaly_dir_content }}
    - user: git
    - force: True
    - require:
      - pkg: gitlab-deps
      - pkg: git
      - sls: gitlab.ruby
      - file: git-home
{%- endif %}

gitaly-private-sockets-dir:
  file.directory:
    - name: {{ sockets_dir }}/private
    - user: git
    - group: git
    - mode: 700

gitaly-bin-dir:
  file.directory:
    - name: {{ root_dir }}/gitaly
    - user: git
    - group: git
    - mode: 750

gitaly-make:
  cmd.run:
    - name: make build install DESTDIR={{ root_dir }}/gitaly PREFIX=
    - user: git
    - cwd: {{ gitaly_dir_content }}
    - onchanges:
      - gitaly-fetcher
    - require:
      - file: gitaly-bin-dir

# https://gitlab.com/gitlab-org/gitaly/blob/master/config.toml.example
# gitaly looks for configuration in the same directory it is running from
gitaly-config:
  file.managed:<commit_msg>gitaly now requires proxy for installation<commit_after>{%- set root_dir = salt['pillar.get']('gitlab:lookup:root_dir', '/home/git') %}
{%- set sockets_dir = salt['pillar.get']('gitlab:lookup:sockets_dir', root_dir ~ '/var/sockets') %}
{%- set lib_dir = salt['pillar.get']('gitlab:lookup:lib_dir', root_dir ~ '/libraries') %}

{%- set gitaly_dir = lib_dir ~ "/gitaly" %}

{%- if salt['pillar.get']('gitlab:archives:enabled', false) %}
    {%- set gitaly_dir_content = gitaly_dir ~ '/' ~ salt['pillar.get']('gitlab:archives:sources:gitaly:content') %}
{%- else %}
    {%- set gitaly_dir_content = gitaly_dir %}
{%- endif %}

{%- if salt['pillar.get']('gitlab:archives:enabled', false) %}
gitaly-fetcher:
  archive.extracted:
    - name: {{ gitaly_dir }}
    - source: {{ salt['pillar.get']('gitlab:archives:sources:gitaly:source') }}
    - source_hash: md5={{ salt['pillar.get']('gitlab:archives:sources:gitaly:md5') }}
    - archive_format: tar
    - if_missing: {{ gitaly_dir_content }}
    - keep: True

gitaly-chown:
  file.directory:
    - name: {{ gitaly_dir }}
    - user: git
    - group: git
    - recurse:
      - user
    - onchanges:
      - archive: gitaly-fetcher
{%- else %}
gitaly-fetcher:
  git.latest:
    - name: https://gitlab.com/gitlab-org/gitaly.git
    - rev: {{ salt['pillar.get']('gitlab:gitaly_version') }}
    - target: {{ gitaly_dir_content }}
    - user: git
    - force: True
    - require:
      - pkg: gitlab-deps
      - pkg: git
      - sls: gitlab.ruby
      - file: git-home
{%- endif %}

gitaly-private-sockets-dir:
  file.directory:
    - name: {{ sockets_dir }}/private
    - user: git
    - group: git
    - mode: 700

gitaly-bin-dir:
  file.directory:
    - name: {{ root_dir }}/gitaly
    - user: git
    - group: git
    - mode: 750

gitaly-make:
  cmd.run:
    - name: make build install DESTDIR={{ root_dir }}/gitaly PREFIX=
    - user: git
    - cwd: {{ gitaly_dir_content }}
    - env:
      {%- if salt['pillar.get']('gitlab:proxy:address') %}
      - HTTP_PROXY: {{ pillar.gitlab.proxy.address }}
      - HTTPS_PROXY: {{ pillar.gitlab.proxy.address }}
      {%- endif %}
    - onchanges:
      - gitaly-fetcher
    - require:
      - file: gitaly-bin-dir

# https://gitlab.com/gitlab-org/gitaly/blob/master/config.toml.example
# gitaly looks for configuration in the same directory it is running from
gitaly-config:
  file.managed:
{'fraction_non_alphanumeric': 0.17846900507390248, 'fraction_numerical': 0.003529671299360247, 'mean_word_length': 2.952920662598082, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7440633', 'n_tokens_mistral': 1813, 'n_tokens_neox': 1737, 'n_words': 294}