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":
|
if message["endpoint"] == "negotiate/ports":
|
||||||
return MainReceiver._handle_port_negotiation(message)
|
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):
|
def handle_message(self, message):
|
||||||
if message["endpoint"] == "ping":
|
if message["endpoint"] == "ping":
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from abc import ABCMeta
|
from abc import ABCMeta
|
||||||
|
import os
|
||||||
import zmq
|
|
||||||
|
|
||||||
|
|
||||||
class SocketBase(object):
|
class SocketBase(object):
|
||||||
@@ -19,7 +18,7 @@ class SocketBase(object):
|
|||||||
self.socket = None # Set later by `create_socket`
|
self.socket = None # Set later by `create_socket`
|
||||||
self.bound = 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.
|
Create a ZeroMQ socket.
|
||||||
|
|
||||||
@@ -46,14 +45,16 @@ class SocketBase(object):
|
|||||||
self.socket.setsockopt(option, arg)
|
self.socket.setsockopt(option, arg)
|
||||||
|
|
||||||
self.bound = bind
|
self.bound = bind
|
||||||
|
host = os.environ.get("CB_HOST", "localhost")
|
||||||
if bind:
|
if bind:
|
||||||
self.socket.bind("tcp://*:{}".format(port))
|
self.socket.bind("tcp://{}:{}".format(host, port))
|
||||||
else:
|
else:
|
||||||
self.socket.connect("tcp://localhost:{}".format(port))
|
self.socket.connect("tcp://{}:{}".format(host, port))
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Close the ZeroMQ socket."""
|
"""Close the ZeroMQ socket."""
|
||||||
if not self.socket: return
|
if not self.socket:
|
||||||
|
return
|
||||||
self.socket.close()
|
self.socket.close()
|
||||||
self.socket = None
|
self.socket = None
|
||||||
|
|
||||||
@@ -65,8 +66,4 @@ class SocketBase(object):
|
|||||||
https://utrechtuniversity.youtrack.cloud/articles/N25B-A-14/RI-CB-Communication#negotiation
|
https://utrechtuniversity.youtrack.cloud/articles/N25B-A-14/RI-CB-Communication#negotiation
|
||||||
:rtype: dict
|
:rtype: dict
|
||||||
"""
|
"""
|
||||||
return {
|
return {"id": self.identifier, "port": self.port, "bind": not self.bound}
|
||||||
"id": self.identifier,
|
|
||||||
"port": self.port,
|
|
||||||
"bind": not self.bound
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user