File gitlab-runner.spec of Package gitlab-runner

#
# spec file for package gitlab-runner
#
# Copyright (c) 2021 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 pkg        gitlab.com/gitlab-org/gitlab-runner
%define common_pkg %{pkg}/common
%define go_ldflags -X %{common_pkg}.NAME=gitlab-runner -X %{common_pkg}.VERSION=%{version} \
                   -X %{common_pkg}.version=%{version} -X %{common_pkg}.BUILT=${SOURCE_DATE} \
                   -w -s

Name:           gitlab-runner
Version:        17.5.1
Release:        0
Summary:        GitLab Runner
License:        MIT
ExclusiveArch:  x86_64
Url:            https://gitlab.com/gitlab-org/gitlab-runner
Group:          Development/Tools/Version Control
Source0:        %{name}-%{version}.tar.gz
Source1:vendor.tar.gz
Source2:        %{name}.sysconfig
Source3:        %{name}.service
Source4:        %{name}-sysusers.conf
Source5:        %{name}-tmpfiles.conf
Source6:        config.toml
BuildRequires:  pkgconfig(systemd)
BuildRequires:  golang-packaging
BuildRequires:  golang(API) >= 1.18
BuildRequires:  go >= 1.4.1
BuildRequires:  unzip
BuildRequires:  sysuser-tools
Provides:       %{name} = %{version}-%{release}
Provides:       user(%{name})
Provides:       group(%{name})
Obsoletes:      %{name} < %{version}-%{release}
Requires:       ca-certificates-mozilla
Requires:       hostname
Requires:       sudo
Requires(post): %fillup_prereq
%{?systemd_ordering}
%sysusers_requires
%if ! %{defined _fillupdir}
  %define _fillupdir %{_localstatedir}/adm/fillup-templates
%endif

%description
The official GitLab Runner written in Go. It runs tests and sends the results
to GitLab.

%prep
%setup -q -n %{name}-%{version} # unpack project sources
%setup -q -n %{name}-%{version} -T -D -a 1 # unpack go dependencies in vendor.tar.gz, which was prepared by the source services

%build
export SOURCE_DATE="$(TZ=UTC date -u '+%%Y-%%m-%%dT%%H:%%M:%%SZ' -r ${RPM_SOURCE_DIR}/%{name}.changes)"
go build \
  -mod=vendor \
  -buildmode=pie \
  -ldflags="%{go_ldflags}" \
  -o %{name}

./gitlab-runner --version

%install
# install config, service, user, files/dirs, binary
install -Dm 0644 %{SOURCE2} %{buildroot}%{_fillupdir}/sysconfig.%{name}
install -Dm 0644 %{SOURCE3} %{buildroot}%{_unitdir}/%{name}.service
install -Dm 0644 %{SOURCE4} %{buildroot}%{_sysusersdir}/%{name}.conf
install -Dm 0644 %{SOURCE5} %{buildroot}%{_tmpfilesdir}/%{name}.conf
install -Dm 0644 %{SOURCE6} %{buildroot}%{_sysconfdir}/%{name}/config.toml
install -Dm 0755 %{name} %{buildroot}%{_sbindir}/%{name}

# create rc-symlink
pushd %{buildroot}%{_sbindir}
ln -s service rc%{name}
popd

%pre
%sysusers_create_package %{name} %{SOURCE4}
%service_add_pre %{name}.service

%post
%fillup_only -n %{name}
%tmpfiles_create %{_tmpfilesdir}/%{name}.conf
%service_add_post %{name}.service

%preun
%service_del_preun %{name}.service

%postun
%service_del_postun %{name}.service

%files
%doc README.md
%license LICENSE
%{_sbindir}/%{name}
%{_sbindir}/rc%{name}
%attr(0750,root,%{name}) %config(noreplace) %{_sysconfdir}/%{name}
%attr(0640,root,%{name}) %config(noreplace) %{_sysconfdir}/%{name}/config.toml
%{_fillupdir}/sysconfig.%{name}
%{_unitdir}/%{name}.service
%{_sysusersdir}/%{name}.conf
%{_tmpfilesdir}/%{name}.conf
%ghost %{_sharedstatedir}/%{name}

%changelog
openSUSE Build Service is sponsored by