Skip to content

Commit a1cbcea

Browse files
authored
Merge pull request #4 from scs/feature/SMT-18-support-building-deb-package
Support building Debian packages
2 parents 036c49c + 47f6711 commit a1cbcea

File tree

17 files changed

+469
-3
lines changed

17 files changed

+469
-3
lines changed

.github/workflows/build-deb.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Build a Debian package
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
tags:
8+
- 'v*'
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
build-deb:
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
os: [ 'debian', 'raspios' ]
20+
include:
21+
- os: debian
22+
dist: buster
23+
arch: amd64
24+
keyring_cmd: sudo apt-get install -y debian-archive-keyring
25+
- os: raspios
26+
dist: buster
27+
arch: armhf
28+
keyring_cmd: wget http://archive.raspbian.org/raspbian/pool/main/r/raspbian-archive-keyring/raspbian-archive-keyring_20120528.2_all.deb && sudo dpkg -i raspbian-archive-keyring_20120528.2_all.deb
29+
30+
name: Build a Debian package for ${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.arch }}
31+
steps:
32+
- uses: actions/checkout@v2
33+
- name: Set up Python
34+
uses: actions/setup-python@v1
35+
with:
36+
python-version: 3.8
37+
38+
- name: Install pipenv
39+
run: |
40+
python -m pip install --upgrade pip pipenv
41+
python --version; python -m pip --version; pipenv --version
42+
- id: cache-pipenv
43+
uses: actions/cache@v1
44+
with:
45+
path: ~/.local/share/virtualenvs
46+
key: ${{ runner.os }}-3.8-pipenv-${{ hashFiles('**/Pipfile.lock') }}
47+
- name: Setup project with pipenv
48+
if: steps.cache-pipenv.outputs.cache-hit != 'true'
49+
run: |
50+
pipenv install --dev
51+
52+
- name: Prepare to build a Debian source package
53+
run: |
54+
sudo apt-get -y install python3-all debhelper dh-python dh-systemd
55+
56+
- name: Build a Debian source package
57+
run: |
58+
pipenv run build_srcdeb
59+
60+
- id: cache-pbuilder-chroot
61+
uses: actions/cache@v1
62+
with:
63+
path: /var/cache/pbuilder/${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.arch }}-base.tgz
64+
key: ${{ runner.os }}-pbuilder-${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.arch }}-${{ hashFiles('**/Pipfile.lock') }}
65+
- name: Prepare the pbuilder chroot for ${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.arch }}
66+
if: steps.cache-pbuilder-${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.arch }}-chroot.outputs.cache-hit != 'true'
67+
run: |
68+
sudo apt-get install -y pbuilder qemu-user-static
69+
${{ matrix.keyring_cmd }}
70+
sudo cp scripts/.pbuilderrc /root/
71+
sudo mkdir -p /var/cache/pbuilder/${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.arch }}/aptcache/
72+
sudo OS=${{ matrix.os }} DIST=${{ matrix.dist }} ARCH=${{ matrix.arch }} pbuilder --create
73+
74+
- name: Build the Debian package for ${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.arch }} using pbuilder
75+
run: |
76+
cd deb_dist
77+
sudo OS=${{ matrix.os }} DIST=${{ matrix.dist }} ARCH=${{ matrix.arch }} pbuilder build *.dsc
78+
79+
- name: Archive the built Debian package for ${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.arch }}
80+
uses: actions/upload-artifact@v2
81+
with:
82+
name: ${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.arch }}-deb
83+
path: /var/cache/pbuilder/${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.arch }}/result/*.deb
84+
85+
- name: Archive the additional Debian package files for ${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.arch }}
86+
uses: actions/upload-artifact@v2
87+
with:
88+
name: ${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.arch }}-packagefiles
89+
path: |
90+
/var/cache/pbuilder/${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.arch }}/result/*.dsc
91+
/var/cache/pbuilder/${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.arch }}/result/*.tar.*
92+
93+
- name: Get the tag name
94+
id: tag-name
95+
if: startsWith(github.ref, 'refs/tags')
96+
uses: olegtarasov/get-tag@v2.1.1
97+
98+
- name: Create a new release
99+
if: startsWith(github.ref, 'refs/tags')
100+
uses: ncipollo/release-action@v1.8.8
101+
with:
102+
allowUpdates: true
103+
artifacts: /var/cache/pbuilder/${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.arch }}/result/*.deb
104+
draft: true
105+
name: Smart Meter Data Collector ${{ steps.tag-name.outputs.tag }}
106+
omitBody: true
107+
omitBodyDuringUpdate: true
108+
omitNameDuringUpdate: true
109+
omitPrereleaseDuringUpdate: true
110+
token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ __pycache__/
1010
.Python
1111
build/
1212
develop-eggs/
13+
deb_dist/
1314
dist/
1415
downloads/
1516
eggs/

Pipfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ licenseheaders = "*"
1616
pipenv-setup = "*"
1717
pylint = "*"
1818
setuptools = "*"
19+
stdeb = {version="*", markers="sys_platform == 'linux'"}
1920
twine = "*"
2021
wheel = "*"
2122

@@ -25,7 +26,10 @@ python_version = "3.8"
2526
[scripts]
2627
build = "bash ./scripts/build.sh"
2728
build_check = "twine check dist/*"
28-
clean = "rm -rf .eggs build dist smartmeter_datacollector.egg-info"
29+
build_srcdeb = "bash ./scripts/build_srcdeb.sh"
30+
build_deb = "bash ./scripts/build_deb.sh"
31+
clean = "rm -rf .eggs build dist deb_dist smartmeter_datacollector.egg-info"
32+
debianize = "bash ./scripts/debianize.sh"
2933
format_check = "autopep8 --diff -r --aggressive smartmeter_datacollector/"
3034
format = "autopep8 --in-place -r --aggressive smartmeter_datacollector/"
3135
isort = "isort ."

Pipfile.lock

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

debian/changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
smartmeter-datacollector (0.4.1-1) unstable; urgency=low
2+
3+
* support building Debian source and binary packages for distribution on Debian Buster amd64 and raspios
4+
5+
-- Supercomputing Systems AG <info@scs.ch> Sun, 29 Aug 2021 21:04:55 +0000

debian/compat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10

debian/control

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Source: smartmeter-datacollector
2+
Maintainer: Supercomputing Systems AG <info@scs.ch>
3+
Section: python
4+
Priority: optional
5+
Build-Depends: python3-setuptools, python3-all, debhelper (>= 10), dh-systemd (>= 1.5)
6+
Standards-Version: 3.9.1
7+
Homepage: https://github.com/scs/smartmeter-datacollector
8+
9+
Package: python3-smartmeter-datacollector
10+
Architecture: all
11+
Pre-Depends: python3-pip
12+
Depends: ${misc:Depends}, ${python3:Depends}
13+
Description: Smart Meter Data Collector
14+
# Smart Meter Data Collector
15+
.
16+
<p align="center">
17+
<a href="LICENSE"><img alt="License: GPL-2.0-only" src="https://img.shields.io/badge/license-GPLv2-blue.svg"></a> <a href="https://github.com/scs/smartmeter-datacollector/pulls"><img alt="Pull Requests Welcome" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg"></a> <a href="https://github.com/scs/smartmeter-datacollector/pulls"><img alt="Contributions Welcome" src="https://img.shields.io/badge/contributions-welcome-brightgreen.svg"></a>
18+
<br />
19+
<img alt="Python Code Checks" src="https://github.com/scs/smartmeter-datacollector/actions/workflows/python-code-checks.yml/badge.svg?branch=master"> <a href="https://pypi.org/project/smartmeter-datacollector/"><img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/smartmeter-datacollector"></a>
20+
</p>
21+
.
22+

debian/postinst

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/sh
2+
# postinst script for python3-smartmeter-datacollector
3+
#
4+
# see: dh_installdeb(1)
5+
6+
# exit on any error
7+
set -e
8+
9+
USERNAME=smartmeter
10+
GROUP=dialout
11+
12+
# make sure the dialout group already exists
13+
if ! getent group | grep -q "^${GROUP}:"; then
14+
>&2 echo "Expected group \"${GROUP}\" doesn't exist!"
15+
exit 1
16+
fi
17+
18+
# add new group "smartmeter" if it doesn't already exist
19+
if ! getent group | grep -q "^${USERNAME}:"; then
20+
echo -n "Adding group ${USERNAME}.."
21+
addgroup --quiet --system ${USERNAME} 2>/dev/null || true
22+
echo "..done"
23+
fi
24+
25+
# add new user "smartmeter" if it doesn't already exist
26+
if ! getent passwd | grep -q "^${USERNAME}:"; then
27+
echo -n "Adding system user ${USERNAME}.."
28+
adduser --quiet \
29+
--system \
30+
--ingroup ${USERNAME} \
31+
--no-create-home \
32+
--disabled-login \
33+
--disabled-password \
34+
${USERNAME} 2>/dev/null || true
35+
echo "..done"
36+
fi
37+
38+
# add the new user "smartmeter" to the dialout group
39+
if ! groups ${USERNAME} | cut -d: -f2 | grep -qw ${GROUP}; then
40+
adduser ${USERNAME} ${GROUP} > /dev/null 2>&1
41+
fi
42+
43+
echo -n "Installing dependencies using pip.."
44+
# write a pip requirements.txt for automatic dependency installation
45+
echo "#
46+
# These requirements were autogenerated by pipenv
47+
# To regenerate from the project's Pipfile, run:
48+
#
49+
# pipenv lock --requirements
50+
#
51+
52+
-i https://pypi.org/simple
53+
aioserial==1.3.0
54+
asyncio-mqtt==0.10.0
55+
gurux-dlms==1.0.104
56+
paho-mqtt==1.5.1
57+
pyserial==3.5" > /tmp/requirements.txt
58+
# install all required dependencies
59+
python3 -m pip install -r /tmp/requirements.txt > /dev/null 2>&1
60+
rm /tmp/requirements.txt
61+
echo "..done"
62+
63+
#DEBHELPER#
64+
65+
exit 0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=Smart Meter Data Collector Service
3+
4+
[Service]
5+
Type=simple
6+
User=smartmeter
7+
Restart=on-failure
8+
ExecStart=smartmeter-datacollector -c /var/lib/smartmeter-datacollector/datacollector.ini
9+
10+
[Install]
11+
WantedBy=multi-user.target

debian/rules

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/make -f
2+
3+
%:
4+
dh $@ --with python3 --buildsystem=python_distutils --with systemd
5+
6+
override_dh_auto_clean:
7+
python3 setup.py clean -a
8+
find . -name \*.pyc -exec rm {} \;
9+
10+
override_dh_auto_build:
11+
python3 setup.py build --force
12+
13+
override_dh_auto_install:
14+
python3 setup.py install --force --root=debian/python3-smartmeter-datacollector --no-compile -O0 --install-layout=deb --prefix=/usr
15+
rm -rf debian/python-smartmeter-datacollector/trash
16+
17+
override_dh_python2:
18+
dh_python2 --no-guessing-versions
19+

0 commit comments

Comments
 (0)