Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Acap runtime proto image #77

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 89 additions & 3 deletions .github/workflows/build-proto-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,99 @@
name: Proto Build Workflow

on:
workflow_dispatch:
push:
branches:
- "main"
tags:
# semver, e.g. 1.2.0 (does not match 0.1.2)
- "[1-9]+.[0-9]+.[0-9]+"
# semver with prerelease info, e.g. 1.0.2-beta.1 or 1.2.3-rc.10
- "[1-9]+.[0-9]+.[0-9]+-[a-z]+.[0-9]+"
# do not match prerelease starting w/ 0, e.g. 1.0.2-beta.0 or 1.2.3-rc.01
- "![1-9]+.[0-9]+.[0-9]+-[a-z]+.[0]*"
# semver with date info, e.g. 1.0.2-20221125
- "[1-9]+.[0-9]+.[0-9]+-[0-9]+"
# do not match date starting w/ 0, e.g. 1.0.2-01232023
- "![1-9]+.[0-9]+.[0-9]+-[0]*"
pull_request:
branches:
- "main"

jobs:
dummy:
build_proto_image:
name: Build Proto Image
runs-on: ubuntu-latest

steps:
- run: echo "Placeholder workflow"
- name: Checkout repository
uses: actions/checkout@v4

- name: Create image metadata
id: meta
uses: ./.github/actions/metadata-action
with:
repository: axisecp/acap-runtime
get_version: "true"

- name: Build Proto image
uses: ./.github/actions/docker-build-push-action
with:
dockerfile: ./Dockerfile.proto
push: false
load: true
tags: axisecp/acap-runtime:${{ steps.meta.outputs.version }}-protofiles
use_qemu: true
platform: linux/arm64

- name: Extract proto files
run: |
container_id=$(docker create --platform linux/arm64 axisecp/acap-runtime:${{ steps.meta.outputs.version }}-protofiles)
docker cp $container_id:/build/param/proto_utils ./proto_utils_param
docker cp $container_id:/build/vdo/proto_utils ./proto_utils_vdo
docker cp $container_id:/build/tf/proto_utils ./proto_utils_tf
docker rm $container_id

- name: Verify proto files
run: |
echo "Verifying proto files..."

# Check param proto files
if [ "$(ls -A ./proto_utils_param)" ]; then
echo "param proto files found:"
ls -l ./proto_utils_param
else
echo "Error: param proto files are missing"
exit 1
fi

# Check vdo proto files
if [ "$(ls -A ./proto_utils_vdo)" ]; then
echo "vdo proto files found:"
ls -l ./proto_utils_vdo
else
echo "Error: vdo proto files are missing"
exit 1
fi

# Check tf proto files
if [ "$(ls -A ./proto_utils_tf)" ]; then
echo "tf proto files found:"
ls -l ./proto_utils_tf
else
echo "Error: tf proto files are missing"
exit 1
fi

echo "All proto files verified successfully"

- name: Push Proto image
if: success() && github.event_name != 'pull_request'
uses: ./.github/actions/docker-build-push-action
with:
dockerfile: ./Dockerfile.proto
push: true
platform: linux/arm64
use_qemu: true
tags: axisecp/acap-runtime:${{ steps.meta.outputs.version }}-protofiles
registry_user: ${{ secrets.ECOSYSTEM_SERVICE_USER_DOCKER_HUB }}
registry_token: ${{ secrets.ECOSYSTEM_ACCESS_TOKEN_DOCKER_HUB }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.github/test/__pycache__/
apis/
!apis/keyvaluestore.proto
!apis/wrappers
build/
build_x86_64-linux-gnu/
larod/
Expand Down
70 changes: 70 additions & 0 deletions Dockerfile.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# syntax=docker/dockerfile:1

Corallo marked this conversation as resolved.
Show resolved Hide resolved
ARG UBUNTU_VERSION=22.04
ARG TFSERVING_VERSION=2.9.0
pataxis marked this conversation as resolved.
Show resolved Hide resolved

# Build image, genearates proto files
FROM arm64v8/ubuntu:${UBUNTU_VERSION} AS build-image

Check warning on line 7 in Dockerfile.proto

View workflow job for this annotation

GitHub Actions / Build Proto Image

Base image platform does not match expected target platform

InvalidBaseImagePlatform: Base image arm64v8/ubuntu:22.04 was pulled with platform "linux/arm64", expected "linux/amd64" for current build

ARG TFSERVING_VERSION

RUN <<EOF
apt-get update && apt-get install -y --no-install-recommends \
python3 \
python3-pip \
git \
&& rm -rf /var/lib/apt/lists/*
EOF

# grpcio-tools contains protoc, which allows to build the pb2.py files in the install-tf.sh script.
# Installing directly grpcio-tools result in an older version of protobuf.
RUN pip install --no-cache-dir \
grpcio==1.46.3 \
protobuf==4.21.1 \
six==1.16.0
RUN pip install --no-dependencies \
grpcio-tools==1.47.0

# Build TensorFlow serving proto files
WORKDIR /build/tf

RUN <<EOF
git clone --depth 1 --branch v${TFSERVING_VERSION} https://github.com/tensorflow/tensorflow.git
git clone --depth 1 --branch ${TFSERVING_VERSION} https://github.com/tensorflow/serving.git

TF_DIR="./tensorflow"
TFS_DIR="./serving"
OUT_DIR="./proto_utils"

mkdir $OUT_DIR

PROTO_FILES="$TF_DIR/tensorflow/core/example/*.proto
$TF_DIR/tensorflow/core/framework/*.proto \
$TF_DIR/tensorflow/core/protobuf/*.proto \
$TFS_DIR/tensorflow_serving/apis/*.proto \
"

PROTO_FILES_GRPC="$TFS_DIR/tensorflow_serving/apis/predict.proto \
$TFS_DIR/tensorflow_serving/apis/prediction_service.proto \
"

python3 -m grpc_tools.protoc -I "$TF_DIR" -I "$TFS_DIR" --python_out="$OUT_DIR" $PROTO_FILES
python3 -m grpc_tools.protoc -I "$TF_DIR" -I "$TFS_DIR" --grpc_python_out="$OUT_DIR" $PROTO_FILES_GRPC

EOF
COPY apis/wrappers/tf_proto_utils.py ./proto_utils

#Build vdo proto
WORKDIR /build/vdo
COPY apis/videocapture.proto ./
RUN mkdir ./proto_utils && python3 -m grpc_tools.protoc -I . --python_out=./proto_utils --grpc_python_out=./proto_utils videocapture.proto
COPY apis/wrappers/vdo_proto_utils.py ./proto_utils

# Build keyvalue proto
WORKDIR /build/param
COPY apis/keyvaluestore.proto ./
RUN mkdir ./proto_utils && python3 -m grpc_tools.protoc -I . --python_out=./proto_utils --grpc_python_out=./proto_utils keyvaluestore.proto

# Saving required libraries versions into a file
RUN pip freeze | grep -E '^(grpcio|protobuf|six)==' > /build/requirements.txt

51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ If you are new to the world of ACAPs take a moment to check out
- [APIs](#apis)
- [Installation and usage](#installation-and-usage)
- [Installation](#installation)
- [Native ACAP application](#native-acap-application)
- [Containerized version](#containerized-version)
- [Configuration](#configuration)
- [Chip id](#chip-id)
- [TLS](#tls)
- [gRPC socket](#grpc-socket)
- [Examples](#examples)
- [Building ACAP Runtime](#building-acap-runtime)
- [Native ACAP application](#native-acap-application-2)
- [Containerized version](#containerized-version-2)
- [Building protofiles for Python](#building-protofiles-for-python)
- [Test suite](#test-suite)
- [Contributing](#contributing)
- [License](#license)
Expand Down Expand Up @@ -234,6 +239,52 @@ docker buildx build --file Dockerfile --build-arg ARCH=<ARCH> --tag acap-runtime

where `<ARCH>` is either `armv7hf` or `aarch64`.

The build is based on [axisecp/acap-native-sdk][docker-hub-acap-native-sdk]. To
base it on a different version than what is on main branch you can provide the
build arguments `VERSION` and `UBUNTU_VERSION` to select a specific tag of the
`acap-native-sdk` image. E.g. to use
[axisecp/acap-native-sdk:1.4_beta1-armv7hf-ubuntu22.04][docker-hub-acap-native-sdk-1.4_beta1-armv7hf-ubuntu22.04]:

```sh
docker buildx build --file Dockerfile.<ARCH> --tag acap-runtime:<ARCH> --build-arg VERSION=1.4beta1 --build-arg UBUNTU_VERSION=22.04 .
```

Once the application is installed it can then be started either in the device GUI **Apps** tab or by running:

```sh
docker run --rm axisecp/acap-runtime:<version>-<ARCH> <device IP> <device password> start
```

Where `<device IP>` is the IP address of the device and `<device password>` is the password for the root user.

The application can be stopped and uninstalled by using the device GUI, or by running:

```sh
docker run --rm axisecp/acap-runtime:<version>-<ARCH> <device IP> <device password> stop
docker run --rm axisecp/acap-runtime:<version>-<ARCH> <device IP> <device password> remove
```

<!-- markdownlint-disable MD024 -->
### Containerized version
<!-- markdownlint-enable MD024 -->

To build the containerized version, use either the Dockerfile `Dockerfile.armv7hf` or `Dockerfile.aarch64`. Select the one that matches the architecture of your device:

```sh
# Build ACAP Runtime containerized version
docker buildx build --file Dockerfile.<ARCH> --tag acap-runtime:<ARCH>-containerized .
```

## Building protofiles for Python

The repository includes a Dockerfile (`Dockerfile.proto`) for building the APIs protofiles for Python. The Dockerfile generates the necessary Python files from the protobuf definitions, allowing gRPC communication with the ACAP Runtime service. This means that applications can copy these prebuilt files from ACAP Runtime container image instead of having to build the protofiles themselves.

To build the protofiles:

```sh
docker build -f Dockerfile.proto -t acap-runtime-proto:latest .
```

## Test suite

The repo contains a test suite project to verify that ACAP Runtime works as expected
Expand Down
2 changes: 1 addition & 1 deletion apis/keyvaluestore.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
Loading
Loading