File etcd.spec of Package etcd
%define realname etcd
%define realver 3.5.15
%define srcext tar.gz
%define etcd_user etcd
%define etcd_group %{etcd_user}
%define etcd_home %{_localstatedir}/lib/%{name}
%define numcpus %(/usr/bin/getconf _NPROCESSORS_ONLN)
# Common info
Name: %{realname}
Version: %{realver}
Release: wiz%{?extraver:0.}1%{?dist}
License: Apache-2.0
Group: Productivity/Clustering/HA
URL: https://etcd.io/
Summary: Distributed reliable key-value store for the most critical data
# Install-time parameters
Provides: %{realname} = %{version}-%{release}
# Build-time parameters
BuildRequires: go >= 1.21.12
BuildRoot: %{_tmppath}/%{name}-root
Source0: https://codeload.github.com/etcd-io/etcd/%{srcext}/refs/tags/v%{realver}#/%{realname}-%{realver}%{?extraver}.%{srcext}
# Vendored modules: ( export GOCACHE=$(pwd -P)/.gocache; export GOMODCACHE=$(pwd -P)/mod ; go get -d && cd tools/mod && go get -d && cd - && cd etcdctl && go get -d && cd - && tar -Jcvf ../mods.tar.xz mod .gocache )
Source1: mods.tar.xz
# SystemD unit file
Source11: etcd.service
%description
etcd is a distributed reliable key-value store for the most critical data of
a distributed system, with a focus on being:
* Simple: well-defined, user-facing API (gRPC)
* Secure: automatic TLS with optional client cert authentication
* Fast: benchmarked 10,000 writes/sec
* Reliable: properly distributed using Raft
etcd is written in Go and uses the Raft consensus algorithm to manage
a highly-available replicated log.
# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver} -a1
%{__sed} -ri \
-e '/^GIT_SHA=/ s/=.+$/=v%{version}/' \
-e '/^GOFAIL_VERSION=/ s/=.+$/=v0.1.0/' \
-e '/^\s+tests_build\s/ d' \
build.sh
# Build step (compile/build binaries, documentation, etc)
%build
export GO_BUILD_FLAGS='-v -mod=mod -buildmode=pie -gcflags=all=-c=%{numcpus} -gcflags=all=-complete -gcflags=all=-dwarf=false'
export GO_LDFLAGS='-s -w'
export GOCACHE=$(pwd -P)/.gocache
export GOMODCACHE=$(pwd -P)/mod
export GOTRACEBACK=crash
export CGO_ENABLED=1
export CGO_CFLAGS='%{optflags}'
export CGO_CXXFLAGS='%{optflags}'
export CGO_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro'
export FORCE_HOST_GO=1
source ./build.sh
set +o xtrace
etcd_build
tools_build
# Install built stuff
%install
# Directories
%{__install} -d -m0755 %{buildroot}%{_bindir}
%{__install} -d -m0755 %{buildroot}%{etcd_home}
# Binaries
BINS=(
bin/etcd
bin/etcdctl
bin/etcdutl
bin/tools/etcd-dump-db
bin/tools/etcd-dump-logs
)
for BIN in ${BINS[@]}; do
%{__install} "$BIN" %{buildroot}%{_bindir}/${BIN##*/}
done
# Configuration (environment) file
%{__sed} -ri \
-e 's|^(data-dir:)|\1 %{etcd_home}/data|' \
-e 's|^(wal-dir:)|\1 %{etcd_home}/wal|' \
-e 's|^(enable-v2:)|\1 false|' \
-e 's|^(enable-pprof:)|\1 false|' \
-e 's|^(log-level:)|\1 info|' \
etcd.conf.yml.sample
%{__install} -D -m0644 etcd.conf.yml.sample %{buildroot}%{_sysconfdir}/%{name}/etcd.conf.yml
# systemd unit
%{__install} -D -m0644 %{S:11} %{buildroot}%{_unitdir}/%{name}.service
# Files list
%files
%defattr(-,root,root)
%license LICENSE
%doc MAINTAINERS README.md
%dir %{_sysconfdir}/%{name}
%config(noreplace) %{_sysconfdir}/%{name}/etcd.conf.yml
%{_bindir}/etcd*
%{_unitdir}/%{name}.service
%dir %attr(0750,%{etcd_user},%{etcd_group}) %{etcd_home}
%pre
/usr/sbin/groupadd -r %{etcd_group} &>/dev/null ||:
/usr/sbin/useradd -g %{etcd_group} -s /bin/false -r -c "etcd" -d %{etcd_home} %{etcd_user} &>/dev/null ||:
%if "%{expand:%_vendor}" == "suse"
%{service_add_pre %{name}.service}
%endif
%if "%{expand:%_vendor}" == "suse"
%post
%{service_add_post %{name}.service}
%preun
%{service_del_preun %{name}.service}
%postun
%{service_del_postun %{name}.service}
%endif
%changelog