RPM packaging (#122)

This commit is contained in:
Kostya Vasilyev 2019-07-25 23:47:41 +03:00 committed by Aliaksandr Valialkin
parent 17096b5750
commit 89eb6d78a4
3 changed files with 114 additions and 4 deletions

2
.gitignore vendored
View file

@ -10,4 +10,6 @@
/vmstorage-data /vmstorage-data
/vmselect-cache /vmselect-cache
/package/temp-deb-* /package/temp-deb-*
/package/temp-rpm-*
/package/*.deb /package/*.deb
/package/*.rpm

View file

@ -38,17 +38,35 @@ victoria-metrics-pure:
victoria-metrics-pure-prod: victoria-metrics-pure-prod:
APP_NAME=victoria-metrics APP_SUFFIX='-pure' DOCKER_OPTS='--env CGO_ENABLED=0' $(MAKE) app-via-docker APP_NAME=victoria-metrics APP_SUFFIX='-pure' DOCKER_OPTS='--env CGO_ENABLED=0' $(MAKE) app-via-docker
### Packaging for Debian - amd64 ### Packaging as DEB - amd64
victoria-metrics-package-deb: victoria-metrics victoria-metrics-package-deb: victoria-metrics
echo "GO_BUILDINFO:" "$(GO_BUILDINFO)"
echo "PWD:" "$(PWD)"
./package/package_deb.sh amd64 ./package/package_deb.sh amd64
### Packaging for Debian - arm64 ### Packaging as DEB - arm64
victoria-metrics-package-deb-arm64: victoria-metrics-arm64 victoria-metrics-package-deb-arm64: victoria-metrics-arm64
./package/package_deb.sh arm64 ./package/package_deb.sh arm64
### Packaging as DEB - all
victoria-metrics-package-deb-all: \ victoria-metrics-package-deb-all: \
victoria-metrics-package-deb \ victoria-metrics-package-deb \
victoria-metrics-package-deb-arm64 victoria-metrics-package-deb-arm64
### Packaging as RPM - amd64
victoria-metrics-package-rpm: victoria-metrics
./package/package_rpm.sh amd64
### Packaging as RPM - arm64
victoria-metrics-package-rpm-arm64: victoria-metrics-arm64
./package/package_rpm.sh arm64
### Packaging as RPM - all
victoria-metrics-package-rpm-all: \
victoria-metrics-package-rpm \
victoria-metrics-package-rpm-arm64
### Packaging as both DEB and RPM - all
victoria-metrics-package-deb-rpm-all: \
victoria-metrics-package-deb \
victoria-metrics-package-deb-arm64 \
victoria-metrics-package-rpm \
victoria-metrics-package-rpm-arm64

90
package/package_rpm.sh Executable file
View file

@ -0,0 +1,90 @@
#!/bin/bash
if ! which rpmbuild 2> /dev/null
then
echo "*** Fatal: please install rpmbuild"
exit 1
fi
ARCH="amd64"
if [[ $# -ge 1 ]]
then
ARCH="$1"
fi
# Map to Debian architecture
if [[ "$ARCH" == "amd64" ]]; then
RPM_ARCH=x86_64
EXENAME_SRC="victoria-metrics"
elif [[ "$ARCH" == "arm64" ]]; then
RPM_ARCH=aarch64
EXENAME_SRC="victoria-metrics-arm64"
else
echo "*** Unknown arch $ARCH"
exit 1
fi
PACKDIR="./package"
TEMPDIR="${PACKDIR}/temp-rpm-${RPM_ARCH}"
EXENAME_DST="victoria-metrics"
# Pull in version info
VERSION=`cat ${PACKDIR}/VAR_VERSION | perl -ne 'chomp and print'`
BUILD=`cat ${PACKDIR}/VAR_BUILD | perl -ne 'chomp and print'`
# Create directories
[[ -d "${TEMPDIR}" ]] && rm -rf "${TEMPDIR}"
mkdir -p "${TEMPDIR}" && echo "*** Created : ${TEMPDIR}"
echo "*** Version : ${VERSION}-${BUILD}"
echo "*** Arch : ${RPM_ARCH}"
OUT_RPM="victoria-metrics-${VERSION}-${BUILD}.${RPM_ARCH}.rpm"
echo "*** Out .rpm : ${OUT_RPM}"
cat > "${TEMPDIR}/victoria-metrics.spec" <<EOF
Summary: The best long-term remote storage for Prometheus
Name: victoria-metrics
Version: ${VERSION}
Release: ${BUILD}
License: Apache License 2.0
URL: https://victoriametrics.com/
Group: System
Packager: Aliaksandr Valialkin
Requires: libpthread
Requires: libc
%description
VictoriaMetrics is fast, cost-effective and scalable time series database. It can be used as a long-term remote storage for Prometheus.
%files
%attr(0744, root, root) /usr/sbin/*
%attr(0644, root, root) /lib/systemd/system/*
%prep
mkdir -p \$RPM_BUILD_ROOT/usr/sbin/
mkdir -p \$RPM_BUILD_ROOT/lib/systemd/system/
cp ${PWD}/bin/${EXENAME_SRC} \$RPM_BUILD_ROOT/usr/sbin/
cp ${PWD}/package/victoria-metrics.service \$RPM_BUILD_ROOT/lib/systemd/system/
%post
/usr/bin/systemctl daemon-reload
%preun
/usr/bin/systemctl stop victoria-metrics
%postun
/usr/bin/systemctl daemon-reload
EOF
rpmbuild -bb --target "${RPM_ARCH}" \
"${TEMPDIR}/victoria-metrics.spec"
cp "${HOME}/rpmbuild/RPMS/${RPM_ARCH}/${OUT_RPM}" "${PACKDIR}"
echo "*** Created : ${PACKDIR}/${OUT_RPM}"