Skip to content

Commit

Permalink
Merge pull request #579 from BrewBlox/develop
Browse files Browse the repository at this point in the history
Edge release
  • Loading branch information
steersbob authored Jul 27, 2023
2 parents e852f40 + adb6e44 commit 2c6cb7c
Show file tree
Hide file tree
Showing 63 changed files with 1,944 additions and 8,732 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.venv/
.vscode/
16 changes: 7 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ jobs:
- name: Download firmware
run: |
bash dev/download-firmware.sh
poetry run invoke download-firmware
- name: Test
run: |
poetry run pytest
poetry run flake8
- name: (Service) Run setup script
- name: Build
run: |
bash docker/before_build.sh
poetry run invoke build
- name: (Service) Build Docker image
uses: docker/build-push-action@v4
Expand All @@ -66,11 +66,8 @@ jobs:
tags: ${{ steps.service_meta.outputs.tags }}
labels: ${{ steps.service_meta.outputs.labels }}
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
context: docker

- name: (Flasher) Run setup script
run: |
bash flasher/before_build.sh
file: Dockerfile.service
context: .

- name: (Flasher) Build Docker image
uses: docker/build-push-action@v4
Expand All @@ -79,4 +76,5 @@ jobs:
tags: ${{ steps.flasher_meta.outputs.tags }}
labels: ${{ steps.flasher_meta.outputs.labels }}
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
context: flasher
file: Dockerfile.flasher
context: .
5 changes: 3 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"editorconfig.editorconfig",
"littlefoxteam.vscode-python-test-adapter",
"ms-python.python",
"ms-python.vscode-pylance"
"ms-python.vscode-pylance",
"ms-python.autopep8"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
}
8 changes: 6 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@
"python.languageServer": "Pylance",
"python.analysis.extraPaths": [
"brewblox_devcon_spark/codec/proto-compiled"
]
}
],
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
},
"python.formatting.provider": "none"
}
File renamed without changes.
9 changes: 4 additions & 5 deletions docker/Dockerfile → Dockerfile.service
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
FROM python:3.9 as base
FROM python:3.9-bullseye as base

ENV PIP_EXTRA_INDEX_URL=https://www.piwheels.org/simple
ENV PIP_FIND_LINKS=/wheeley

COPY ./dist /app/dist
COPY ./requirements.txt /app/requirements.txt
COPY ./firmware /app/firmware

RUN set -ex \
&& mkdir /wheeley \
&& pip3 install --upgrade pip wheel setuptools \
&& pip3 wheel --wheel-dir=/wheeley -r /app/requirements.txt \
&& pip3 wheel --wheel-dir=/wheeley /app/dist/* \
&& pip3 wheel --wheel-dir=/wheeley -r /app/dist/requirements.txt \
&& pip3 wheel --wheel-dir=/wheeley /app/dist/*.tar.gz \
&& ARCH="$(dpkg --print-architecture)" \
&& if [ "${ARCH}" = "amd64" ]; then OTHER_SIM='brewblox-{arm32,arm64}.sim'; fi \
&& if [ "${ARCH}" = "armhf" ]; then OTHER_SIM='brewblox-{amd64,arm64}.sim'; fi \
&& if [ "${ARCH}" = "arm64" ]; then OTHER_SIM='brewblox-{amd64,arm32}.sim'; fi \
&& bash -c "rm /app/firmware/${OTHER_SIM}" \
&& rm /app/firmware/*.elf

FROM python:3.9-slim
FROM python:3.9-slim-bullseye
EXPOSE 5000
WORKDIR /app

Expand Down
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubun
sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
```

When updating firmware, the protobuf compiler is required:

```sh
sudo apt install -y \
protobuf-compiler
```

## Firmware

The Spark service is coupled to a specific Spark firmware version.
Expand All @@ -38,14 +31,14 @@ The firmware.ini file contains a sha for the relevant brewblox-proto commit.

The brewblox-proto repository only contains .proto files. The associated pb2.py files are compiled here and committed into version control.

Firmware dependency management is handled by scripts in *dev/*:
Firmware dependency management is handled by [invoke](https://docs.pyinvoke.org/en/stable/index.html) commands, defined in `tasks.py`:

**[update-firmware.sh](./dev/update-firmware.sh)** fetches the latest firmware.ini file for a given firmware build (*develop* by default), checks out the associated brewblox-proto commit for the submodule, and calls both `compile-proto.sh` and `download-firmware.sh`.
`invoke update-firmware` fetches the latest firmware.ini file for a given firmware build (*develop* by default), checks out the associated brewblox-proto commit for the submodule, and calls both `compile-proto.sh` and `download-firmware.sh`.

**[compile-proto.sh](./dev/compile-proto.sh)** compiles .proto files found in the proto submodule into _pb2.py python files.
`invoke compile-proto` compiles .proto files found in the proto submodule into _pb2.py python files.
The_pb2.py files are committed into version control.

**[download-firmware.sh](./dev/download-firmware.sh)** reads the version information in firmware.ini,
`invoke download-firmware` reads the version information in firmware.ini,
and downloads the associated binary files into `firmware/`.
The binary files are **not** committed into version control.
Instead, they are re-downloaded during the CI build.
Expand All @@ -54,6 +47,6 @@ Instead, they are re-downloaded during the CI build.

- Commit the firmware changes to the *develop* branch in the [Brewblox firmware](https://github.com/BrewBlox/brewblox-firmware) repository.
- Wait until the firmware CI build is done.
- Run `bash dev/update-firmware.sh`
- Run `invoke update-firmware`
- Run `pytest` to verify that no code changes are required.
- Commit the changed files (firmware.ini, the proto submodule, and compiled _pb2.py files).
94 changes: 93 additions & 1 deletion brewblox_devcon_spark/api/blocks_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from brewblox_service import brewblox_logger, mqtt

from brewblox_devcon_spark import controller
from brewblox_devcon_spark.models import Block, BlockIdentity, BlockNameChange
from brewblox_devcon_spark.models import (Block, BlockIdentity,
BlockIdentityList, BlockList,
BlockNameChange)

LOGGER = brewblox_logger(__name__)
routes = web.RouteTableDef()
Expand Down Expand Up @@ -149,6 +151,96 @@ async def post(self, args: BlockIdentity) -> r200[BlockIdentity]:
)


@routes.view('/blocks/batch/create')
class BatchCreateView(BlocksView):
async def post(self, args: BlockList) -> r200[list[Block]]:
"""
Create multiple blocks.
Tags: Blocks
"""
blocks_in = args.__root__
blocks_out = []
for block in blocks_in:
blocks_out.append(await self.controller.create_block(block))
await self.publish(changed=blocks_out)
return web.json_response([
block.dict() for block in blocks_out
],
status=201)


@routes.view('/blocks/batch/read')
class BatchReadView(BlocksView):
async def post(self, args: BlockIdentityList) -> r200[list[Block]]:
"""
Read multiple existing blocks.
Tags: Blocks
"""
blocks_in = args.__root__
blocks_out = []
for block in blocks_in:
blocks_out.append(await self.controller.read_block(block))
return web.json_response([
block.dict() for block in blocks_out
])


@routes.view('/blocks/batch/write')
class BatchWriteView(BlocksView):
async def post(self, args: BlockList) -> r200[list[Block]]:
"""
Write multiple existing blocks.
Tags: Blocks
"""
blocks_in = args.__root__
blocks_out = []
for block in blocks_in:
blocks_out.append(await self.controller.write_block(block))
await self.publish(changed=blocks_out)
return web.json_response([
block.dict() for block in blocks_out
])


@routes.view('/blocks/batch/patch')
class BatchPatchView(BlocksView):
async def post(self, args: BlockList) -> r200[list[Block]]:
"""
Patch multiple existing blocks.
Tags: Blocks
"""
blocks_in = args.__root__
blocks_out = []
for block in blocks_in:
blocks_out.append(await self.controller.patch_block(block))
await self.publish(changed=blocks_out)
return web.json_response([
block.dict() for block in blocks_out
])


@routes.view('/blocks/batch/delete')
class BatchDeleteView(BlocksView):
async def post(self, args: BlockIdentityList) -> r200[list[Block]]:
"""
Delete multiple existing blocks.
Tags: Blocks
"""
idents_in = args.__root__
idents_out = []
for ident in idents_in:
idents_out.append(await self.controller.delete_block(ident))
await self.publish(deleted=idents_out)
return web.json_response([
ident.dict() for ident in idents_out
])


@routes.view('/blocks/all/read')
class ReadAllView(BlocksView):
async def post(self) -> r200[list[Block]]:
Expand Down
2 changes: 2 additions & 0 deletions brewblox_devcon_spark/codec/pb2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import brewblox_pb2
import command_pb2
import DigitalActuator_pb2
import DigitalInput_pb2
import DisplaySettings_pb2
import DS2408_pb2
import DS2413_pb2
Expand Down Expand Up @@ -53,6 +54,7 @@
'brewblox_pb2',
'command_pb2',
'DigitalActuator_pb2',
'DigitalInput_pb2',
'DisplaySettings_pb2',
'DS2408_pb2',
'DS2413_pb2',
Expand Down
Loading

0 comments on commit 2c6cb7c

Please sign in to comment.