-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #54 * Update package metadata * First steps to building Debian packages * Rename workflow * Remove unsupported option from cargo build * Specify directory where to download binaries * Move comment * Split logic over two steps * More aggressive caching of previously built artifacts * Use standard GitHub Action caches * More detailed inspection of cache results * Creating the package requires Rust ARM-target to be installed * A bit less troubleshooting * No need to build the project again, just the Debian package * Do not strip the binary This avoids re-installing cross-compilation tools * Better inspection of intermediary results * Verbose invocation of cargo deb * First shot at creating a Debian service
- Loading branch information
1 parent
66704ad
commit 360c5b2
Showing
5 changed files
with
155 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
name: Build Debian packages for Raspberry Pi | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
# Consider creating a matrix to also include armv7-unknown-linux-musleabihf | ||
|
||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v3.5.3 | ||
|
||
- name: Set up Cargo cache | ||
uses: actions/cache@v3.3.1 | ||
continue-on-error: false | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
target/ | ||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
restore-keys: ${{ runner.os }}-cargo- | ||
|
||
- name: Install cross-compilation tools | ||
uses: taiki-e/setup-cross-toolchain-action@v1.15.0 | ||
with: | ||
target: arm-unknown-linux-musleabihf | ||
|
||
- name: Perform build | ||
run: | | ||
cargo build --target arm-unknown-linux-musleabihf --release --features "" | ||
package: | ||
runs-on: ubuntu-latest | ||
needs: [ build ] | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v3.5.3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Cargo cache | ||
uses: actions/cache@v3.3.1 | ||
continue-on-error: false | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
target/ | ||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
restore-keys: ${{ runner.os }}-cargo- | ||
|
||
- name: Inspect downloaded binaries | ||
run: | | ||
file target/arm-unknown-linux-musleabihf/release/dsmr-rs | ||
- name: Prepare packaging | ||
run: | | ||
sudo apt update -y | ||
sudo apt install -y dpkg dpkg-dev liblzma-dev libssl-dev | ||
cargo install cargo-deb | ||
rustup target add arm-unknown-linux-musleabihf | ||
- name: Create Debian package | ||
run: | | ||
cargo deb --target arm-unknown-linux-musleabihf --no-build --no-strip -v | ||
- name: Inspect generated packages | ||
run: | | ||
find target/ -name "*.deb" -exec file {} \; | ||
- name: Upload Debian packages | ||
uses: actions/upload-artifact@v3.1.2 | ||
if: github.ref == 'refs/heads/main' | ||
with: | ||
name: binaries | ||
path: target/debian/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Inspired by https://github.com/NLnetLabs/krill/blob/main/pkg/debian/postinst | ||
|
||
#!/bin/sh | ||
set -e | ||
|
||
PKG_CONF="/etc/dsmr-rs.conf" | ||
PKG_CONF_PERMS=640 | ||
PKG_USER="dsmr-rs" | ||
|
||
create_user() { | ||
if id ${PKG_USER} > /dev/null 2>&1; then return; fi | ||
adduser --system --no-create-home --group ${PKG_USER} | ||
} | ||
|
||
create_configuration() { | ||
if [ ! -f "${PKG_CONF}" ]; then | ||
cat <<EOF > ${PKG_CONF} | ||
# The DSMR-reader API to forward telegrams to | ||
DATALOGGER_API_HOSTS=https://my.host.name | ||
|
||
# The serial port to read telegrams from | ||
DATALOGGER_SERIAL_PORT=/dev/ttyUSB0 | ||
|
||
# The API key to authenticate against the DSMR-reader API | ||
DATALOGGER_API_KEYS=something-secret | ||
|
||
# The input method for reading telegrams. Expected to always be 'serial', so effectively ignored. | ||
DATALOGGER_INPUT_METHOD=serial | ||
|
||
# Baudrate for reading telegrams from the serial line. | ||
DATALOGGER_SERIAL_BAUDRATE=9600 | ||
|
||
EOF | ||
# Ensure that the config file has the correct ownership | ||
chown ${PKG_USER}:${PKG_USER} ${PKG_CONF} | ||
|
||
# Ensure that the config file has the correct permissions | ||
chmod ${PKG_CONF_PERMS} ${PKG_CONF} | ||
fi | ||
} | ||
|
||
case "$1" in | ||
configure) | ||
create_user | ||
create_configuration | ||
;; | ||
esac | ||
|
||
#DEBHELPER# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Unit] | ||
Description=dsmr-rs | ||
|
||
[Service] | ||
EnvironmentFile=/etc/dsmr-rs.conf | ||
ExecStart=/usr/bin/dsmr-rs | ||
|
||
[Install] | ||
WantedBy=multi-user.target |