diff --git a/.github/workflows/pkg.yml b/.github/workflows/pkg.yml index 1db370ea..2db7e730 100644 --- a/.github/workflows/pkg.yml +++ b/.github/workflows/pkg.yml @@ -45,6 +45,11 @@ on: - 'README.md' - 'tests/e2e/**' +defaults: + run: + # see: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell + shell: bash --noprofile --norc -eo pipefail -x {0} + jobs: # Use the cargo-deb Rust create to build a Debian package for installing # Krill. See: https://github.com/mmstick/cargo-deb @@ -59,7 +64,7 @@ jobs: "debian:10", ] env: - CARGO_DEB_VER: 1.23.1 + CARGO_DEB_VER: 05545d4 # A Krill version of the form 'x.y.z-plus' denotes a dev build that is # newer than the released x.y.z version but is not yet a new release. NEXT_VER_LABEL: plus @@ -99,7 +104,7 @@ jobs: - name: Install compilation and other dependencies run: | - apt-get install -y build-essential jq libssl-dev lintian pkg-config + apt-get install -y build-essential jq libssl-dev lintian pkg-config env: DEBIAN_FRONTEND: noninteractive @@ -127,7 +132,7 @@ jobs: - name: Install Cargo Deb if: steps.cache-cargo-deb.outputs.cache-hit != 'true' run: | - cargo install cargo-deb --version=$CARGO_DEB_VER + cargo install --git https://github.com/ximon18/cargo-deb.git --branch dh_installsystemd_and_changelog_fix --rev $CARGO_DEB_VER cargo-deb # Instruct cargo-deb to build the Debian package using the config section # in Cargo.toml for the specified "variant". @@ -160,7 +165,7 @@ jobs: # to. In this case we do NOT want dash '-' to become '~' because `-` # is treated as higher and tilda is treated as lower. KRILL_VER=$(cargo read-manifest | jq -r '.version' | tr '-' '~') - KRILL_VER=$(echo $KRILL_VER | sed -e "s/~$NEXT_VER_LABEL/-$NEXT_VER_LABEL/") + DEB_KRILL_VER=$(echo $KRILL_VER | sed -e "s/~$NEXT_VER_LABEL/-$NEXT_VER_LABEL/") case ${MATRIX_IMAGE} in ubuntu:16.04) OS_REL=xenial ;; ubuntu:18.04) OS_REL=bionic ;; @@ -169,7 +174,20 @@ jobs: debian:10) OS_REL=buster ;; *) echo 2>&1 "ERROR: Unexpected matrix image"; exit 1 ;; esac - DEB_VER="${KRILL_VER}-1${OS_REL}" + + case ${{ github.event_name }} in + pull_request) MAINTAINER="${{ github.actor }} " ;; + push) MAINTAINER="${{ github.event.pusher.name }} <${{ github.event.pusher.email }}>" ;; + *) echo 2>&1 "ERROR: Unexpected GitHub Actions event"; exit 1 ;; + esac + + # Generate the changelog file that Debian packages are required to have. + # See: https://www.debian.org/doc/manuals/maint-guide/dreq.en.html#changelog + echo "krill (${DEB_KRILL_VER}) unstable; urgency=medium" >debian/changelog + echo " * See: https://github.com/NLnetLabs/krill/releases/tag/v${KRILL_VER}" >>debian/changelog + echo " -- maintainer ${MAINTAINER} $(date --rfc-email)" >>debian/changelog + + DEB_VER="${DEB_KRILL_VER}-1${OS_REL}" cargo deb --variant $DEB_NAME --deb-version $DEB_VER -v env: MATRIX_IMAGE: ${{ matrix.image }} @@ -179,7 +197,7 @@ jobs: # Policy) say they should be compressed. - name: Verify the DEB package run: | - lintian -v target/debian/*.deb || true + lintian -v target/debian/*.deb # Upload the produced DEB package. The artifact will be available # via the GH Actions job summary and build log pages, but only to @@ -253,6 +271,7 @@ jobs: - name: Launch LXC container run: | + # security.nesting=true is needed to avoid error "Failed to set up mount # namespacing: Permission denied" in a Debian 10 container. sg lxd -c "lxc launch $LXC_IMAGE -c security.nesting=true testcon" diff --git a/Cargo.toml b/Cargo.toml index 9c3542da..867ce6fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,31 +87,25 @@ priority = "optional" section = "net" extended-description-file = "debian/description.txt" license-file = ["LICENSE", "0"] -maintainer-scripts = "debian/scripts/" depends = "$auto, adduser, libssl1.1" - -[package.metadata.deb.variants.ubuntu2004] +maintainer-scripts = "debian/" +changelog = "debian/changelog" # this will be generated by the pkg workflow +copyright = "Copyright (c) 2019, NLnet Labs. All rights reserved." assets = [ ["target/release/krill", "/usr/bin/krill", "755"], ["target/release/krillc", "/usr/bin/krillc", "755"], ["defaults/krill.conf", "/usr/share/doc/krill/krill.conf", "644"], ["doc/krill.1", "/usr/share/man/man1/krill.1", "644"], ["doc/krillc.1", "/usr/share/man/man1/krillc.1", "644"], - ["debian/assets/krill.service.ubuntu2004", "/lib/systemd/system/krill.service", "644"] + ["debian/krill.service.preset", "/lib/systemd/system-preset/50-krill.preset", "644"], ] -# Variant of the Debian packaging configuration that uses a slightly simpler -# systemd service unit file because Ubuntu 18.04 doesn't support newer features -# supported by Ubuntu 20.04. -[package.metadata.deb.variants.ubuntu1804] -assets = [ - ["target/release/krill", "/usr/bin/krill", "755"], - ["target/release/krillc", "/usr/bin/krillc", "755"], - ["defaults/krill.conf", "/usr/share/doc/krill/krill.conf", "644"], - ["doc/krill.1", "/usr/share/man/man1/krill.1", "644"], - ["doc/krillc.1", "/usr/share/man/man1/krillc.1", "644"], - ["debian/assets/krill.service.ubuntu1804", "/lib/systemd/system/krill.service", "644"] -] +[package.metadata.deb.systemd-units] +unit-name = "krill" +enable = false +start = true +restart-after-upgrade = false +stop-on-upgrade = true # Variant of the Debian packaging configuration that: # a) statically links with OpenSSL when building a Debian package because the @@ -123,38 +117,16 @@ assets = [ [package.metadata.deb.variants.ubuntu1604] features = [ "static-openssl" ] depends = "$auto, adduser" -assets = [ - ["target/release/krill", "/usr/bin/krill", "755"], - ["target/release/krillc", "/usr/bin/krillc", "755"], - ["defaults/krill.conf", "/usr/share/doc/krill/krill.conf", "644"], - ["doc/krill.1", "/usr/share/man/man1/krill.1", "644"], - ["doc/krillc.1", "/usr/share/man/man1/krillc.1", "644"], - ["debian/assets/krill.service.ubuntu1604", "/lib/systemd/system/krill.service", "644"] -] -# Debian 10 variant, identical to the Ubuntu 1804 variant. -[package.metadata.deb.variants.debian10] -assets = [ - ["target/release/krill", "/usr/bin/krill", "755"], - ["target/release/krillc", "/usr/bin/krillc", "755"], - ["defaults/krill.conf", "/usr/share/doc/krill/krill.conf", "644"], - ["doc/krill.1", "/usr/share/man/man1/krill.1", "644"], - ["doc/krillc.1", "/usr/share/man/man1/krillc.1", "644"], - ["debian/assets/krill.service.ubuntu1804", "/lib/systemd/system/krill.service", "644"] -] +[package.metadata.deb.variants.ubuntu1804] + +[package.metadata.deb.variants.ubuntu2004] -# Debian 9 variant, identical to the Ubuntu 1604 variant. [package.metadata.deb.variants.debian9] features = [ "static-openssl" ] depends = "$auto, adduser" -assets = [ - ["target/release/krill", "/usr/bin/krill", "755"], - ["target/release/krillc", "/usr/bin/krillc", "755"], - ["defaults/krill.conf", "/usr/share/doc/krill/krill.conf", "644"], - ["doc/krill.1", "/usr/share/man/man1/krill.1", "644"], - ["doc/krillc.1", "/usr/share/man/man1/krillc.1", "644"], - ["debian/assets/krill.service.ubuntu1604", "/lib/systemd/system/krill.service", "644"] -] + +[package.metadata.deb.variants.debian10] # END DEBIAN PACKAGING # ------------------------------------------------------------------------------ diff --git a/debian/krill-debian10.krill.service b/debian/krill-debian10.krill.service new file mode 120000 index 00000000..9e5bebd1 --- /dev/null +++ b/debian/krill-debian10.krill.service @@ -0,0 +1 @@ +krill-ubuntu1804.krill.service \ No newline at end of file diff --git a/debian/krill-debian9.krill.service b/debian/krill-debian9.krill.service new file mode 120000 index 00000000..105ab10b --- /dev/null +++ b/debian/krill-debian9.krill.service @@ -0,0 +1 @@ +krill-ubuntu1604.krill.service \ No newline at end of file diff --git a/debian/assets/krill.service.ubuntu1604 b/debian/krill-ubuntu1604.krill.service similarity index 100% rename from debian/assets/krill.service.ubuntu1604 rename to debian/krill-ubuntu1604.krill.service diff --git a/debian/assets/krill.service.ubuntu1804 b/debian/krill-ubuntu1804.krill.service similarity index 96% rename from debian/assets/krill.service.ubuntu1804 rename to debian/krill-ubuntu1804.krill.service index 408d940a..abadc832 100644 --- a/debian/assets/krill.service.ubuntu1804 +++ b/debian/krill-ubuntu1804.krill.service @@ -20,7 +20,6 @@ ProtectKernelModules=yes ProtectKernelTunables=yes ProtectSystem=strict ReadWritePaths=/var/lib/krill/ -ConfigurationDirectory=krill RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 RestrictNamespaces=yes RestrictRealtime=yes diff --git a/debian/assets/krill.service.ubuntu2004 b/debian/krill-ubuntu2004.krill.service similarity index 96% rename from debian/assets/krill.service.ubuntu2004 rename to debian/krill-ubuntu2004.krill.service index 7407b744..78d607cc 100644 --- a/debian/assets/krill.service.ubuntu2004 +++ b/debian/krill-ubuntu2004.krill.service @@ -20,7 +20,6 @@ ProtectKernelModules=yes ProtectKernelTunables=yes ProtectSystem=strict ReadWritePaths=/var/lib/krill/ -ConfigurationDirectory=krill RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 RestrictNamespaces=yes RestrictRealtime=yes diff --git a/debian/krill.service.preset b/debian/krill.service.preset new file mode 100644 index 00000000..f24946d7 --- /dev/null +++ b/debian/krill.service.preset @@ -0,0 +1 @@ +disable krill.service \ No newline at end of file diff --git a/debian/scripts/postinst b/debian/postinst similarity index 99% rename from debian/scripts/postinst rename to debian/postinst index bece4c38..43e1bcda 100755 --- a/debian/scripts/postinst +++ b/debian/postinst @@ -43,3 +43,5 @@ configure) create_first_time_configuration ;; esac + +#DEBHELPER# diff --git a/debian/scripts/postrm b/debian/postrm similarity index 95% rename from debian/scripts/postrm rename to debian/postrm index cc544754..100dac14 100644 --- a/debian/scripts/postrm +++ b/debian/postrm @@ -12,4 +12,6 @@ purge) rm ${KRILL_CONF} fi ;; -esac \ No newline at end of file +esac + +#DEBHELPER# diff --git a/debian/preinst b/debian/preinst new file mode 100644 index 00000000..99e7a38f --- /dev/null +++ b/debian/preinst @@ -0,0 +1,18 @@ +#!/bin/sh -e + +if [ "$1" = "upgrade" ] ; then + if [ -d /run/systemd/system ]; then + if [ -n "$2" ]; then + # special case to handle <= 0.7.3 versions of the deb package + # failing to stop krill in the prerm script so we handle it in the + # >= 0.7.3 preinst script instead. + case $2 in + 0.7.0*|0.7.1*|0.7.2*|0.7.3*) + deb-systemd-invoke stop krill.service >/dev/null || true + ;; + esac + fi + fi +fi + +#DEBHELPER# diff --git a/debian/scripts/prerm b/debian/scripts/prerm deleted file mode 100755 index 720364f6..00000000 --- a/debian/scripts/prerm +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh -set -e - -# lintian warns maintainer-script-calls-systemctl. -# at https://lintian.debian.org/tags/maintainer-script-calls-systemctl.html it -# explains that deb-systemd-helper should be used instead, but we are not using -# debhelper, we are using cargo-deb, so we have to manage systemd ourselves. -uninstall_service_unit() { - if systemctl is-enabled krill.service >/dev/null; then - systemctl disable --now krill.service - fi -} - -case "$1" in -remove|purge) - uninstall_service_unit - ;; -esac \ No newline at end of file