<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Thomas Huffert on Medium]]></title>
        <description><![CDATA[Stories by Thomas Huffert on Medium]]></description>
        <link>https://medium.com/@quadratclown?source=rss-ee497641a323------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lhfh3eR_M_Mu8FG9JcImjA.jpeg</url>
            <title>Stories by Thomas Huffert on Medium</title>
            <link>https://medium.com/@quadratclown?source=rss-ee497641a323------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 07:17:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@quadratclown/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Continuously delivering a multi-repository application for multi-architecture Kubernetes-clusters]]></title>
            <link>https://medium.com/omi-uulm/continuously-delivering-a-multi-repository-application-for-multi-architecture-kubernetes-clusters-6805e578f07e?source=rss-ee497641a323------2</link>
            <guid isPermaLink="false">https://medium.com/p/6805e578f07e</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[continous-delivery]]></category>
            <dc:creator><![CDATA[Thomas Huffert]]></dc:creator>
            <pubDate>Tue, 06 Jul 2021 07:59:57 GMT</pubDate>
            <atom:updated>2021-07-06T07:59:57.715Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IXbQo4HshgBjjIIc" /><figcaption>Photo by <a href="https://unsplash.com/@heytowner?utm_source=medium&amp;utm_medium=referral">JOHN TOWNER</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In a recent TypeScript-based project, we ran into a challenge. We had two different repositories, an application depending on an underlying framework. The application needed to be retested every time changes to the framework were applied to ensure the integrity of the update.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/161/1*VkCpPHh1nIYSKYmjlqx9Ow.png" /></figure><p>For local development, a structure like this is not a problem at all. In the case of TypeScript, npm for example allows linking the two repositories by first running npm link in the framework repository, after which it can be incorporated as local dependency in the application via npm link framework. This works perfectly fine if testing the repositories locally is sufficient. Other languages or runtime-environments allow for similar solutions.</p><p>However, in our case, it was not quite as easy. Our application is situated in the domain of the Internet of Things (IoT), targeting multiple different architectures and utilizing device and platform specific communication technologies. It therefore could not be fully tested locally, but needed to be deployed on a testbed — for us, in form of a local Kubernetes-Cluster — to ensure that everything is working correctly. Consequently, the application had to be containerized and made available first.</p><p>In the following article, we describe how we built an applicable continous delivery solution via GitLab ci-pipelines, utilizing intermediate images in an Open Container Initiative (OCI) container registry.</p><h3>The starting point</h3><p>First, lets describe the starting-point in form of the basic pipeline we used for a single-repository project. We use a self-hosted GitLab to host our repositories.</p><p>The goal was to build multi-architecture images that work on linux-based amd64, arm64 and arm/v7 systems. This is the basic gitlab-ci.yml we used for a multi-architecture TypeScript-project:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e332cb57e8648c92681dc060ad8008ed/href">https://medium.com/media/e332cb57e8648c92681dc060ad8008ed/href</a></iframe><h4>npm</h4><p>In the first stage, the npm dependencies are resolved and the package is built In our case, we utilize pnpm for the dependencies, an <a href="https://github.com/pnpm/pnpm#Benchmark">alternative, faster package-manager</a> for nodejs. It gives us benefits down the line, which we utilize in the containerize step.</p><p>Both dependencies and build-output are stored as artifacts for usage in later stages.</p><h4>eslint</h4><p>In the second stage, the source code is analyzed using <a href="https://eslint.org/">ESLint</a> to check for problems in the code, for example syntax errors.</p><p>We also use the <a href="https://prettier.io/">prettier</a>-plugin for ESLint to ensure a consistent code style and format.</p><h4>test</h4><p>In the third stage, we execute tests using <a href="https://jestjs.io/">jest</a> to check for easy to catch errors in the code.</p><h4>containerize</h4><p>In the last stage, it gets interesting. We containerize our application using the jess/img-image, <a href="https://github.com/genuinetools/img">a Dockerfile-based container build-tool built based on BuildKit</a>. The produced images are uploaded to a local container registry.</p><p>Within jess/img, the image of for every architecture is build separately. In consequence, a many partly redundant operations are done in the building process. To allow for shorter build-times, we therefore had made several optimizations to our base Dockerfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a263d9a122a8b210d302b2c454c799af/href">https://medium.com/media/a263d9a122a8b210d302b2c454c799af/href</a></iframe><p>Mainly, we did three things:</p><ul><li>Use the smallest applicable base-image (for us, alpine worked)</li><li>Use compiled TypeScript code from build artifacts</li><li>Use pnpm for installation of dependencies instead of npm</li></ul><p>All in all, these optimizations drove down the build time from around 30 minutes to below 5. This saved us some headache, but cost us a few coffee-pauses — well, somewhere priorities have to be set.</p><h3>The realization</h3><p>Now, let’s start incorporating our scenario. We have two different packages, one being the application, one being the framework. Both are managed in different repositories, however the former depends on the latter. This means that build-artifacts need to be shared between different pipelines, since every repository has it’s own build pipeline.</p><p>In GitLab, there are multiple ways to do this. One would be to use a <a href="https://docs.gitlab.com/ee/user/packages/package_registry/">GitLab Package Registry</a> to upload the compiled package to a local registry, another to retrieve artifacts of another pipeline via <a href="https://docs.gitlab.com/ee/ci/triggers/#when-a-pipeline-depends-on-the-artifacts-of-another-pipeline">CI_JOB_TOKENS</a>. These solutions however are dependent on GitLab (and the latter only works with GitLab premium). We instead opted to use our self-hosted OCI container registry, <a href="https://docs.docker.com/develop/develop-images/multistage-build/">inspired by docker multistage builds</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*xUDzpv_UXskqUqHWaSrIDg.png" /><figcaption>Schematic structure of project pipelines</figcaption></figure><p>In the framework-pipeline, we regularly create an image based on alpine — base— as we would if we only had a single-repository project. However, we create an additional image, base-build, which is intended as build-image for later steps. Both of those images now contain the build artifacts — aka the the compiled framework — for later usage in the application-pipeline</p><p>In the application-pipeline, we use the aforemention base-build image to produce our build artifacts. Subsequently, the image base is used as base-image to produce the image app. The app image can then be deployed on the Kubernetes-Cluster.</p><h4>Framework-pipeline</h4><p>We only slightly have to adjust our basic build-pipelines to create the framework-pipeline:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b5044dcd17cc643d7c09d16c41efde5/href">https://medium.com/media/8b5044dcd17cc643d7c09d16c41efde5/href</a></iframe><p>Most notably, we create an additional image — base-build— with a slightly different Dockerfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c7df39d7af4ff2a907c3726b47d8170/href">https://medium.com/media/9c7df39d7af4ff2a907c3726b47d8170/href</a></iframe><p>It uses another buster-based base-image instead, which includes necessary os-dependencies for compiling TypeScript projects. Additionally, dependencies are not installed, since that is done as part of the application pipeline — this makes the image smaller.</p><p>The regular Dockerfile looks almost the same:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3f36dde1744418d3d692e4e887118c3/href">https://medium.com/media/c3f36dde1744418d3d692e4e887118c3/href</a></iframe><p>We just do not install the production dependencies, again to make the image smaller.</p><p>Both dockerfiles do not include an entrypoint, since they are not meant to be deployed alone.</p><h4>Application-pipeline</h4><p>We modify the basic-pipeline to incorporate the images created earlier.</p><p>The application pipeline looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a79b8451bcc9fe0d63c997db5e434377/href">https://medium.com/media/a79b8451bcc9fe0d63c997db5e434377/href</a></iframe><p>We use the base-build image to create our build-artifacts. The included framework package is linked in the <strong>npm</strong> stage.</p><p>Similarly, we modify our basic Dockerfile to use the base image and link the framework as well:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5781046255bde5d57bb607f6a37b915/href">https://medium.com/media/a5781046255bde5d57bb607f6a37b915/href</a></iframe><p>With this, were done.</p><h3>Final thoughts</h3><p>With this, we created pipelines, spanning across multiple repositories, that manage inter-pipeline build artifacts using a OCI container repository and create multi-architecture images for usage in an Kubernetes-Cluster. Although it is focussed on nodejs-based TypeScript project, this method could be used with as other languages or runtime environments as well, since it basically just uses the intermediate-images as containers to share the project-artifacts. Also, since no GitLab exclusive features were used, it would work with other hosting-services like GitHub as well (albeit with conversion of the gitlab-ci.yml -files).</p><p>One thing that still can be improved uppon is the handling of job-triggers. Currently, a job for the application-pipeline needs to be triggered manually after the framework’s is done. This could be done automatically with GitLab <a href="https://docs.gitlab.com/ee/ci/pipelines/multi_project_pipelines.html#trigger-a-pipeline-when-an-upstream-project-is-rebuilt">pipeline-triggers</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6805e578f07e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/omi-uulm/continuously-delivering-a-multi-repository-application-for-multi-architecture-kubernetes-clusters-6805e578f07e">Continuously delivering a multi-repository application for multi-architecture Kubernetes-clusters</a> was originally published in <a href="https://medium.com/omi-uulm">omi-uulm</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to run containerized Bluetooth applications with BlueZ]]></title>
            <link>https://medium.com/omi-uulm/how-to-run-containerized-bluetooth-applications-with-bluez-dced9ab767f6?source=rss-ee497641a323------2</link>
            <guid isPermaLink="false">https://medium.com/p/dced9ab767f6</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[bluetooth]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Thomas Huffert]]></dc:creator>
            <pubDate>Thu, 18 Feb 2021 13:17:20 GMT</pubDate>
            <atom:updated>2021-02-18T13:27:27.830Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p>For a multitude of reasons, it can be beneficial to containerize applications. These might include security concerns, ease of use or other reasons, such as automated deployment via container platforms like Kubernetes. In the times of huge <a href="https://docs.microsoft.com/en-us/dotnet/architecture/cloud-native/definition">Cloud-native applications</a>, containers are an integral part of making them flexible, scalable and easy to deploy.</p><p>While many applications can be containerized and run rather straight forwardly, this is not the case for ones that require host-specific functionality — as in the case of Bluetooth. In this article, we show how to accomplish the aforementioned task with applications that use <a href="http://www.bluez.org/">BlueZ, the official Linux Bluetooth Stack</a>. We will describe how to build and run containers, which problems we faced along the way — and possible usecases for such a solution.</p><p><strong>About Bluetooth</strong></p><p>Bluetooth is a Wireless Personal Area Network (WPAN) standard developed by the Bluetooth Special Interest Group (SIG) with version 1.0 being released in 1999. The standard has seen several updates up to the <a href="https://www.bluetooth.com/bluetooth-resources/whats-new-in-core-spec-version-5-2/">current specification of Bluetooth 5.2</a>. It is currently one of the most widespread wireless technologies, being supported by many laptops, smartphones, single-board computers and IoT-devices.</p><p><a href="https://www.bluetooth.com/specifications/specs/">Bluetooth has many different predefined profiles</a> that expand the core specification and define how certain applications shall communicate with each other. These include streaming of audio, data transfer, printing, remote controls and many other use cases. Bluetooth Profiles allow vendor-agnostic interoperability between devices of different companies, which is a big contributor to Bluetooth’s prevalence.</p><p>Bluetooth has <a href="https://www.bluetooth.com/learn-about-bluetooth/radio-versions/">two different radio versions</a>, Bluetooth Classic and Bluetooth Low Energy (LE), the latter one being added with core specification 4.0. Bluetooth LE aims at maximum energy efficiency, making it a good fit for low power wireless applications. While adapters with Bluetooth 4.0 or higher support Bluetooth LE, it has separate profiles, such as <a href="https://www.bluetooth.com/bluetooth-resources/intro-to-bluetooth-gap-gatt/">Generic Attribute Profiles (GATT)</a>, which are not compatible to Bluetooth Classic.</p><p><strong>About BlueZ</strong></p><p>BlueZ is at the heart of many applications that utilize Bluetooth connectivity. It is the official Bluetooth stack for Linux and is therefore pre-installed on many popular distributions, such as the latest versions of Ubuntu and Raspberry Pi OS. However, is compatible to <a href="http://www.bluez.org/about/">many other distributions too,</a> while being almost entirely platform independent. Bluez supports widely used <a href="http://www.bluez.org/profiles/">Classic Bluetooth profiles such as A2DP or AVRCP out of the box</a>, as well as Generic Attribute Profiles of Bluetooth LE.</p><p>BlueZ runs in a process called bluetoothd. It mounts the Bluetooth adapter(s) using the Host Controller Interface (HCI), in most cases the adapter hci0, which is the default one of a Bluetooth-capable device with a single adapter. Applications can communicate with bluetoothdusing the interprocess message bus <a href="https://www.freedesktop.org/wiki/Software/dbus/">D-Bus</a>, more precisely, the system D-Bus:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*RpIeCZ8j9uDOez1KfKaQ-Q.png" /><figcaption>Fig 1: Structure of an arbitrary application with BlueZ</figcaption></figure><p><strong>About our Application</strong></p><p>Our application is a nodejs app, written in TypeScript. It utilizes Bluetooth LE to exchange json encoded messages via the UART GATT with other instances running on different devices.</p><p>While the D-Bus calls necessary to communicate with the Bluetooth service can be implemented manually, this would require a lot of work. To make the implementation easier, a number of BlueZ api-wrappers exist for different platforms, <a href="https://www.npmjs.com/package/@sorrir/bluetooth">such as the one that we are using</a>.</p><p>In theory, the runtime environment should not matter, since all necessary inter-process communication is done via the D-Bus, as long as the aforementioned is supported. Consequently, this article can be applied to other applications that use BlueZ as well.</p><p>Our goal is to containerize our nodejs app and include all necessary services like BlueZ and D-Bus in the container. Essentially, we want to enclose as much Bluetooth-related software as possible, to minimize dependencies on host devices, as we intended to deploy such a container in a Kubernetes cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*yJfR7VBBXdNbStA0Ji1kPQ.png" /></figure><p><strong>About our testing</strong></p><p>We have built containers for multiple architectures, including arm/v6, arm/v7, arm64 and amd64. The containers were run on multiple versions of the Raspberry Pi (Zero W, Pi 3B, Pi 4) and a Thinkpad T470s.</p><p><strong>Before we start</strong></p><p>This article focuses on how to build and run containers that use BlueZ. We assume that the host has all prerequesites so that BlueZ is able to run locally in the first place. That includes a compliant Bluetooth adapter and all necessary kernel modules. While we will not cover setting up the host in this article, if your device is able to run your Bluetooth application un-containerized, it should be able to run it in a container as well.</p><h3><strong>Basic Solution</strong></h3><p>Now that we know about BlueZ and the basics of our use case, we can proceed to the realization of the container.</p><p><strong>Containerization</strong></p><p>With the information we have, we can set a number of requirements that our container has to fulfill:</p><ul><li>nodejs support, in our case Version 14</li><li>BlueZ support</li><li>D-Bus support</li></ul><p>From these requirements, we can construct the Dockerfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95acd32c329a04b03da7cf119778e8e5/href">https://medium.com/media/95acd32c329a04b03da7cf119778e8e5/href</a></iframe><p>We have chosen node:14.15.5-buster as base image since it combines a suitable version of nodejs with Debians current stable version 10. While we have not tested different images, other Debian-based distributions are likely to work as well. We have not yet tested images based on other distributions like Alpine.</p><p>The entry point of the docker container is a script called entrypoint.sh. Since the container does not automatically start the necessary services like dbus and bluetooth, they need to be started manually before launching the application. The basic script consequently looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4dacc69129888a84f91ed9ce96807b1f/href">https://medium.com/media/4dacc69129888a84f91ed9ce96807b1f/href</a></iframe><p>Now, we can build the image, for example with docker:</p><pre>docker build -t our-container .</pre><p><strong>Running the container</strong></p><p>With the container built, it can now be run. However, a few things come to mind:</p><ul><li>the container needs to be able to directly communicate with the Bluetooth adapter, which is handled as a network interface</li><li>the container needs to be able control the adapter administratively</li></ul><p>In the case of running the container via docker, these requirements lead to the start options that we need to set when launching:</p><pre>docker run --net=host --privileged -t our-container</pre><p>The first flag, --net=host, allows us to handle network adapters natively. The second one, --privileged, gives the containers application the same capabilities as if they were native as well. While the first one is mandatory, there are better solutions for the latter one — but more on that later.</p><p>One thing we need to make sure is that no application owning the Bluetooth adapter we intend to use is running on the host. For example, if the bluetoothd service is active, the adapter will not be visible to the container, as it is already owned by a process. If that is kept in mind, this solution should run just fine. However…</p><p><strong>Problems with this solution</strong></p><p>…while this works, it has a few issues that we need to address:</p><ul><li>Running a container with privileged rights <a href="https://www.trendmicro.com/en_us/research/19/l/why-running-a-privileged-container-in-docker-is-a-bad-idea.html">is a security liability</a>, especially if the container executes as root user, which it does by default</li><li>The container startup can fail obfuscatedly</li></ul><h3><strong>Fixing our problems</strong></h3><p>With the previously established knowledge, let’s reiterate and fix the problems of our first, basic solution.</p><p><strong>In-container rights management</strong></p><p>By default, containers run with the root user. This is a problem, especially since the container is running with privileged rights. However, it is not directly possible to just change the user to a non-elevated one. Starting the dbus service requires super-user rights, as does communication to the bluetoothd process, which utilizes the system D-Bus. As our application needs to communicate with BlueZ, this means it would have to be started by a super-user as well —we want to avoid this if possible.</p><p>Luckily, at least the latter (running the app as non-root user) can be managed rather easily. The D-Bus allows us to configure the rights that each individual user has by placing a *.conf file in /etc/dbus-1/system.d/. We can set which processes a user is allowed to communicate with, as well as which interfaces can be owned or sent to:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2721e816b0aa9388bc43c2eca9324f4d/href">https://medium.com/media/2721e816b0aa9388bc43c2eca9324f4d/href</a></iframe><p>The list of send-interfaces that need to be permitted depends on the user application. This particular configuration allows the user bluezuser to use GATT via BlueZ. Other applications <a href="https://www.npmjs.com/package/@sorrir/bluetooth#prerequisites">might require additional permissions</a>.</p><p>After saving the above file, e.g. as bluezuser.conf, we have to add it to the container via the Dockerfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/463c06898f9de2739e2906626757c90c/href">https://medium.com/media/463c06898f9de2739e2906626757c90c/href</a></iframe><p>Now, while we can run the app without elevated rights, we still need to address starting the dbus service. One possibility is to allow bluezuser to start applications via sudo. This requires us to install the sudo package, as well as set up the bluezuser so that it can headlessly start processes with root-rights. We can do this by appending the following section to the Dockerfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b8b4b502dbbc18b5fcc60400674e231/href">https://medium.com/media/1b8b4b502dbbc18b5fcc60400674e231/href</a></iframe><p>Since now the container is run as bluezuser, we need to prefix the service start commands in entrypoint.sh with sudo:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8febedf4cf6ef309d5c5d15e213b0fe/href">https://medium.com/media/d8febedf4cf6ef309d5c5d15e213b0fe/href</a></iframe><p><strong>Making the start-up reliable</strong></p><p>While experimenting, we’ve run into seemingly random failures on start-up. One possible cause was easily identified — the adapter could get stuck if the container was run previously and did not exit correctly, not allowing the newly started one to own it. This could be fixed by just restarting the adapter once before launching the app in entrypoint.sh:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf62c5c17cbc725e090da2cd6de5e237/href">https://medium.com/media/cf62c5c17cbc725e090da2cd6de5e237/href</a></iframe><p>However, still some container launches resulted in failures. On some Raspberry Pis, part of a Kubernetes-Cluster, launching did not seem to work at all — even though it worked fine when launching the container locally on the same devices. After a lot of debugging and even more headscratches, the breakthrough came when we observed that launching the user application directly after starting the container did not work, while starting it after waiting for a few minutes did.</p><p>The culprit was the bluez service, which in some cases took unreasonably long to start. While we could not yet identify why the start took so long on the Kubernetes nodes, it is clear that the user application cannot be run before the service it depends on is fully started. So to make the start-up process reliable, we need to ensure that all services launched correctly first. This again can be done in entrypoint.sh:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/096299d235e1e1ad8452c86a936e2cc2/href">https://medium.com/media/096299d235e1e1ad8452c86a936e2cc2/href</a></iframe><p>Unintuitively, just checking the services status does not work, since the bluetooth service shows as running right away, even though it is not yet fully started. Instead, we check once per second if the start-stop-daemon, which starts and stops services, is still active. Once the start-stop-daemon is gone from the list of active processes, all services have launched successfully. In our case, applying this change fixed all our issues and the start-up became fully reliable. However, the validity of this solution might depend on your base image, as it will only work the images distribution uses the start-stop-daemon.</p><p><strong>Running the container without privileged rights</strong></p><p>While we’ve already managed to start the container itself as non-root user, executing with privileged rights is still problematic. In the case of docker however, it is possible to more granularly set its permissions.</p><p>The Bluetooth adapter is a network adapter. If we look at the l<a href="https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities">ist of privileges a container can receive</a>, we can see that the NET_ADMIN capability allows it to “Perform various network-related operations.” — just what we need.</p><p>We can add this permission by replacing the --privileged flag with the --cap-add=NET_ADMIN start option:</p><pre>docker run --net=host --cap-add=NET_ADMIN -t our-container</pre><p>And lo and behold, everything worked as intended (and our Sysadmin is happy :) ).</p><h3>Advanced Solution</h3><p>Applying the fixes to our previous, basic solution, we have managed to build and run a container that utilizes BlueZ, while not requiring to be run as privileged. In the following, let’s see the new solution we have ended up with:</p><p><strong>Dockerfile</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95d91c5c6557887bb16d4d90abe3da77/href">https://medium.com/media/95d91c5c6557887bb16d4d90abe3da77/href</a></iframe><p><strong>Entrypoint.sh</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/518de9eeb23e884b5f42036761a9ddb8/href">https://medium.com/media/518de9eeb23e884b5f42036761a9ddb8/href</a></iframe><p><strong>bluezuser.conf</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2721e816b0aa9388bc43c2eca9324f4d/href">https://medium.com/media/2721e816b0aa9388bc43c2eca9324f4d/href</a></iframe><p><strong>Running the container</strong></p><pre>docker run --net=host --cap-add=NET_ADMIN -t our-container</pre><h3>Applications</h3><p>Now that we’ve successfully built a reliable container for Bluetooth applications — what possible usecases exist for such a solution?</p><p>While it can be useful to containerize simple monolithic applications such as a Bluetooth sensor running on a Raspberry Pi, a task like this can be rather easily — and in many cases more efficiently — done natively as well. However the containerization allows us many more possibilities…</p><p><strong>Bluetooth container as Bluetooth service</strong></p><p>This article focuses on an arbitrary, monolithic nodejs-based application. However, the developed procedure can also be used to implement a Bluetooth-capable service, for instance by exposing the BlueZ-api via a REST api that other applications or services could communicate with to access Bluetooth connectivity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*5qbpzUzq2gvzcx8yxAIkNQ.png" /><figcaption>Fig 3: Example structure of a Bluetooth container as service</figcaption></figure><p>This structure is advantageous for multiple reasons:</p><ul><li>The Bluetooth container requires more rights than by default, so limiting its functionality to just being a proxy for other applications with regular permissions benefits security</li><li>BlueZ can only be owned by a single process. Deploying multiple applications that include BlueZ on the same device would not work. However, if the Bluetooth service balances the load instead, multiple applications can use it simultaneously</li><li>The Bluetooth service and other services can be individually updated</li><li>Bluetooth can be accessible from other devices as well, allowing applications on devices that are not capable of Bluetooth to utilize it</li></ul><p>While this could all still be done natively, it already becomes apparent that containerization is helpful. However, it becomes even more interesting when paired with a container platform like Kubernetes.</p><p><strong>Bluetooth as microservice</strong></p><blockquote><a href="https://docs.microsoft.com/en-us/dotnet/architecture/cloud-native/definition">Cloud-native systems embrace microservices, a popular architectural style for constructing modern applications.</a></blockquote><p>One of the paradigms of Cloud-native is to split applications into microservices that can be individually deployed on-demand. This allows to dynamically deploy capabilities if necessary, while not requiring them to share their code base.</p><p>Imagine a Kubernetes cluster with Bluetooth capable devices such as Raspberry Pis, which are part of a big Cloud-native application. Wouldn’t it be cool to be able to dynamically use some of them as sensors or Bluetooth beacons? That is something we can do now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*0ktL79BpHd8wqamksYbvbw.png" /><figcaption>Fig 4: Cloud with Bluetooth capable devices</figcaption></figure><p>Possible usecases for a Bluetooth microservice sensing applications, for example to measure the density of a crowd. It also makes it possible to contact devices that have no Internet-connectivity, but can use Bluetooth. Many other applications are imaginable, such as energy efficient close range monitoring that does not use-up network bandwidth, or fallback mechanisms if for instance the WiFi connection fails.</p><p>Finally, we’ve reached a point where native just does not cut it anymore.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dced9ab767f6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/omi-uulm/how-to-run-containerized-bluetooth-applications-with-bluez-dced9ab767f6">How to run containerized Bluetooth applications with BlueZ</a> was originally published in <a href="https://medium.com/omi-uulm">omi-uulm</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>