Blob Blame History Raw
# Generated by go2rpm 1.9.0
%bcond_without check

# Results in:
# ERROR: Source RPM is not installable:
# error: Missing rpmlib features for reg-0.16.1-7.el7.x86_64:
# error:  rpmlib(DynamicBuildRequires) <= 4.15.0-1
# when `0%%{?epel}` is used.
%if 0%{?rhel}
%bcond_without bundled
%endif

# Redefine macros for EPEL
%if 0%{?epel}
  %global gobuilddir %{_builddir}/%{name}-%{version}/_build
  %global gourl https://%{goipath}
  %global gosource %{gourl}/archive/v%{version}/%{name}-%{version}.tar.gz
  %define gobuild(o:) %{expand:
    # https://bugzilla.redhat.com/show_bug.cgi?id=995136#c12
    %global _dwz_low_mem_die_limit 0
    %ifnarch ppc64
    go build -buildmode pie -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-}%{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}' -compressdwarf=false" -a -v -x %{?**};
    %else
    go build                -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-}%{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}' -compressdwarf=false" -a -v -x %{?**};
    %endif
  }
  %define goprep(:k) %{expand:
    if [[ ! -e "%{gobuilddir}/bin" ]] ; then
      install -m 0755 -vd "%{gobuilddir}/bin"
      export GOPATH="%{gobuilddir}:${GOPATH:+${GOPATH}:}/usr/share/gocode"
    fi
    if [[ ! -e "%{gobuilddir}/src/%{goipath}" ]] ; then
      install -m 0755 -vd "$(dirname %{gobuilddir}/src/%{goipath})"
      ln -fs "%{_builddir}/%{name}-%{version}" "%{gobuilddir}/src/%{goipath}"
    fi
  }
%endif

# https://github.com/genuinetools/reg
%global goipath         github.com/genuinetools/reg
Version:                0.16.1

%if !0%{?epel}
%gometa
%endif

%global common_description %{expand:
Docker registry v2 command line client and repo listing generator with security
checks.}

%global golicenses      LICENSE
%global godocs          VERSION.txt README.md

Name:       reg
Release:    %autorelease
Summary:    Docker registry v2 command line client

License:    MIT
URL:        %{gourl}
Source0:    %{gosource}

# Upstream advertises this as something that's meant to be run in a container
# and doesn't provide a systemd unit or sysV init script or sysconfig files
# so I'm providing them here.
Source1:    reg-server.service
Source2:    sysconfig.reg-server

# https://github.com/genuinetools/reg/pull/200
Patch0: fix-row-cell-index-for-server-searching-feature.patch

%if 0%{?epel}
ExclusiveArch:  %{?go_arches:%{go_arches}}%{!?go_arches:%{ix86} x86_64 aarch64 %{arm}}
BuildRequires:  %{?go_compiler:compiler(go-compiler)}%{!?go_compiler:golang}
%endif

%if 0%{?epel} && 0%{?epel} < 8
BuildRequires: systemd
%else
BuildRequires: systemd-rpm-macros
%endif

Obsoletes: reg-server < %{version}

%description %{common_description}

%prep
%if 0%{?epel}
%setup -q -n %{name}-%{version}
%endif
%goprep %{?with_bundled:-k}
%autopatch -p1
%if %{without bundled}
# Use new docker/distribution import path
sed \
    -e 's|github.com/docker/distribution|github.com/distribution/distribution/v3|' \
    -i $(find . -name '*.go')

# remove dependency to pkg/term
rm -rfv main_test>go testutils/
# Use new quay
sed \
    -e 's|github.com/coreos/clair|github.com/quay/clair/v3|' \
    -i $(find . -name '*.go')
%endif

%if %{without bundled}
%generate_buildrequires
%go_generate_buildrequires
%endif

%build
# When vendoring, use Go modules
%if %{with bundled}
%global gomodulesmode GO111MODULE=on
export GO111MODULE=on
export GOFLAGS=-mod=vendor
%endif
%gobuild -o %{gobuilddir}/bin/reg %{goipath}

%install
# Install the binaries
install -m 0755 -vd                     %{buildroot}%{_bindir}
install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_bindir}/

# Install templates and static content
mkdir -p %{buildroot}%{_sharedstatedir}/%{name}-server
install -d server/templates/ %{buildroot}/%{_sharedstatedir}/%{name}-server/templates/
install -d server/static/ %{buildroot}%{_sharedstatedir}/%{name}-server/static/
cp -p -r server/templates/* %{buildroot}%{_sharedstatedir}/%{name}-server/templates/
cp -p -r server/static/* %{buildroot}%{_sharedstatedir}/%{name}-server/static/

# Install the systemd unit
mkdir -p %{buildroot}%{_unitdir}
install -p -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/%{name}-server.service

# Install the sysconfig file
mkdir -p %{buildroot}%{_sysconfdir}/sysconfig
install -p -m 0640 %{SOURCE2} %{buildroot}%{_sysconfdir}/sysconfig/%{name}-server

%post
%systemd_post %{name}-server.service

%preun
%systemd_preun %{name}-server.service

%postun
%systemd_postun %{name}-server.service

%files
%doc README.md Dockerfile Makefile
%license LICENSE
%{_bindir}/%{name}
%{_unitdir}/%{name}-server.service
%config(noreplace) %{_sysconfdir}/sysconfig/%{name}-server
%config(noreplace) %{_sharedstatedir}/%{name}-server/static/
%config(noreplace) %{_sharedstatedir}/%{name}-server/templates/

%changelog
%autochangelog