Skip to content

Commit 3c68d06

Browse files
committed
Update build to create distributables.
Closes #1.
1 parent 21b3d3d commit 3c68d06

13 files changed

+265
-4
lines changed

.github/workflows/main.yml

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
name: CI
2-
on: [push, pull_request]
2+
on:
3+
push:
4+
branches:
5+
- '*'
6+
tags:
7+
- 'v*'
8+
pull_request:
9+
310
jobs:
411
tests:
512
runs-on: ubuntu-latest
@@ -9,9 +16,9 @@ jobs:
916
uses: actions/checkout@v2
1017
-
1118
name: Install Nix
12-
uses: cachix/install-nix-action@v20
19+
uses: cachix/install-nix-action@v22
1320
with:
14-
nix_path: nixpkgs=channel:nixos-23.05
21+
nix_path: nixpkgs=channel:nixos-23.11
1522
-
1623
name: Cargo cache
1724
uses: actions/cache@v3
@@ -26,3 +33,50 @@ jobs:
2633
-
2734
name: Run tests
2835
run: nix-shell --command "make test"
36+
37+
dist:
38+
needs: tests
39+
runs-on: ubuntu-latest
40+
if: startsWith(github.ref, 'refs/tags/v')
41+
strategy:
42+
matrix:
43+
target:
44+
- x86_64-unknown-linux-musl
45+
- aarch64-unknown-linux-musl
46+
- armv7-unknown-linux-musleabihf
47+
steps:
48+
-
49+
name: Checkout
50+
uses: actions/checkout@v2
51+
-
52+
name: Install Nix
53+
uses: cachix/install-nix-action@v22
54+
with:
55+
nix_path: nixpkgs=channel:nixos-23.11
56+
-
57+
name: Cargo cache
58+
uses: actions/cache@v3
59+
with:
60+
path: |
61+
~/.cargo/bin/
62+
~/.cargo/registry/index/
63+
~/.cargo/registry/cache/
64+
~/.cargo/git/db/
65+
target/
66+
key: ${{ runner.os }}-cargo-dist-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
67+
-
68+
name: Build distributables
69+
run: nix-shell --command "make dist-${{ matrix.target }}"
70+
-
71+
name: Configure AWS credentials
72+
uses: aws-actions/configure-aws-credentials@v1
73+
with:
74+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
75+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
76+
aws-region: eu-west-1
77+
-
78+
name: Upload binaries to S3
79+
run: |
80+
aws s3 sync dist s3://builds.loraserver.io/chirpstack-udp-forwarder
81+
if: startsWith(github.ref, 'refs/tags/v')
82+

Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,27 @@
3333
prometheus-client = "0.22"
3434
lazy_static = "1.4"
3535
anyhow = "1.0"
36+
37+
[package.metadata.deb]
38+
assets = [
39+
[
40+
"target/release/chirpstack-udp-forwarder",
41+
"usr/bin/",
42+
"755",
43+
],
44+
[
45+
"packaging/debian/chirpstack-udp-forwarder.toml",
46+
"etc/chirpstack-udp-forwarder/",
47+
"640",
48+
],
49+
]
50+
conf-files = ["/etc/chirpstack-udp-forwarder/chirpstack-udp-forwarder.toml"]
51+
maintainer-scripts = "packaging/debian/"
52+
systemd-units = { enable = true }
53+
54+
[profile.release]
55+
strip = true
56+
opt-level = "z"
57+
lto = true
58+
codegen-units = 1
59+
panic = "abort"

Cross.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[target.x86_64-unknown-linux-musl]
2+
dockerfile="cross/Dockerfile.x86_64-unknown-linux-musl"
3+
4+
[target.aarch64-unknown-linux-musl]
5+
dockerfile="cross/Dockerfile.aarch64-unknown-linux-musl"
6+
7+
[target.armv7-unknown-linux-musleabihf]
8+
dockerfile="cross/Dockerfile.armv7-unknown-linux-musleabihf"

Makefile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,66 @@
11
.PHONY: dist
22

3+
# Compile the binaries for all targets
4+
build: \
5+
build-aarch64-unknown-linux-musl \
6+
build-x86_64-unknown-linux-musl \
7+
build-armv7-unknown-linux-musleabihf
8+
9+
build-x86_64-unknown-linux-musl:
10+
cross build --target x86_64-unknown-linux-musl --release
11+
12+
build-aarch64-unknown-linux-musl:
13+
cross build --target aarch64-unknown-linux-musl --release
14+
15+
build-armv7-unknown-linux-musleabihf:
16+
cross build --target armv7-unknown-linux-musleabihf --release
17+
18+
# Build distributable binaries for all targets.
19+
dist: \
20+
dist-aarch64-unknown-linux-musl \
21+
dist-x86_64-unknown-linux-musl \
22+
dist-armv7-unknown-linux-musleabihf
23+
24+
dist-x86_64-unknown-linux-musl: build-x86_64-unknown-linux-musl package-x86_64-unknown-linux-musl
25+
26+
dist-aarch64-unknown-linux-musl: build-aarch64-unknown-linux-musl package-aarch64-unknown-linux-musl
27+
28+
dist-armv7-unknown-linux-musleabihf: build-armv7-unknown-linux-musleabihf package-armv7-unknown-linux-musleabihf
29+
30+
# Package the compiled binaries
31+
package-x86_64-unknown-linux-musl:
32+
$(eval PKG_VERSION := $(shell cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version'))
33+
mkdir -p dist
34+
35+
# .tar.gz
36+
tar -czvf dist/chirpstack-udp-forwarder_$(PKG_VERSION)_amd64.tar.gz -C target/x86_64-unknown-linux-musl/release chirpstack-udp-forwarder
37+
38+
# .deb
39+
cargo deb --target x86_64-unknown-linux-musl --no-build --no-strip
40+
cp target/x86_64-unknown-linux-musl/debian/*.deb ./dist
41+
42+
package-aarch64-unknown-linux-musl:
43+
$(eval PKG_VERSION := $(shell cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version'))
44+
mkdir -p dist
45+
46+
# .tar.gz
47+
tar -czvf dist/chirpstack-udp-forwarder_$(PKG_VERSION)_arm64.tar.gz -C target/aarch64-unknown-linux-musl/release chirpstack-udp-forwarder
48+
49+
# .deb
50+
cargo deb --target aarch64-unknown-linux-musl --no-build --no-strip
51+
cp target/aarch64-unknown-linux-musl/debian/*.deb ./dist
52+
53+
package-armv7-unknown-linux-musleabihf:
54+
$(eval PKG_VERSION := $(shell cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version'))
55+
mkdir -p dist
56+
57+
# .tar.gz
58+
tar -czvf dist/chirpstack-udp-forwarder_$(PKG_VERSION)_armv7hf.tar.gz -C target/armv7-unknown-linux-musleabihf/release chirpstack-udp-forwarder
59+
60+
# .deb
61+
cargo deb --target armv7-unknown-linux-musleabihf --no-build --no-strip
62+
cp target/armv7-unknown-linux-musleabihf/debian/*.deb ./dist
63+
364
# Update the version
465
version:
566
test -n "$(VERSION)"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM ghcr.io/cross-rs/aarch64-unknown-linux-musl:latest
2+
3+
RUN apt-get update && \
4+
apt-get --assume-yes install \
5+
protobuf-compiler \
6+
libprotobuf-dev
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM ghcr.io/cross-rs/armv7-unknown-linux-musleabihf:latest
2+
3+
RUN apt-get update && \
4+
apt-get --assume-yes install \
5+
protobuf-compiler \
6+
libprotobuf-dev
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM ghcr.io/cross-rs/x86_64-unknown-linux-musl:latest
2+
3+
RUN apt-get update && \
4+
apt-get --assume-yes install \
5+
protobuf-compiler \
6+
libprotobuf-dev
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# UDP Forwarder configuration.
2+
[udp_forwarder]
3+
4+
# Log level.
5+
#
6+
# Valid options are:
7+
# * TRACE
8+
# * DEBUG
9+
# * INFO
10+
# * WARN
11+
# * ERROR
12+
# * OFF
13+
log_level="INFO"
14+
15+
# Log to syslog.
16+
#
17+
# When set to true, log messages are being written to syslog instead of stdout.
18+
log_to_syslog=false
19+
20+
# Prometheus metrics bind.
21+
#
22+
# E.g. '0.0.0.0:9800', leave blank to disable the metrics endpoint.
23+
metrics_bind=""
24+
25+
26+
# Servers to forward the data to using UDP.
27+
# This section can be repeated.
28+
[[udp_forwarder.servers]]
29+
# Server (hostname:port).
30+
server="localhost:1700"
31+
32+
# Keepalive interval (seconds).
33+
#
34+
# In this interval, the ChirpStack UDP Forwarder will send keepalive
35+
# frames to the server, which must be answered by an acknowledgement.
36+
keepalive_interval_secs=10
37+
38+
# Max. allowed keepalive failures.
39+
#
40+
# After the max. number has been reached, the ChirpStack UDP Forwarder will
41+
# 're-connect' to the server, meaning it will also re-resolve the DNS in case
42+
# the server address is a hostname.
43+
keepalive_max_failures=12
44+
45+
# Forward CRC OK.
46+
forward_crc_ok=true
47+
48+
# Forward CRC invalid.
49+
forward_crc_invalid=false
50+
51+
# Forward CRC missing.
52+
forward_crc_missing=false
53+
54+
55+
# Concentratord configuration.
56+
[concentratord]
57+
58+
# Event API URL.
59+
event_url="ipc:///tmp/concentratord_event"
60+
61+
# Command API URL.
62+
command_url="ipc:///tmp/concentratord_command"

packaging/debian/postinst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
# Set config-file permissions
4+
chown -R chirpstack:chirpstack /etc/chirpstack-udp-forwarder
5+
chmod 750 /etc/chirpstack-udp-forwarder
6+
chmod 640 /etc/chirpstack-udp-forwarder/*.toml
7+
8+
#DEBHELPER#
9+

packaging/debian/preinst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
# Create the ChirpStack user
4+
id chirpstack &>/dev/null
5+
if [[ $? -ne 0 ]]; then
6+
useradd --system -U -M chirpstack -s /bin/false -d /etc/chirpstack
7+
fi
8+
9+
#DEBHELPER#

packaging/debian/service

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=ChirpStack UDP Forwarder
3+
Documentation=https://www.chirpstack.io/
4+
Wants=network-online.target
5+
After=network-online.target
6+
7+
[Service]
8+
User=chirpstack
9+
Group=chirpstack
10+
ExecStart=/usr/bin/chirpstack-udp-forwarder -c /etc/chirpstack-udp-forwarder/chirpstack-udp-forwarder.toml
11+
Restart=on-failure
12+
13+
[Install]
14+
WantedBy=multi-user.target

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
2-
channel = "1.77.1"
2+
channel = "1.78.0"
33
components = ["rustfmt", "clippy"]
44
profile = "default"

shell.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ pkgs.mkShell {
55
pkgs.cacert
66
pkgs.rustup
77
pkgs.protobuf
8+
pkgs.cargo-cross
9+
pkgs.cargo-deb
810
];
911
}

0 commit comments

Comments
 (0)