From f88fe1092d09fe1a0b79d07a41b5256a77011077 Mon Sep 17 00:00:00 2001 From: Dmitriy Zabolotskiy Date: Tue, 1 Nov 2022 11:29:14 +0300 Subject: [PATCH] [#223] Debian packaging Debian package includes: - user creation; - directories and permissions; - unit file for systemd Signed-off-by: Dmitriy Zabolotskiy --- .gitignore | 3 +++ Makefile | 19 +++++++++++++ debian/changelog | 5 ++++ debian/control | 15 +++++++++++ debian/copyright | 23 ++++++++++++++++ debian/neofs-http-gw.dirs | 2 ++ debian/neofs-http-gw.docs | 4 +++ debian/neofs-http-gw.examples | 1 + debian/neofs-http-gw.install | 2 ++ debian/neofs-http-gw.postinst | 51 +++++++++++++++++++++++++++++++++++ debian/neofs-http-gw.postrm | 41 ++++++++++++++++++++++++++++ debian/neofs-http-gw.preinst | 35 ++++++++++++++++++++++++ debian/neofs-http-gw.prerm | 38 ++++++++++++++++++++++++++ debian/neofs-http-gw.service | 16 +++++++++++ debian/rules | 16 +++++++++++ debian/source/format | 1 + docs/building-deb-package.md | 46 +++++++++++++++++++++++++++++++ 17 files changed, 318 insertions(+) create mode 100644 debian/changelog create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/neofs-http-gw.dirs create mode 100644 debian/neofs-http-gw.docs create mode 100644 debian/neofs-http-gw.examples create mode 100644 debian/neofs-http-gw.install create mode 100644 debian/neofs-http-gw.postinst create mode 100644 debian/neofs-http-gw.postrm create mode 100644 debian/neofs-http-gw.preinst create mode 100644 debian/neofs-http-gw.prerm create mode 100644 debian/neofs-http-gw.service create mode 100755 debian/rules create mode 100644 debian/source/format create mode 100644 docs/building-deb-package.md diff --git a/.gitignore b/.gitignore index 2726d2d..ebadc7a 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,6 @@ testfile coverage.txt coverage.html + +# debhelpers +**/.debhelper diff --git a/Makefile b/Makefile index 005fa28..3bea558 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,13 @@ BINS = $(BINDIR)/neofs-http-gw .PHONY: all $(BINS) $(DIRS) dep docker/ test cover fmt image image-push dirty-image lint docker/lint version clean +# .deb package versioning +OS_RELEASE = $(shell lsb_release -cs) +PKG_VERSION ?= $(shell echo $(VERSION) | sed "s/^v//" | \ + sed -E "s/(.*)-(g[a-fA-F0-9]{6,8})(.*)/\1\3~\2/" | \ + sed "s/-/~/")-${OS_RELEASE} +.PHONY: debpackage debclean + # Make all binaries all: $(BINS) @@ -111,4 +118,16 @@ clean: rm -rf vendor rm -rf $(BINDIR) +# Package for Debian +debpackage: + dch --package neofs-http-gw \ + --controlmaint \ + --newversion $(PKG_VERSION) \ + --distribution $(OS_RELEASE) \ + "Please see CHANGELOG.md for code changes for $(VERSION)" + dpkg-buildpackage --no-sign -b + +debclean: + dh clean + include help.mk diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..eae76ab --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +neofs-http-gw (0.0.0) stable; urgency=medium + + * Please see CHANGELOG.md + + -- NeoSPCC Wed, 24 Aug 2022 18:29:49 +0300 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..e428567 --- /dev/null +++ b/debian/control @@ -0,0 +1,15 @@ +Source: neofs-http-gw +Section: neofs +Priority: optional +Maintainer: NeoSPCC +Build-Depends: debhelper-compat (= 13), dh-sysuser, git, devscripts +Standards-Version: 4.5.1 +Homepage: https://fs.neo.org/ +Vcs-Git: https://github.com/nspcc-dev/neofs-http-gw.git +Vcs-Browser: https://github.com/nspcc-dev/neofs-http-gw + +Package: neofs-http-gw +Architecture: any +Depends: ${misc:Depends} +Description: NeoFS HTTP Gateway bridges NeoFS internal protocol and HTTP standard. + diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..0849725 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,23 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: neofs-http-gw +Upstream-Contact: tech@nspcc.ru +Source: https://github.com/nspcc-dev/neofs-http-gw + +Files: * +Copyright: 2018-2022 NeoSPCC (@nspcc-dev), contributors of neofs-http-gw project + (https://github.com/nspcc-dev/neofs-http-gw/blob/master/CREDITS.md) + + +License: GPL-3 + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; version 3. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program or at /usr/share/common-licenses/GPL-3. + If not, see . diff --git a/debian/neofs-http-gw.dirs b/debian/neofs-http-gw.dirs new file mode 100644 index 0000000..9bacd8b --- /dev/null +++ b/debian/neofs-http-gw.dirs @@ -0,0 +1,2 @@ +etc/neofs +srv/neofs_cache diff --git a/debian/neofs-http-gw.docs b/debian/neofs-http-gw.docs new file mode 100644 index 0000000..884d34d --- /dev/null +++ b/debian/neofs-http-gw.docs @@ -0,0 +1,4 @@ +docs/gate-configuration.md +README.md +CREDITS.md +CONTRIBUTING.md diff --git a/debian/neofs-http-gw.examples b/debian/neofs-http-gw.examples new file mode 100644 index 0000000..dd04e98 --- /dev/null +++ b/debian/neofs-http-gw.examples @@ -0,0 +1 @@ +config/* diff --git a/debian/neofs-http-gw.install b/debian/neofs-http-gw.install new file mode 100644 index 0000000..afd9c36 --- /dev/null +++ b/debian/neofs-http-gw.install @@ -0,0 +1,2 @@ +bin/neofs-http-gw usr/bin +config/config.yaml etc/neofs/http diff --git a/debian/neofs-http-gw.postinst b/debian/neofs-http-gw.postinst new file mode 100644 index 0000000..ef4dbc0 --- /dev/null +++ b/debian/neofs-http-gw.postinst @@ -0,0 +1,51 @@ +#!/bin/sh +# postinst script for neofs-http-gw +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `configure' +# * `abort-upgrade' +# * `abort-remove' `in-favour' +# +# * `abort-remove' +# * `abort-deconfigure' `in-favour' +# `removing' +# +# for details, see https://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + configure) + USERNAME=http + id -u neofs-$USERNAME >/dev/null 2>&1 || useradd -s /usr/sbin/nologin -d /srv/neofs_cache --system -M -U -c "NeoFS HTTP gateway" neofs-$USERNAME + if ! dpkg-statoverride --list /etc/neofs/$USERNAME >/dev/null; then + chown -f root:neofs-$USERNAME /etc/neofs/$USERNAME + chown -f root:neofs-$USERNAME /etc/neofs/$USERNAME/config.yaml || true + chmod -f 0750 /etc/neofs/$USERNAME + chmod -f 0640 /etc/neofs/$USERNAME/config.yaml || true + fi + USERDIR=$(getent passwd "neofs-$USERNAME" | cut -d: -f6) + if ! dpkg-statoverride --list neofs-$USERDIR >/dev/null; then + chown -f neofs-$USERNAME: $USERDIR + fi + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/neofs-http-gw.postrm b/debian/neofs-http-gw.postrm new file mode 100644 index 0000000..02d5ccf --- /dev/null +++ b/debian/neofs-http-gw.postrm @@ -0,0 +1,41 @@ +#!/bin/sh +# postrm script for neofs-http-gw +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `remove' +# * `purge' +# * `upgrade' +# * `failed-upgrade' +# * `abort-install' +# * `abort-install' +# * `abort-upgrade' +# * `disappear' +# +# for details, see https://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + purge) + rm -rf /srv/neofs_cache + ;; + + remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + ;; + + *) + echo "postrm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/neofs-http-gw.preinst b/debian/neofs-http-gw.preinst new file mode 100644 index 0000000..e832e16 --- /dev/null +++ b/debian/neofs-http-gw.preinst @@ -0,0 +1,35 @@ +#!/bin/sh +# preinst script for neofs-http-gw +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `install' +# * `install' +# * `upgrade' +# * `abort-upgrade' +# for details, see https://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + install|upgrade) + ;; + + abort-upgrade) + ;; + + *) + echo "preinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/neofs-http-gw.prerm b/debian/neofs-http-gw.prerm new file mode 100644 index 0000000..10b59ec --- /dev/null +++ b/debian/neofs-http-gw.prerm @@ -0,0 +1,38 @@ +#!/bin/sh +# prerm script for neofs-http-gw +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `remove' +# * `upgrade' +# * `failed-upgrade' +# * `remove' `in-favour' +# * `deconfigure' `in-favour' +# `removing' +# +# for details, see https://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + remove|upgrade|deconfigure) + ;; + + failed-upgrade) + ;; + + *) + echo "prerm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/neofs-http-gw.service b/debian/neofs-http-gw.service new file mode 100644 index 0000000..d7ce5eb --- /dev/null +++ b/debian/neofs-http-gw.service @@ -0,0 +1,16 @@ +[Unit] +Description=NeoFS HTTP Gateway +Requires=network.target + +[Service] +Type=simple +ExecStart=/usr/bin/neofs-http-gw --config /etc/neofs/http/config.yaml +User=neofs-http +Group=neofs-http +WorkingDirectory=/srv/neofs_cache +Restart=always +RestartSec=5 +PrivateTmp=true + +[Install] +WantedBy=multi-user.target diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..cbeb2d1 --- /dev/null +++ b/debian/rules @@ -0,0 +1,16 @@ +#!/usr/bin/make -f + +# Do not try to strip Go binaries and do not run test +export DEB_BUILD_OPTIONS := nostrip nocheck +SERVICE = neofs-http-gw + +%: + dh $@ + +override_dh_installsystemd: + dh_installsystemd --no-enable --no-start $(SERVICE).service + +override_dh_installchangelogs: + dh_installchangelogs -k CHANGELOG.md + + diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/docs/building-deb-package.md b/docs/building-deb-package.md new file mode 100644 index 0000000..26a77a2 --- /dev/null +++ b/docs/building-deb-package.md @@ -0,0 +1,46 @@ +# Building Debian package on host + +## Prerequisites + +For now, we're assuming building for Debian 11 (stable) x86_64. + +Go version 18.4 or later should already be installed, i.e. this runs +successfully: + +* `make all` + +## Installing packaging dependencies + +```shell +$ sudo apt install debhelper-compat dh-sequence-bash-completion devscripts +``` + +Warining: number of package installed is pretty large considering dependecies. + +## Package building + +```shell +$ make debpackage +``` + +## Leftovers cleaning + +```shell +$ make debclean +``` +or +```shell +$ dh clean +``` + +# Package versioning + +By default, package version is based on product version and may also contain git +tags and hashes. + +Package version could be overwritten by setting `PKG_VERSION` variable before +build, Debian package versioning rules should be respected. + +```shell +$ PKG_VERSION=0.32.0 make debpackge +```