From 806f2a7c118dbbb875bab0cbfbb025fe132e7a72 Mon Sep 17 00:00:00 2001 From: Teerapatr K Date: Mon, 12 Dec 2022 13:30:13 +0100 Subject: [PATCH 1/2] GitHub actions: Building deb package on release --- .github/workflows/build-package.yml | 87 +++++++++++++++++++++++++++++ ChangeLog | 19 ++++--- Makefile | 24 +++++++- debian/compat | 1 + debian/control | 29 ++++++++++ debian/postinst | 41 ++++++++++++++ debian/rules | 32 +++++++++++ debian/schaufel.dirs | 3 + debian/schaufel.docs | 1 + debian/schaufel.install | 1 + debian/schaufel.logrotate | 11 ++++ debian/schaufel.manpages | 2 + debian/schaufel.service | 28 ++++++++++ 13 files changed, 270 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/build-package.yml create mode 100644 debian/compat create mode 100644 debian/control create mode 100755 debian/postinst create mode 100755 debian/rules create mode 100644 debian/schaufel.dirs create mode 100644 debian/schaufel.docs create mode 100644 debian/schaufel.install create mode 100644 debian/schaufel.logrotate create mode 100644 debian/schaufel.manpages create mode 100644 debian/schaufel.service diff --git a/.github/workflows/build-package.yml b/.github/workflows/build-package.yml new file mode 100644 index 0000000..aa99423 --- /dev/null +++ b/.github/workflows/build-package.yml @@ -0,0 +1,87 @@ +--- +name: Build install package + +on: + release: + types: + - published + + workflow_dispatch: + +defaults: + run: + shell: bash + +env: + LC_ALL: C.UTF-8 + +jobs: + build-deb-gcc: + name: Build (${{ matrix.os }}, ${{ matrix.cc }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: + - ubuntu-20.04 + # # Disable jammy + # - ubuntu-22.04 + cc: + - gcc + # # Disable Clang (enable required: matrix.include.cc: clang) + # - clang + include: + - cc: gcc + LDFLAGS: '' + CFLAGS: '-O2' + # # Disable Clang (enable required: matrix.cc.clang) + # - cc: clang + # # # Disable ASan, incompatible w/ Valgrind test + # # # https://github.com/google/sanitizers/issues/856#issuecomment-924966052 + # # LDFLAGS: '-fsanitize=address -fno-omit-frame-pointer' + # # CFLAGS: '-Og -fsanitize=address -fno-omit-frame-pointer' + # LDFLAGS: '' + # CFLAGS: '-O2' + env: + CC: ${{ matrix.cc }} + LDFLAGS: ${{ matrix.LDFLAGS }} + CFLAGS: ${{ matrix.CFLAGS }} + steps: + - name: Checkout source code + uses: actions/checkout@v3 + + - name: Fetch update package information + run: sudo apt-get update --assume-yes + + - name: Install build-essential and tools + run: sudo apt-get install --assume-yes build-essential debhelper dpkg-dev valgrind clang + + - name: Install package dependencies + run: sudo apt-get install --assume-yes libconfig-dev libconfig++-dev libhiredis-dev libjson-c-dev libpq-dev librdkafka-dev + + - name: Run testsuite + run: make test + + - name: Compile and build bianry + run: make + + - name: Build package + run: make package-deb + + - name: Upload package(s) + uses: actions/upload-artifact@v3 + with: + name: Packages + path: | + schaufel_*.buildinfo + schaufel_*.changes + schaufel_*.deb + + - name: Release package(s) + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: | + schaufel_*.buildinfo + schaufel_*.changes + schaufel_*.deb diff --git a/ChangeLog b/ChangeLog index 31df96b..60ad9f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,11 @@ -v0.11 - - support for callbacks via metadata (transactional producers) - - full autoconf build system - - full endian.h portability - - full freebsd compatibility - - deprecated hash_r gnuism - - deprecated asprintf gnuism - - various smaller bugfixes +schaufel (0.11) unstable; urgency=low + + * support for callbacks via metadata (transactional producers) (Closes: #97) + * full autoconf build system + * full endian.h portability + * full freebsd compatibility + * deprecated hash_r gnuism (Closes: #108) + * deprecated asprintf gnuism (Closes: #108) + * various smaller bugfixes + + -- Robert Abraham 31 Aug 2022 09:05:00 +0000 diff --git a/Makefile b/Makefile index d9d8538..c70aaf4 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,13 @@ DOCS = $(patsubst man/%, doc/%.pdf , $(wildcard man/*)) SCHAUFEL_VERSION ?= 0.11 +ARCH = $(shell uname -m) +# OS_ID = $(shell cat /etc/os-release | awk -F= '{if ($$1=="ID") print $$2}') +# OS_VERSION_ID = $(shell cat /etc/os-release | awk -F= '{if ($$1=="VERSION_ID") print $$2}') +CC_VERSION = $(shell $(CC) -dumpversion | awk -F. '{print $$1}') +# PACKAGE_DEB_DIR = schaufel-$(SCHAUFEL_VERSION)-$(OS_ID)$(OS_VERSION_ID)-$(CC)$(CC_VERSION)-$(ARCH) +PACKAGE_DEB_DIR = schaufel-$(SCHAUFEL_VERSION)-$(CC)$(CC_VERSION)-$(ARCH) + all: release docs: $(DOCS) @@ -47,7 +54,7 @@ release: before_release $(OBJ) out_release test: clean_release before_release $(OBJ_TEST) $(OBJ_BIN_TEST) before_release: - mkdir -p obj/utils obj/hooks bin + mkdir -p obj/utils obj/hooks bin $(PACKAGE_DEB_DIR) clean: clean_release @@ -56,6 +63,7 @@ clean_release: rm -rf bin rm -rf $(OBJDIR) rm -rf doc/*.pdf + rm -rf $(PACKAGE_DEB_DIR) out_release: $(OBJ) $(LD) $(LIBDIR) $(OBJ) $(LIB) -o $(OUT) @@ -73,3 +81,17 @@ install: all $(INSTALL) -m 0644 -t $(DESTDIR)$(DOCDIR) doc/* $(INSTALL) -m 0644 man/schaufel.1 $(DESTDIR)$(MAN1DIR)/schaufel.1 $(INSTALL) -m 0644 man/schaufel.conf.5 $(DESTDIR)$(MAN5DIR)/schaufel.conf.5 + +package-deb: all + $(INSTALL) bin/schaufel $(PACKAGE_DEB_DIR)$(DESTDIR)$(BINDIR)/schaufel + $(INSTALL) -m 0644 -t $(PACKAGE_DEB_DIR)$(DESTDIR)$(DOCDIR) doc/* + $(INSTALL) -m 0644 man/schaufel.1 $(PACKAGE_DEB_DIR)$(DESTDIR)$(MAN1DIR)/schaufel.1 + $(INSTALL) -m 0644 man/schaufel.conf.5 $(PACKAGE_DEB_DIR)$(DESTDIR)$(MAN5DIR)/schaufel.conf.5 + + $(INSTALL) -m 0644 -t $(PACKAGE_DEB_DIR)/DEBIAN debian/* + $(INSTALL) -m 0775 debian/postinst $(PACKAGE_DEB_DIR)/DEBIAN/postinst + $(INSTALL) -m 0775 debian/rules $(PACKAGE_DEB_DIR)/DEBIAN/rules + $(INSTALL) -m 0644 ChangeLog $(PACKAGE_DEB_DIR)/DEBIAN/changelog + $(INSTALL) -m 0644 LICENSE $(PACKAGE_DEB_DIR)/DEBIAN/copyright + ln -s DEBIAN $(PACKAGE_DEB_DIR)/debian + cd $(PACKAGE_DEB_DIR) && dpkg-buildpackage --build=binary diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..48082f7 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +12 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..2d2cc15 --- /dev/null +++ b/debian/control @@ -0,0 +1,29 @@ +Source: schaufel +Section: admin +Priority: optional +Maintainer: Robert Abraham +Build-Depends: debhelper (>= 12), + dpkg-dev, + libconfig-dev, + libconfig++-dev, + libhiredis-dev, + libjson-c-dev, + libpq-dev, + librdkafka-dev +Standards-Version: 0.11 + +Package: schaufel +Version: 0.11 +Architecture: any +Multi-Arch: foreign +Pre-Depends: dh-systemd (>= 12), + dpkg +Depends: libconfig9 (>= 1.5~), + libhiredis0.14 (>= 0.14~), + libjson-c4 (>= 0.13~), + libpq5 (>= 12.~), + librdkafka1 (>= 1.2~) +Description: schaufel aims to be a swiss army knife for moving data. + It can take data from list-like sources and insert them into list-like sinks. + In other words, it can take data from a redis list and insert it into kafka or vice versa. +Homepage: https://github.com/adjust/schaufel diff --git a/debian/postinst b/debian/postinst new file mode 100755 index 0000000..7733f06 --- /dev/null +++ b/debian/postinst @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +set -e + +#DEBHELPER# + +PACKAGE_NAME="schaufel" +PACKAGE_UID=997 +PACKAGE_USER="schaufel" +PACKAGE_GID=997 +PACKAGE_GROUP="schaufel" +CONF_DIR="/etc/${PACKAGE_NAME}" +WORK_DIR="/var/lib/${PACKAGE_NAME}" +LOG_DIR="/var/log/${PACKAGE_NAME}" + +## Create group if not exist +if ! getent group | grep --quiet "^${PACKAGE_GROUP}:" ; then + echo -n "Adding system group ${PACKAGE_GROUP} .." + addgroup --quiet --system \ + --gid ${PACKAGE_GID} \ + ${PACKAGE_GROUP} 2>/dev/null || true + echo ".. done" +fi + +## Create user if not exist +if ! getent passwd | grep --quiet "^${PACKAGE_USER}:" ; then + echo -n "Adding system user ${PACKAGE_USER} .." + adduser --quiet --system \ + --home /dev/null \ + --shell /usr/sbin/nologin \ + --no-create-home \ + --uid ${PACKAGE_UID} \ + --gecos "Shovel data around" \ + --ingroup ${PACKAGE_GROUP} \ + --disabled-password \ + ${PACKAGE_USER} 2>/dev/null || true + echo ".. done" +fi + +## Create other directories and files and adjsut permissions +mkdir --parents --mode 0750 ${CONF_DIR} ${WORK_DIR} ${LOG_DIR} +chown --recursive ${PACKAGE_USER}:${PACKAGE_GROUP} ${CONF_DIR} ${WORK_DIR} ${LOG_DIR} diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..1fd0a14 --- /dev/null +++ b/debian/rules @@ -0,0 +1,32 @@ +#!/usr/bin/make -f +# See debhelper(7) (uncomment to enable) +# output every command that modifies files on the build system. +export DH_VERBOSE = 1 + + +# see FEATURE AREAS in dpkg-buildflags(1) +export DEB_BUILD_MAINT_OPTIONS = hardening=+all + +# see ENVIRONMENT in dpkg-buildflags(1) +# package maintainers to append CFLAGS +export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic +# package maintainers to append LDFLAGS +export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed + +%: + dh $@ + +override_dh_install: + dh_install --sourcedir=usr/local/bin + +override_dh_installdocs: + dh_installdocs --sourcedir=usr/local/share/doc + +override_dh_installinit: + dh_installinit --onlyscripts + +override_dh_installman: + dh_installman --sourcedir=usr/local/share/man + +override_dh_installsystemd: + dh_installsystemd --no-enable --no-restart-after-upgrade --no-restart-on-upgrade --no-start schaufel.service diff --git a/debian/schaufel.dirs b/debian/schaufel.dirs new file mode 100644 index 0000000..2814789 --- /dev/null +++ b/debian/schaufel.dirs @@ -0,0 +1,3 @@ +/etc/schaufel +/var/lib/schaufel +/var/log/schaufel diff --git a/debian/schaufel.docs b/debian/schaufel.docs new file mode 100644 index 0000000..2913918 --- /dev/null +++ b/debian/schaufel.docs @@ -0,0 +1 @@ +schaufel/* diff --git a/debian/schaufel.install b/debian/schaufel.install new file mode 100644 index 0000000..03aa90b --- /dev/null +++ b/debian/schaufel.install @@ -0,0 +1 @@ +schaufel /usr/bin/ diff --git a/debian/schaufel.logrotate b/debian/schaufel.logrotate new file mode 100644 index 0000000..07e1525 --- /dev/null +++ b/debian/schaufel.logrotate @@ -0,0 +1,11 @@ +/var/log/schaufel/*.log { + su schaufel schaufel + daily + rotate 7 + dateext + copytruncate + compress + delaycompress + missingok + notifempty +} diff --git a/debian/schaufel.manpages b/debian/schaufel.manpages new file mode 100644 index 0000000..d168a25 --- /dev/null +++ b/debian/schaufel.manpages @@ -0,0 +1,2 @@ +man1/schaufel.1 +man5/schaufel.conf.5 diff --git a/debian/schaufel.service b/debian/schaufel.service new file mode 100644 index 0000000..1e1f634 --- /dev/null +++ b/debian/schaufel.service @@ -0,0 +1,28 @@ +[Unit] +Description=Schaufel +Documentation=https://github.com/adjust/schaufel +Requires=network.target +After=network.target + +[Service] +## systemd.exec +WorkingDirectory=/var/lib/schaufel +User=schaufel +Group=schaufel +Environment=SCHAUFEL_CONFIG_FILE=/etc/schaufel/schaufel.conf +Environment=SCHAUFEL_OPTS="-l /var/log/schaufel/schaufel.log" +SyslogIdentifier=%p + +## systemd.service +Type=simple +ExecStart=/usr/bin/schaufel ${SCHAUFEL_OPTS} -C ${SCHAUFEL_CONFIG_FILE} +Restart=no +SuccessExitStatus=0 +TimeoutStopSec=1800 + +## systemd.kill +KillSignal=SIGTERM +SendSIGKILL=no + +[Install] +WantedBy=multi-user.target From 8f41e7eb0c162e1107f78e7ae977233154fcea81 Mon Sep 17 00:00:00 2001 From: Teerapatr K Date: Mon, 9 Jan 2023 11:54:06 +0100 Subject: [PATCH 2/2] schaufel.service: Use systemd specifier in files name --- debian/schaufel.service | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/debian/schaufel.service b/debian/schaufel.service index 1e1f634..d56d569 100644 --- a/debian/schaufel.service +++ b/debian/schaufel.service @@ -9,13 +9,11 @@ After=network.target WorkingDirectory=/var/lib/schaufel User=schaufel Group=schaufel -Environment=SCHAUFEL_CONFIG_FILE=/etc/schaufel/schaufel.conf -Environment=SCHAUFEL_OPTS="-l /var/log/schaufel/schaufel.log" SyslogIdentifier=%p ## systemd.service Type=simple -ExecStart=/usr/bin/schaufel ${SCHAUFEL_OPTS} -C ${SCHAUFEL_CONFIG_FILE} +ExecStart=/usr/bin/schaufel -l /var/log/schaufel/%p.log -C /etc/schaufel/%p.conf Restart=no SuccessExitStatus=0 TimeoutStopSec=1800