File gitaly.spec of Package gitaly

# spec file for package gitlab-git-http-server
# Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

%if 0%{?suse_version} > 1230 || 0%{?rhel_version} > 6 || 0%{?centos_version} > 6 || 0%{?fedora_version} >= 20 || 0%{?el7}%{?fc20}%{?fc21}%{?fc22}%{?fc23}
%bcond_without systemd
%bcond_with    systemd

%define gitaly_dir /usr/lib/gitlab/gitaly

Name:           gitaly
Version:        1.83.0
Release:        0
License:        MIT
Summary:        A Git RPC service for handling all the git calls made by GitLab
Group:          Development/Tools/Version Control
Source1:        vendor.tar.xz
Source2:        %{name}.service
Patch:          config.patch
Patch1:         better_socket_path.patch
Patch2:         use_correct_ruby.patch
Patch3:         fixdeps.patch
Patch4:         bump-git2go.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  git-core >= 2.24.0
Requires:       git-core >= 2.24.0
BuildRequires:  golang-packaging
BuildRequires:  golang(API) >= 1.13
BuildRequires:  rsync
BuildRequires:  gitlab-common
%requires_eq    gitlab-common
Requires(pre):  gitlab-common
BuildRequires:  ruby-common-rails
BuildRequires:  pkg-config
BuildRequires:  pkgconfig(libgit2)
BuildRequires:  pkgconfig(systemd)
%define rb_build_versions ruby26
%define rb_build_abi      ruby:2.6.0
%define rb_suffix    ruby2.6
BuildRequires:  %{rubygem bundler >= 2}
BuildRequires:  %{rubygem rugged:0 >= 0.28}
BuildRequires:  %{rubygem github-linguist:7 >= 7.5}
BuildRequires:  %{rubygem gitlab-markup:1.7 >= 1.7.0}
BuildRequires:  %{rubygem actionpack:5.2 >= 5.2.3}
BuildRequires:  %{rubygem rdoc:6 >= 6.1}
BuildRequires:  %{rubygem gitlab-gollum-lib:4.2.7 >=}
BuildRequires:  %{rubygem gitlab-gollum-rugged_adapter:0.4.4 >=}
BuildRequires:  %{rubygem grpc:1.24 >= 1.24.0}
BuildRequires:  %{rubygem sentry-raven:2.9 >= 2.9.0}
BuildRequires:  %{rubygem faraday:0 >= 0.12}
BuildRequires:  %{rubygem rbtrace}
BuildRequires:  %{rubygem gitlab-labkit:0.8 >= 0.8.0}
BuildRequires:  %{rubygem licensee:8.9 >= 8.9.0}
BuildRequires:  %{rubygem google-protobuf:3.8 >= 3.8.0}

Gitaly is a Git RPC service for handling all the git calls made by GitLab.

%autosetup -p1 -n %{name}-v%{version} -a 1

export LC_ALL="en_US.UTF-8"
export LANG="$LC_ALL"
ruby.%{rb_suffix} -r rubygems -p -i -e \
  '$_.gsub!(/\A#!.*ruby/, "#!#{Gem.ruby}")' \
  $(grep '#!.*ruby' -rl .)

ruby.%{rb_suffix}             -p -i -e \
  '$_.gsub!(/RUBY_SUFFIX/, "%{rb_suffix}")' \
  internal/linguist/linguist.go internal/rubyserver/rubyserver.go
mkdir -p _build/src/${PKG}
tar -cf - --exclude _build --exclude .git . | (cd _build/src/${PKG} && tar -xf -)
pushd _build
export GOPATH="$PWD"
export BUILDDATE="$(date -u +%%Y%%m%%d.%%H%%M%%S -r ../ )"
go install -mod=vendor -buildmode=pie -ldflags "-X ${PKG}/internal/version.version=%{version} -X ${PKG}/internal/version.buildtime=${BUILDDATE}" ${PKG}/cmd/...
pushd ruby
mv Gemfile.lock{,.upstream}
bundle.%{rb_suffix} exec bin/gitaly-ruby 0 /tmp/gitaly-ruby-test.socket ||:
diff -urN Gemfile.lock{.upstream,} || :
cp ruby/

install -d -m 0755 %{buildroot}%{gitaly_dir}/bin/ %{buildroot}%{_sbindir}
install -D -m 0755 _build/bin/*                                     %{buildroot}%{gitaly_dir}/bin/
pushd ruby/
rsync -av ../VERSION .appinfo.yml bin Gemfile Gemfile.lock git-hooks lib gitlab-shell proto %{buildroot}%{gitaly_dir}/
install -D -m 0644 %{S:2} %{buildroot}%{_unitdir}/%{name}.service
%if 0%{?suse_version}
ln -s -f %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
install -D -m 0640 config.toml.example %{buildroot}%{_sysconfdir}/gitaly/config.toml
chmod -R u=rwX,g=rX,o=                 %{buildroot}%{_sysconfdir}/gitaly/
find %{buildroot} -name spec -print0 | xargs -r0 rm -rv

%if 0%{?suse_version}
%service_add_pre %{name}.service

%if 0%{?suse_version}
%service_del_preun %{name}.service
%systemd_preun %{name}.service

for gitlab_yml in /srv/www/vhosts/gitlab-ce/config/gitlab.yml /etc/gitaly/config.toml ; do
  if [ -e ${gitlab_yml} ] ; then
    if grep -q %{_datadir}/gitlab/gitaly ${gitlab_yml} ; then
      echo "patching path to gitaly in ${gitlab_yml}"
      perl -p -i.update -e 's|%{_datadir}/gitlab/gitaly|%{gitaly_dir}|g' ${gitlab_yml}
      diff -urN ${gitlab_yml}.update ${gitlab_yml} ||:
      rm ${gitlab_yml}.update
# also fix bin_dir which now really needs /bin/ at the end
if ! grep -q '^bin_dir = "/usr/lib/gitlab/gitaly/bin/"' ${config_toml} ; then
  perl -p -i.update -e 's|^bin_dir = .*|bin_dir = "/usr/lib/gitlab/gitaly/bin/"|g' ${config_toml}
  diff -urN ${config_toml}.update ${config_toml} ||:
  rm ${config_toml}.update

%if 0%{?suse_version}
%service_add_post %{name}.service
%systemd_post %{name}.service

%if 0%{?suse_version}
%service_del_postun %{name}.service
%systemd_postun_with_restart %{name}.service

%license LICENSE
%doc NOTICE *.md doc/
%config(noreplace) %attr(-,root,gitlab) %{_sysconfdir}/gitaly/
%if 0%{?suse_version}