Skip to content

Commit

Permalink
Merge pull request #13 from koalo/develop/docker-build
Browse files Browse the repository at this point in the history
Tested the build and was able to create .deb file
  • Loading branch information
kamber-intel committed Jan 12, 2024
2 parents 30aeb78 + 93234db commit 1a327a1
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 14 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,16 @@ tail /var/log/detd.log
At this point the service is ready to receive requests.


#### Docker

To avoid installing all build dependencies locally, you can also use Docker for building the Debian package:

```
docker build -f tools/Dockerfile . -t detd_builder
docker run --name detd_build_container detd_builder
docker cp detd_build_container:/tmp/detd_0.1.dev0-1_all.deb ./
docker rm detd_build_container
```

#### pip

Expand Down
26 changes: 20 additions & 6 deletions detd/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,28 @@ def __init__(self, test_mode=False, log_filename=None):
# We create the lock file even before calling parent's constructor
self.setup_lock_file()

self.setup_unix_domain_socket()
try:
self.setup_unix_domain_socket()

# Create directory for the socket file
try:
os.makedirs(os.path.dirname(_SERVICE_UNIX_DOMAIN_SOCKET))
except FileExistsError:
# directory already exists
pass

super().__init__(_SERVICE_UNIX_DOMAIN_SOCKET, ServiceRequestHandler)
super().__init__(_SERVICE_UNIX_DOMAIN_SOCKET, ServiceRequestHandler)

self.test_mode = test_mode
self.test_mode = test_mode

self.manager = Manager()
self.manager = Manager()

signal.signal(signal.SIGINT, self.terminate)
signal.signal(signal.SIGTERM, self.terminate)
signal.signal(signal.SIGINT, self.terminate)
signal.signal(signal.SIGTERM, self.terminate)
except Exception as ex:
self.cleanup_lock_file()
logger.exception("Exception while initializing service")
raise


def setup_lock_file(self):
Expand Down Expand Up @@ -142,7 +154,9 @@ def cleanup(self):
if os.path.exists(self.server_address):
raise

self.cleanup_lock_file()

def cleanup_lock_file(self):
# Clean-up lock file
if not Check.is_valid_file(Service._SERVICE_LOCK_FILE):
logger.error(f"{Service.SERVICE_LOCK_FILE} is not a valid file")
Expand Down
22 changes: 22 additions & 0 deletions tools/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM debian:bookworm
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update --fix-missing && \
apt-get upgrade --assume-yes --no-install-recommends && \
apt-get install --assume-yes --no-install-recommends \
debmake debhelper-compat dh-python \
python3 python3-all python3-setuptools \
protobuf-compiler python3-protobuf && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

ADD . /usr/local/src/detd/

WORKDIR /usr/local/src/detd/tools

# Work around bug in debmake
RUN ln -s /usr/lib/debmake/python3.short /usr/lib/debmakepython3.short
RUN ln -s /usr/lib/debmake/python3.long /usr/lib/debmakepython3.long

CMD ./package_debian.sh

19 changes: 11 additions & 8 deletions tools/package_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
# Generates a rudimentary deb package to facilitate installations on Debian
# based distributions. The package is then copied to /tmp



set -e # exit early on errors

function usage () {
echo "Usage:"
Expand Down Expand Up @@ -50,6 +49,7 @@ function create_deb () {
# E.g. detd-0.1.dev0 (PKG: detd, VERSION: 0.1.dev0)
PKG=$(awk '/^name/{print $3}' ./setup.cfg)
VERSION=$(awk '/^version/{print $3}' ./setup.cfg)
REVISION=1
ID="${PKG}-${VERSION}"


Expand All @@ -62,7 +62,9 @@ function create_deb () {

# Generate and customize the debian directory
cd ${TMPDIR}/${ID}
debmake --binaryspec ':py3' --email ${EMAIL} --fullname ${FULLNAME} --spec
debmake --binaryspec ':py3' --email ${EMAIL} --fullname ${FULLNAME} --spec --revision ${REVISION}

ARCHITECTURE=`grep -Po 'Architecture: \K\S+' debian/control`

cp ${TMPDIR}/detd.service debian/

Expand All @@ -77,16 +79,17 @@ function create_deb () {

echo -e "\tdh_installsystemd" >> debian/rules
# Restart detd when the application is upgraded
echo -e "\noverride_dh_systemd_start:\n\tdh_systemd_start --restart-after-upgrade" >> debian/rules
echo -e "\noverride_dh_installsystemd:\n\tdh_installsystemd --restart-after-upgrade" >> debian/rules
# Force xz for compression, to prevent installation issues with Zstandard
echo -e "\noverride_dh_builddeb:\n\tdh_builddeb -- -Zxz" >> debian/rules

# Generate the deb, make it available and perform clean-up
fakeroot debian/rules binary
dpkg --contents ../*deb
dpkg -I ../*deb
cp ../*deb /tmp
echo "The deb package is now available in /tmp"
FILENAME=${PKG}_${VERSION}-${REVISION}_${ARCHITECTURE}.deb
dpkg --contents ../${FILENAME}
dpkg -I ../${FILENAME}
cp ../${FILENAME} /tmp
echo "The deb package is now available at /tmp/${FILENAME}"

rm -rf ${TMPDIR}

Expand Down

0 comments on commit 1a327a1

Please sign in to comment.