Skip to content

Commit

Permalink
Merge pull request #117 from adjust/github-action-build-deb-package
Browse files Browse the repository at this point in the history
GitHub workflow: Building deb package on release
  • Loading branch information
teerapatrk authored Jan 13, 2023
2 parents c6e7c9e + 8f41e7e commit d119875
Show file tree
Hide file tree
Showing 13 changed files with 268 additions and 9 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/build-package.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 11 additions & 8 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> 31 Aug 2022 09:05:00 +0000
24 changes: 23 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12
29 changes: 29 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Source: schaufel
Section: admin
Priority: optional
Maintainer: Robert Abraham <[email protected]>
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
41 changes: 41 additions & 0 deletions debian/postinst
Original file line number Diff line number Diff line change
@@ -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}
32 changes: 32 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions debian/schaufel.dirs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/etc/schaufel
/var/lib/schaufel
/var/log/schaufel
1 change: 1 addition & 0 deletions debian/schaufel.docs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
schaufel/*
1 change: 1 addition & 0 deletions debian/schaufel.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
schaufel /usr/bin/
11 changes: 11 additions & 0 deletions debian/schaufel.logrotate
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/var/log/schaufel/*.log {
su schaufel schaufel
daily
rotate 7
dateext
copytruncate
compress
delaycompress
missingok
notifempty
}
2 changes: 2 additions & 0 deletions debian/schaufel.manpages
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
man1/schaufel.1
man5/schaufel.conf.5
26 changes: 26 additions & 0 deletions debian/schaufel.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[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
SyslogIdentifier=%p

## systemd.service
Type=simple
ExecStart=/usr/bin/schaufel -l /var/log/schaufel/%p.log -C /etc/schaufel/%p.conf
Restart=no
SuccessExitStatus=0
TimeoutStopSec=1800

## systemd.kill
KillSignal=SIGTERM
SendSIGKILL=no

[Install]
WantedBy=multi-user.target

0 comments on commit d119875

Please sign in to comment.