File migrate.spec of Package golang-migrate
%define realname migrate
%define realver 4.19.0
%define srcext tar.gz
# Common info
Name: %{realname}
Version: %{realver}
Release: wiz%{?extraver:0.}1%{?dist}
License: MIT
Group: Productivity/Databases/Tools
URL: https://github.com/golang-migrate/migrate
Summary: Database migrations CLI tool
# Build-time parameters
BuildRequires: go
Source0: https://codeload.github.com/golang-migrate/migrate/%{srcext}/refs/tags/v%{realver}#/%{realname}-%{realver}%{?extraver}.%{srcext}
# go mod vendor; tar -Jcvf ../vendor-mods.tar.xz vendor; rm -rf vendor
Source1: vendor-mods.tar.xz
%description
Database migrations written in Go. Use as CLI or import as library.
* Migrate reads migrations from sources and applies them in correct order to
a database.
* Drivers are "dumb", migrate glues everything together and makes sure the
logic is bulletproof. (Keeps the drivers lightweight, too.)
* Database drivers don't assume things or try to correct user input. When in
doubt, fail.
# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver} -a1
%{__mkdir} vendor/github.com/golang-migrate
%{__ln_s} ../../.. vendor/github.com/golang-migrate/migrate
# Build step (compile/build binaries, documentation, etc)
%build
_CFLAGS="%{optflags} %{?gcc_lto}"
_LDFLAGS="-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro %{?gcc_lto}"
# Set go build variables
export GOPATH=$(pwd -P)/gomodules
export GOCACHE=$(pwd -P)/.gocache
export GOTRACEBACK=crash
export CGO_ENABLED=1
export CGO_CFLAGS="$_CFLAGS"
export CGO_CXXFLAGS="$_CFLAGS"
export CGO_LDFLAGS="$_LDFLAGS"
# Build binary
go build \
-a -v -mod=vendor -buildmode=pie -trimpath \
-gcflags=all="-c=$(nproc) -dwarf=false" \
-ldflags=all="-s -w -linkmode=external '-extldflags=$_LDFLAGS'" \
-tags=clickhouse,mongodb,mysql,postgres,sqlite3,sqlserver \
-o migrate \
./cmd/migrate
# Install built stuff
%install
%{__install} -D -m0755 migrate %{buildroot}%{_bindir}/migrate
# Files list
%files
%defattr(-,root,root)
%license LICENSE
%doc FAQ.md GETTING_STARTED.md MIGRATIONS.md cmd/migrate/README.md
%{_bindir}/migrate
%changelog