Skip to content

Commit 891b99f

Browse files
previavivaceRoberto Previtera
authored
fixes (#169)
* tf 2.7 * revert tf 2.1 * bump numpy ver * bump requirements_stub * bump requirements_stub * led ws2812b * led ws2812b * led ws2812b * add listMusicPackages api * fix musicPackage export * remove coderbot-copy.py * fix music package removal * v1 feature parity * fix #155 * fix program status and log with v2 * update ci * add default activity init * add default activity init * add default activity * activity default parameters * bullseye wip * bullseye wip * Update audioControls.py bullseye: "PCM" => "Headphone" * bullseye wip * Update audio.py fix audio sampling rate * update stock activities * Update program.py fix Program.load() when program non found * Update activity_default.json add "shadow" input blocks * Update coderbot.py * no longer init_activities * move init_activities on frontend for i18n * fix v4.1 bugs * fix 4.1 bugs * fix 4.1 bugs * fix 4.1 bugs * fix 4.1 bugs * fix v4.1 bugs * fix 4.1 bugs * fix 4.1 bugs * fix 4.1 bugs * fix 4.1 bugs * fix 4.1 bugs * Update wifi.py * Update wifi.py * add CONTRIBUTING.md (#162) Co-authored-by: previ <roberto.previtera@gmail.com> * fix event * Refactor API (#166) * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * merge remove_old_ui * merge remove_old_ui * fix merge * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * WIP #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wop #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #184 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 Co-authored-by: Roberto Previtera <roberto@MacBook-Air.station> * Refactor api v3 (#167) * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * merge remove_old_ui * merge remove_old_ui * fix merge * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * WIP #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wop #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #184 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 Co-authored-by: Roberto Previtera <roberto@MacBook-Air.station> * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * wip #164 * status * status * status * status * status * add stub * stub * remove unnecessary updatePckages dir * disable cicleci Co-authored-by: Antonio Vivace <avivace4@gmail.com> Co-authored-by: Roberto Previtera <roberto@MacBook-Air.station>
1 parent a04ec7a commit 891b99f

File tree

12 files changed

+134
-83
lines changed

12 files changed

+134
-83
lines changed
File renamed without changes.

.github/workflows/build_backend.yml

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
container: coderbot/coderbot-ci:3.9-bullseye-slim
1212
steps:
1313
- uses: actions/checkout@v3 # Checking out the repo
14-
- run: pip install -r requirements_stub.txt
14+
- run: pip install -r docker/stub/requirements.txt
1515
- run: |
1616
export PYTHONPATH=./coderbot:./stub:./test
1717
mkdir test-reports
@@ -58,7 +58,7 @@ jobs:
5858
type=ref,event=pr
5959
# push event
6060
type=sha,enable=true,prefix=git-,format=short
61-
- uses: actions/checkout@v2 # Checking out the repo
61+
- uses: actions/checkout@v3 # Checking out the repo
6262
- name: Set up QEMU
6363
uses: docker/setup-qemu-action@v2
6464
- name: Set up Docker Buildx
@@ -74,9 +74,46 @@ jobs:
7474
uses: docker/build-push-action@v3
7575
with:
7676
push: true
77+
build-args: CODERBOT_VERSION=${{github.ref_name}}-${{github.sha}}
7778
platforms: linux/arm/v7
7879
tags: ${{ steps.meta.outputs.tags }}
7980
context: .
8081
file: docker/Dockerfile
8182
cache-from: type=registry,ref=ghcr.io/coderbotorg/backend:latest
8283
cache-to: type=inline
84+
85+
release-stub:
86+
needs: [test]
87+
runs-on: ubuntu-latest
88+
steps:
89+
- name: Docker meta
90+
id: meta
91+
uses: docker/metadata-action@v4
92+
with:
93+
# list of Docker images to use as base name for tags
94+
images: ghcr.io/coderbotorg/backend
95+
# generate Docker tags based on the following events/attributes
96+
tags: |
97+
# always latest
98+
type=raw,value=stub-latest
99+
- uses: actions/checkout@v3 # Checking out the repo
100+
- name: Set up Docker Buildx
101+
id: buildx
102+
uses: docker/setup-buildx-action@v2
103+
- name: Login to DockerHub
104+
uses: docker/login-action@v2
105+
with:
106+
registry: ghcr.io
107+
username: ${{ github.actor }}
108+
password: ${{ secrets.GITHUB_TOKEN }}
109+
- name: Build and push
110+
uses: docker/build-push-action@v3
111+
with:
112+
push: true
113+
build-args: CODERBOT_VERSION=${{github.ref_name}}-${{github.sha}}
114+
platforms: linux/amd64
115+
tags: ${{ steps.meta.outputs.tags }}
116+
context: .
117+
file: docker/stub/Dockerfile
118+
cache-from: type=registry,ref=ghcr.io/coderbotorg/backend:stub-latest
119+
cache-to: type=inline

coderbot/api.py

Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ def get_status():
6868
uptime = 0
6969
try:
7070
uptime = subprocess.check_output(["uptime"]).decode('utf-8').replace('\n', '')
71-
except:
71+
except Exception:
7272
pass
7373

7474
internet_status = False
7575
try:
7676
urllib.request.urlopen("https://coderbot.org")
7777
internet_status = True
78-
except:
78+
except Exception:
7979
pass
8080

8181
return {'internet_status': internet_status,
@@ -87,42 +87,20 @@ def get_info():
8787
Expose informations about the CoderBot system.
8888
(Cached method)
8989
"""
90-
backend_commit = "undefined"
91-
coderbot_version = "undefined"
92-
update_status = "ok"
9390
device = {}
94-
motors = 'undefined'
95-
96-
try:
97-
# manifest.json is generated while building/copying the backend
98-
with open('manifest.json', 'r') as f:
99-
metadata = json.load(f)
100-
backend_commit = metadata["backend_commit"][0:7]
101-
coderbot_version = metadata["backend_version"][0:7]
102-
except Exception:
103-
pass
104-
105-
try:
106-
encoder = bool(Config.read().get('encoder'))
107-
if(encoder):
108-
motors = 'DC encoder motors'
109-
else:
110-
motors = 'DC motors'
111-
except Exception:
112-
pass
113-
11491
serial = get_serial()
11592

11693
try:
117-
device = Baleba.get_instance().device()
94+
device = Balena.get_instance().device()
95+
logging.info("device: %s", str(device))
11896
except Exception:
11997
pass
120-
return { 'backend_commit': device.get("commit"),
121-
'coderbot_version': coderbot_version,
98+
99+
return { 'release_commit': device.get("commit"),
100+
'coderbot_version': os.getenv("CODERBOT_VERSION"),
122101
'update_status': device.get("status"),
123102
'kernel': device.get("os_version"),
124-
'serial': serial,
125-
'motors': motors }
103+
'serial': serial }
126104

127105
prog = None
128106
prog_engine = ProgramEngine.get_instance()
@@ -249,39 +227,6 @@ def deletePhoto(name):
249227
except FileNotFoundError:
250228
return 404
251229

252-
## System
253-
254-
def status():
255-
sts = get_status()
256-
# getting reset log file
257-
data = []
258-
try:
259-
with open('/home/pi/coderbot/logs/reset_trigger_service.log', 'r') as log_file:
260-
data = [x for x in log_file.read().split('\n') if x]
261-
except Exception: # direct control case
262-
pass # if file doesn't exist, no restore as ever been performed. return empty data
263-
264-
265-
return {
266-
"status": "ok",
267-
"internetConnectivity": sts["internet_status"],
268-
"temp": sts["temp"],
269-
"uptime": sts["uptime"],
270-
"log": data
271-
}
272-
273-
def info():
274-
inf = get_info()
275-
return {
276-
"model": 1,
277-
"version": inf["coderbot_version"],
278-
"backend commit build": inf["backend_commit"],
279-
"kernel" : inf["kernel"],
280-
"update status": inf["update_status"],
281-
"serial": inf["serial"],
282-
"motors": inf["motors"]
283-
}
284-
285230
def restoreSettings():
286231
Config.restore()
287232
return restart()

coderbot/balena/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@ def __init__(self):
2121
def purge(self):
2222
logging.debug("reset bot")
2323
req = Request(f'{self.supervisor_address}/v1/purge?apikey={self.supervisor_key}', data=self.app_id_data, headers=self.headers, method='POST')
24-
return urlopen(req).read()
24+
return json.load(urlopen(req))
2525

2626
def shutdown(self):
2727
logging.debug("shutdown bot")
2828
req = Request(f'{self.supervisor_address}/v1/shutdown?apikey={self.supervisor_key}', headers=self.headers, method='POST')
29-
return urlopen(req).read()
29+
return json.load(urlopen(req))
3030

3131
def restart(self):
3232
logging.debug("restarting bot")
3333
req = Request(f'{self.supervisor_address}/v1/restart?apikey={self.supervisor_key}', data=self.app_id_data, headers=self.headers, method='POST')
34-
return urlopen(req).read()
34+
return json.load(urlopen(req))
3535

3636
def reboot(self):
3737
logging.debug("reboot bot")
3838
req = Request(f'{self.supervisor_address}/v1/reboot?apikey={self.supervisor_key}', headers=self.headers, method='POST')
39-
return urlopen(req).read()
39+
return json.load(urlopen(req))
4040

4141
def device(self):
4242
logging.debug("reboot bot", f'{self.supervisor_address}get?apikey={self.supervisor_key}')
43-
req = Request(f'{self.supervisor_address}/device?apikey={self.supervisor_key}', headers=self.headers, method='GET')
43+
req = Request(f'{self.supervisor_address}/v1/device?apikey={self.supervisor_key}', headers=self.headers, method='GET')
4444
return json.load(urlopen(req))

coderbot/v1.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ paths:
397397
description: "upload failed"
398398
/system/status:
399399
get:
400-
operationId: "api.status"
400+
operationId: "api.get_status"
401401
summary: "Bot general informations, execution status and reset log file"
402402
tags:
403403
- System operations
@@ -422,7 +422,7 @@ paths:
422422
description: Test ended.
423423
/system/info:
424424
get:
425-
operationId: "api.info"
425+
operationId: "api.get_info"
426426
summary: "Bot general informations and execution status"
427427
tags:
428428
- System operations

docker/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ RUN pip install --no-cache-dir -r /tmp/requirements.txt
5050
RUN mkdir -p /coderbot && \
5151
mkdir -p /coderbot/data && \
5252
mkdir -p /coderbot/logs && \
53-
mkdir -p /coderbot/updatePackages && \
5453
mkdir -p /coderbot/cnn_modules && \
5554
mkdir -p /coderbot/coderbot && \
5655
mkdir -p /coderbot/defaults && \
@@ -63,5 +62,9 @@ ADD sounds /coderbot/sounds/.
6362
ADD docker/scripts/*.sh /tmp/.
6463
RUN /tmp/install_generic_cnn_models.sh
6564
RUN /tmp/install_lib_firmware.sh
65+
ADD docker/start.sh /coderbot/.
6666

67-
ENTRYPOINT cd /coderbot && modprobe i2c-dev && python3 coderbot/main.py
67+
ARG CODERBOT_VERSION
68+
ENV CODERBOT_VERSION=${CODERBOT_VERSION}
69+
70+
ENTRYPOINT /coderbot/start.sh

docker/start.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
cd /coderbot && modprobe i2c-dev && python3 coderbot/main.py

docker/stub/Dockerfile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
FROM debian:bullseye-slim
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
RUN apt-get update -y && apt-get install -y \
6+
procps \
7+
sudo \
8+
wget \
9+
unzip \
10+
xz-utils \
11+
ffmpeg \
12+
portaudio19-dev \
13+
python3 \
14+
python3-pip \
15+
libopenjp2-7-dev \
16+
libtiff5 \
17+
libatlas-base-dev \
18+
libhdf5-dev \
19+
alsa-utils \
20+
espeak \
21+
libharfbuzz-bin \
22+
libwebp6 \
23+
libilmbase25 \
24+
libgstreamer1.0-0 \
25+
libavcodec-extra58 \
26+
libavformat58 \
27+
libopencv-dev \
28+
zbar-tools \
29+
libzbar0 \
30+
sox \
31+
libsox-fmt-all \
32+
avrdude \
33+
tesseract-ocr \
34+
tesseract-ocr-eng \
35+
tesseract-ocr-ita \
36+
tesseract-ocr-fra \
37+
tesseract-ocr-spa \
38+
tesseract-ocr-deu
39+
40+
ADD docker/stub/requirements.txt /tmp/.
41+
RUN pip install --no-cache-dir -r /tmp/requirements.txt
42+
43+
RUN mkdir -p /coderbot && \
44+
mkdir -p /coderbot/data && \
45+
mkdir -p /coderbot/logs && \
46+
mkdir -p /coderbot/updatePackages && \
47+
mkdir -p /coderbot/cnn_modules && \
48+
mkdir -p /coderbot/coderbot && \
49+
mkdir -p /coderbot/defaults && \
50+
mkdir -p /coderbot/sounds
51+
52+
ADD coderbot /coderbot/coderbot/.
53+
ADD stub /coderbot/stub/.
54+
ADD test /coderbot/test/.
55+
ADD defaults /coderbot/defaults/.
56+
ADD sounds /coderbot/sounds/.
57+
58+
ADD docker/scripts/*.sh /tmp/.
59+
RUN /tmp/install_generic_cnn_models.sh
60+
ADD docker/stub/start.sh /coderbot/.
61+
62+
ARG CODERBOT_VERSION
63+
ENV CODERBOT_VERSION=${CODERBOT_VERSION}
64+
65+
ENTRYPOINT /coderbot/start.sh

requirements_stub.txt renamed to docker/stub/requirements.txt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,9 @@ pybind11==2.10.0
2626
inflection==0.5.1
2727
event-channel==0.4.3
2828
pytz==2022.2.1
29-
cachetools==5.2.0
30-
31-
# IO extensions
32-
pigpio==1.78
33-
smbus2==0.4.2
34-
spidev==3.5
3529

3630
# Audio
3731
sox==1.4.1
38-
PyAudio==0.2.12
39-
pyalsaaudio==0.9.2
4032

4133
# Computer Vision
4234
grpcio==1.48.1
@@ -48,4 +40,5 @@ tflite-runtime==2.10.0
4840
pytesseract==0.3.10
4941
pyzbar==0.1.9
5042

51-
#picamera==1.13
43+
#I/O
44+
spidev==3.5

docker/stub/start.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
export PYTHONPATH=./stub:./test:./coderbot
4+
cd /coderbot
5+
python3 coderbot/main.py

0 commit comments

Comments
 (0)