File gitaly.spec of Package gitaly

#
# spec file for package gitlab-git-http-server
#
# Copyright (c) 2022 SUSE LLC
#
# 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 https://bugs.opensuse.org/
#

%define gitaly_dir /usr/lib/gitlab/gitaly
%define gitaly_runtime_dir /var/lib/gitaly

%define pkg gitlab.com/gitlab-org/gitaly/v14

Name:           gitaly
Version:        15.1.2
Release:        0
%define pkg_version %{version}
License:        MIT
Summary:        A Git RPC service for handling all the git calls made by GitLab
Url:            https://gitlab.com/gitlab-org/gitaly/-/tags
Group:          Development/Tools/Version Control
Source:         https://gitlab.com/gitlab-org/gitaly/-/archive/v%{pkg_version}/gitaly-v%{pkg_version}.tar.bz2
Source1:        vendor.tar.xz
Source2:        %{name}.service
Source3:        series
Patch:          config.patch
Patch1:         better_socket_path.patch
Patch2:         use_correct_ruby.patch
Patch3:         fixdeps.patch
Patch4:         git2go-path.patch
BuildRequires:  golang-packaging
BuildRequires:  golang(API) >= 1.17
BuildRequires:  rsync
BuildRequires:  gitlab-common >= 14.9.0
%requires_eq    gitlab-common
Requires(pre):  gitlab-common
BuildRequires:  ruby-common-rails
BuildRequires:  pkg-config
BuildRequires:  (pkgconfig(libgit2) >= 1.1.0 with pkgconfig(libgit2) < 1.4)
BuildRequires:  pkgconfig(systemd)
#
%define rb_build_versions %{gitlab_rb_build_versions}
%define rb_build_abi      %{gitlab_rb_build_abi}
%define rb_suffix         %{gitlab_rb_suffix}
#
BuildRequires:  %{rubygem rugged:1 >= 1.2}
BuildRequires:  %{rubygem github-linguist:7 >= 7.12}
BuildRequires:  %{rubygem gitlab-markup:1.8 >= 1.8.0}
BuildRequires:  %{rubygem actionpack:6.1 >= 6.1.5}
BuildRequires:  %{rubygem rdoc >= 6.3.2}
BuildRequires:  %{rubygem gitlab-gollum-lib >= 4.2.7.10.gitlab.2}
BuildRequires:  %{rubygem gitlab-gollum-rugged_adapter >= 0.4.4.4.gitlab.1}
BuildRequires:  %{rubygem grpc:1.42 >= 1.42.0}
BuildRequires:  %{rubygem sentry-raven:3 >= 3.0}
BuildRequires:  %{rubygem faraday:1 >= 1.0}
BuildRequires:  %{rubygem rbtrace}
BuildRequires:  %{rubygem gitlab-labkit:0.23 >= 0.23.0}
BuildRequires:  %{rubygem licensee:9.14 >= 9.14.1}
BuildRequires:  %{rubygem google-protobuf:3.19 >= 3.19.0}
#
BuildRequires:  %{rubygem rack:2}
BuildRequires:  %{rubygem racc >= 1.5}
BuildRequires:  %{rubygem redis}
BuildRequires:  %{rubygem json >= 2.3.1}
BuildRequires:  %{rubygem nokogiri:1 >= 1.13}
%go_nostrip

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

%prep
%autosetup -p1 -n %{name}-v%{pkg_version} -a 1

%build
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}")' \
  $(grep -l -r 'RUBY_SUFFIX' .)

mkdir bin
export BUILDDATE="$(date -u +%%Y%%m%%d.%%H%%M%%S -r CHANGELOG.md )"
for i in $(ls cmd/) ; do

go build \
  -tags="tracer_static,tracer_static_jaeger,tracer_static_stackdriver,continuous_profiler_stackdriver,static,system_libgit2" \
  -mod=vendor \
  -buildmode=pie \
  -ldflags "-X %{pkg}/internal/version.version=%{version} -X %{pkg}/internal/version.buildtime=${BUILDDATE} -X %{pkg}/internal/version.moduleVersion=%{pkg}"\
  -o bin/$i ./cmd/$i
done
./bin/gitaly -version

pushd ruby
mv Gemfile.lock{,.upstream}
%rails_write_appinfo
# bundle.%{rb_suffix} check ||:
bundle.%{rb_suffix} exec bin/gitaly-ruby 0 /tmp/gitaly-ruby-test.socket ||:
test -e Gemfile.lock || exit 1
diff -urN Gemfile.lock{.upstream,} || :
popd
cp ruby/README.md README.ruby.md
pushd bin
ln -s gitaly-git2go-v15 gitaly-git2go
popd

%install
install -d -m 0755 %{buildroot}%{gitaly_dir}/bin/ %{buildroot}%{_sbindir}
install -D -m 0755 bin/* %{buildroot}%{gitaly_dir}/bin/
pushd ruby/
rsync -av ../VERSION .appinfo.yml bin Gemfile Gemfile.lock lib proto README.md %{buildroot}%{gitaly_dir}/
popd
install -D -m 0644 %{S:2} %{buildroot}%{_unitdir}/%{name}.service
%if 0%{?suse_version}
ln -s -f %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
%endif
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

install -D -d -m 0750 %{buildroot}%{gitaly_runtime_dir}

# START BIG SYSTEMD
%if 0%{?suse_version}
%pre
%service_add_pre %{name}.service
%endif

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

%post
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
    fi
  fi
done
# also fix bin_dir which now really needs /bin/ at the end
config_toml=/etc/gitaly/config.toml
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
fi

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

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

%files
%defattr(-,root,root)
%license LICENSE
%doc NOTICE *.md doc/
%config(noreplace) %attr(-,root,gitlab) %{_sysconfdir}/gitaly/
%if 0%{?suse_version}
%{_sbindir}/rc%{name}
%endif
%{_unitdir}/%{name}.service
%{gitaly_dir}
%dir %attr(-,gitlab,gitlab) %{gitaly_runtime_dir}
openSUSE Build Service is sponsored by