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:
9
.dockerignore
Normal file
9
.dockerignore
Normal file
@@ -0,0 +1,9 @@
|
||||
.git
|
||||
.githooks/
|
||||
.idea/
|
||||
.venv/
|
||||
test/
|
||||
typings/
|
||||
.dockerignore
|
||||
.gitignore
|
||||
README.md
|
||||
12
Dockerfile
Normal file
12
Dockerfile
Normal 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
9
asound.conf
Normal file
@@ -0,0 +1,9 @@
|
||||
pcm.!default {
|
||||
type hw
|
||||
card 2
|
||||
}
|
||||
|
||||
ctl.!default {
|
||||
type hw
|
||||
card 2
|
||||
}
|
||||
4
install_deps.sh
Executable file
4
install_deps.sh
Executable 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
|
||||
@@ -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":
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user