build: add Docker container

Some changes (like `asound.conf`) are not portable and only work on my
machine. This will be fixed in the future.

ref: N25B-284
This commit is contained in:
2025-11-14 14:15:00 +01:00
parent c037eb7ec2
commit ec0e8e3504
6 changed files with 47 additions and 13 deletions

9
.dockerignore Normal file
View File

@@ -0,0 +1,9 @@
.git
.githooks/
.idea/
.venv/
test/
typings/
.dockerignore
.gitignore
README.md

12
Dockerfile Normal file
View File

@@ -0,0 +1,12 @@
FROM python:2.7.18-alpine
WORKDIR /app
COPY install_deps.sh requirements.txt ./
RUN ./install_deps.sh
COPY . .
ENV PYTHONPATH=src
CMD [ "python2", "-m", "robot_interface.main" ]

9
asound.conf Normal file
View File

@@ -0,0 +1,9 @@
pcm.!default {
type hw
card 2
}
ctl.!default {
type hw
card 2
}

4
install_deps.sh Executable file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env sh
apk add portaudio-dev libzmq gcc musl-dev g++ alsa-utils
pip install -r requirements.txt

View File

@@ -45,7 +45,10 @@ class MainReceiver(ReceiverBase):
if message["endpoint"] == "negotiate/ports":
return MainReceiver._handle_port_negotiation(message)
return {"endpoint": "negotiate/error", "data": "The requested endpoint is not implemented."}
return {
"endpoint": "negotiate/error",
"data": "The requested endpoint is not implemented.",
}
def handle_message(self, message):
if message["endpoint"] == "ping":

View File

@@ -1,6 +1,5 @@
from abc import ABCMeta
import zmq
import os
class SocketBase(object):
@@ -19,7 +18,7 @@ class SocketBase(object):
self.socket = None # Set later by `create_socket`
self.bound = None # Set later by `create_socket`
def create_socket(self, zmq_context, socket_type, port, options=[], bind=True):
def create_socket(self, zmq_context, socket_type, port, options=[], bind=False):
"""
Create a ZeroMQ socket.
@@ -43,17 +42,19 @@ class SocketBase(object):
self.socket = zmq_context.socket(socket_type)
for option, arg in options:
self.socket.setsockopt(option,arg)
self.socket.setsockopt(option, arg)
self.bound = bind
host = os.environ.get("CB_HOST", "localhost")
if bind:
self.socket.bind("tcp://*:{}".format(port))
self.socket.bind("tcp://{}:{}".format(host, port))
else:
self.socket.connect("tcp://localhost:{}".format(port))
self.socket.connect("tcp://{}:{}".format(host, port))
def close(self):
"""Close the ZeroMQ socket."""
if not self.socket: return
if not self.socket:
return
self.socket.close()
self.socket = None
@@ -65,8 +66,4 @@ class SocketBase(object):
https://utrechtuniversity.youtrack.cloud/articles/N25B-A-14/RI-CB-Communication#negotiation
:rtype: dict
"""
return {
"id": self.identifier,
"port": self.port,
"bind": not self.bound
}
return {"id": self.identifier, "port": self.port, "bind": not self.bound}