Skip to content

docker: Add official local docker support #3006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples/
73 changes: 73 additions & 0 deletions .github/workflows/container-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Create and publish Container image

on:
push:
branches:
- master
tags:
- '[0-9]+.[0-9]+*'
pull_request:
branches:
- master

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
include:
- container: ./dist/Containerfile
autotag: auto

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=edge
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
flavor: |
latest=${{ matrix.autotag }}
suffix=${{ matrix.suffix }}
- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7,linux/arm/v6
context: .
file: ${{ matrix.container }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,24 @@ On FreeBSD, `pkg install rtl-433`.

On MacOS, `brew install rtl_433`.

Docker images with rtl_433 are available [on the github page of hertzg](https://github.com/hertzg/rtl_433_docker).
## Docker

Running the application through docker is easy with the offical docker image from this repository. Either use `latest` for the latest stable, a tagged version or `master` for the latest build from master. See https://github.com/merbanan/rtl_433/pkgs/container/rtl_433 for available releases.

```console
$ docker run \
--device '/dev/bus/usb:/dev/bus/usb' \
--interactive \
--rm \
--tty \
--volume '/path/for/dumps:/dumps' \
--workdir '/dumps' \
ghcr.io/merbanan/rtl_433/rtl_433:latest --help
```

> __Note:__ The volume (and workdir) arguments are only needed to store (and load) dumps.
> __Warning:__ The `--device` flag still exposes all usb devices to the container, this can be trimmed down by using the exact endpoint for more security, the trouble is that this changes every time a dongle is put in a different USB port. The `--privileged` flag might be needed instead of the `--device` flag in certain cases if the USB devices cannot be enumerated and accessed from within the container. Also the container could be run as the current user by using `--user "$(id -u):$(id -g)"`, but then care with user mapping and the use of udev rules is needed. This left as an exercise to the reader.
## How to add support for unsupported sensors

Expand Down
52 changes: 52 additions & 0 deletions dist/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright (C) 2024 Olliver Schinagl <oliver@schinagl.nl>

ARG ALPINE_VERSION="latest"
ARG TARGET_ARCH="library"

FROM docker.io/${TARGET_ARCH}/alpine:${ALPINE_VERSION} AS builder

WORKDIR /src

COPY . /src/

RUN apk add --no-cache \
'build-base' \
'cmake' \
'git' \
'librtlsdr-dev' \
'libusb-dev' \
'ninja' \
'openssl-dev>3' \
'soapy-sdr-dev' \
&& \
cmake -B '.build' -GNinja \
-DFORCE_COLORED_BUILD:BOOL=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX='/usr' \
-DCMAKE_INSTALL_SYSCONFDIR='/etc' \
-DENABLE_OPENSSL=ON \
&& \
cmake --build '.build' -j $(($(nproc) -1 )) && \
DESTDIR='/rtl_433' cmake --build '.build' --target install && \
rm -f -r '/rtl_433/include' && \
rm -f -r '/rtl_433/usr/share'

FROM docker.io/${TARGET_ARCH}/alpine:${ALPINE_VERSION}

LABEL maintainer="Olliver Schinagl <oliver@schinagl.nl>"

RUN apk add --no-cache \
'librtlsdr' \
'libusb' \
'openssl' \
'soapy-sdr-libs' \
'tini' \
'tzdata' \
;

COPY --from=builder "/rtl_433" "/"
COPY "dist/container-entrypoint.sh" "/init"

ENTRYPOINT [ "/sbin/tini", "--", "/init" ]
25 changes: 25 additions & 0 deletions dist/container-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright (C) 2024 Olliver Schinagl <oliver@schinagl.nl>
#
# A beginning user should be able to docker run image bash (or sh) without
# needing to learn about --entrypoint
# https://github.com/docker-library/official-images#consistency

set -eu
if [ -n "${DEBUG_TRACE_SH:-}" ] && \
[ "${DEBUG_TRACE_SH:-}" != "${DEBUG_TRACE_SH#*"$(basename "${0}")"*}" ] || \
[ "${DEBUG_TRACE_SH:-}" = 'all' ]; then
set -x
fi

bin='rtl_433'

# Prefix args with $bin if $1 is not a valid command
if ! command -v -- "${1:-}" > '/dev/null' 2>&1; then
set -- "${bin:?}" "${@}"
fi
exec "${@}"

exit 0
14 changes: 14 additions & 0 deletions docs/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ Purge all SoapySDR packages and source installation from /usr/local.
Then install only from packages (version 0.7) or only from source (version 0.8).
:::

## Docker

To build the container (and thus the application) from source:

```console
$ docker build \
--rm \
--tag 'rtl_433:MR123' \
--file dist/Containerfile \
'./'
```

and then can be run as above, with `rtl_433:MR123` as container name instead when running the container.

## Package maintainers

To properly configure builds without relying on automatic feature detection you should set all options explicitly, e.g.
Expand Down