From 8c3629a89204d18909a8f7534373ce905e3798c4 Mon Sep 17 00:00:00 2001 From: Kostya Vasilyev Date: Mon, 22 Jul 2019 17:12:48 +0300 Subject: [PATCH] Debian packaging (#116) * initial commit of deb packaging * Incorporated feedback from @valyala: - Put data directory under /var/lib - More beef in systemd file - Packaging for arm64 - Package all target which builds and packages both amd64 and arm64 * Remove PIDFile from systemd unit, useless * per PR feedback, move debian specific files into deb subdirectory Updates #107 . --- .gitignore | 2 + app/victoria-metrics/Makefile | 15 +++++ package/VAR_BUILD | 1 + package/VAR_VERSION | 1 + package/deb/conffile | 0 package/deb/control | 7 +++ package/deb/postinst | 5 ++ package/deb/postrm | 0 package/package_deb.sh | 103 +++++++++++++++++++++++++++++++ package/victoria-metrics.service | 16 +++++ 10 files changed, 150 insertions(+) create mode 100644 package/VAR_BUILD create mode 100644 package/VAR_VERSION create mode 100644 package/deb/conffile create mode 100644 package/deb/control create mode 100644 package/deb/postinst create mode 100644 package/deb/postrm create mode 100755 package/package_deb.sh create mode 100644 package/victoria-metrics.service diff --git a/.gitignore b/.gitignore index b5246b398..9879e811b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ /victoria-metrics-data /vmstorage-data /vmselect-cache +/package/temp-deb-* +/package/*.deb diff --git a/app/victoria-metrics/Makefile b/app/victoria-metrics/Makefile index 706439fe1..79b82274f 100644 --- a/app/victoria-metrics/Makefile +++ b/app/victoria-metrics/Makefile @@ -25,3 +25,18 @@ victoria-metrics-arm: victoria-metrics-arm64: CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOARCH=arm64 GO111MODULE=on go build -mod=vendor -ldflags "$(GO_BUILDINFO)" -o bin/victoria-metrics-arm64 ./app/victoria-metrics + +### Packaging for Debian - amd64 +victoria-metrics-package-deb: victoria-metrics + echo "GO_BUILDINFO:" "$(GO_BUILDINFO)" + echo "PWD:" "$(PWD)" + ./package/package_deb.sh amd64 + +### Packaging for Debian - arm64 +victoria-metrics-package-deb-arm64: victoria-metrics-arm64 + ./package/package_deb.sh arm64 + +victoria-metrics-package-deb-all: \ + victoria-metrics-package-deb \ + victoria-metrics-package-deb-arm64 + diff --git a/package/VAR_BUILD b/package/VAR_BUILD new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/package/VAR_BUILD @@ -0,0 +1 @@ +1 diff --git a/package/VAR_VERSION b/package/VAR_VERSION new file mode 100644 index 000000000..bd8bf882d --- /dev/null +++ b/package/VAR_VERSION @@ -0,0 +1 @@ +1.7.0 diff --git a/package/deb/conffile b/package/deb/conffile new file mode 100644 index 000000000..e69de29bb diff --git a/package/deb/control b/package/deb/control new file mode 100644 index 000000000..6a1666eba --- /dev/null +++ b/package/deb/control @@ -0,0 +1,7 @@ +Package: victoria-metrics +Maintainer: Aliaksandr Valialkin +Depends: libc6 (>= 2.7-1) +Section: net +Priority: optional +Homepage: https://github.com/VictoriaMetrics/VictoriaMetrics +Description: VictoriaMetrics is fast, cost-effective and scalable time series database. It can be used as a long-term remote storage for Prometheus. diff --git a/package/deb/postinst b/package/deb/postinst new file mode 100644 index 000000000..c913aa083 --- /dev/null +++ b/package/deb/postinst @@ -0,0 +1,5 @@ +#!/bin/sh +set -e + +# Reload systemd unit +systemctl daemon-reload diff --git a/package/deb/postrm b/package/deb/postrm new file mode 100644 index 000000000..e69de29bb diff --git a/package/package_deb.sh b/package/package_deb.sh new file mode 100755 index 000000000..d3e2272c4 --- /dev/null +++ b/package/package_deb.sh @@ -0,0 +1,103 @@ +#!/bin/bash + +ARCH="amd64" +if [[ $# -ge 1 ]] +then + ARCH="$1" +fi + +# Map to Debian architecture +if [[ "$ARCH" == "amd64" ]]; then + DEB_ARCH=amd64 + EXENAME_SRC="victoria-metrics" +elif [[ "$ARCH" == "arm64" ]]; then + DEB_ARCH=arm64 + EXENAME_SRC="victoria-metrics-arm64" +else + echo "*** Unknown arch $ARCH" + exit 1 +fi + +PACKDIR="./package" +TEMPDIR="${PACKDIR}/temp-deb-${DEB_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}" + +mkdir -p "${TEMPDIR}/usr/sbin/" +mkdir -p "${TEMPDIR}/lib/systemd/system/" + +echo "*** Version : ${VERSION}-${BUILD}" +echo "*** Arch : ${DEB_ARCH}" + +OUT_DEB="victoria-metrics_${VERSION}-${BUILD}_$DEB_ARCH.deb" + +echo "*** Out .deb : ${OUT_DEB}" + +# Copy the binary + +cp "./bin/${EXENAME_SRC}" "${TEMPDIR}/usr/sbin/${EXENAME_DST}" +file "${TEMPDIR}/usr/sbin/${EXENAME_DST}" + +# Copy supporting files + +cp "${PACKDIR}/victoria-metrics.service" "${TEMPDIR}/lib/systemd/system/" + +# Generate debian-binary + +echo "2.0" > "${TEMPDIR}/debian-binary" + +# Generate control + +echo "Version: $VERSION-$BUILD" > "${TEMPDIR}/control" +echo "Installed-Size:" `du -sb "${TEMPDIR}" | awk '{print int($1/1024)}'` >> "${TEMPDIR}/control" +echo "Architecture: $DEB_ARCH" >> "${TEMPDIR}/control" +cat "${PACKDIR}/deb/control" >> "${TEMPDIR}/control" + +# Copy conffile + +cp "${PACKDIR}/deb/conffile" "${TEMPDIR}/conffile" + +# Copy postinst and postrm + +cp "${PACKDIR}/deb/postinst" "${TEMPDIR}/postinst" +cp "${PACKDIR}/deb/postrm" "${TEMPDIR}/postrm" + +( + # Generate md5 sums + + cd "${TEMPDIR}" + + find ./usr ./lib -type f | while read i ; do + md5sum "$i" | sed 's/\.\///g' >> md5sums + done + + # Archive control + + chmod 644 control md5sums + chmod 755 postrm postinst + fakeroot -- tar -c --xz -f ./control.tar.xz ./control ./md5sums ./postinst ./postrm + + # Archive data + + fakeroot -- tar -c --xz -f ./data.tar.xz ./usr ./lib + + # Make final archive + + fakeroot -- ar -cr "${OUT_DEB}" debian-binary control.tar.xz data.tar.xz +) + +ls -lh "${TEMPDIR}/${OUT_DEB}" + +cp "${TEMPDIR}/${OUT_DEB}" "${PACKDIR}" + +echo "*** Created : ${PACKDIR}/${OUT_DEB}" diff --git a/package/victoria-metrics.service b/package/victoria-metrics.service new file mode 100644 index 000000000..7c45bd34d --- /dev/null +++ b/package/victoria-metrics.service @@ -0,0 +1,16 @@ +[Unit] +Description=VictoriaMetrics is a fast, cost-effective and scalable time series database. + +[Service] +Type=simple +StartLimitBurst=5 +StartLimitInterval=0 +Restart=on-failure +RestartSec=1 +ExecStart=/usr/sbin/victoria-metrics -storageDataPath /var/lib/victoria-metrics -retentionPeriod 12 +ExecStop=/bin/kill -s SIGTERM $MAINPID +LimitNOFILE=32000 +LimitNPROC=32000 + +[Install] +WantedBy=multi-user.target