Skip to content

Commit

Permalink
Moving proto-build to ACAP runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelo DelliSanti authored and johan-olsson-work committed Sep 10, 2024
1 parent 7c63884 commit 444a334
Show file tree
Hide file tree
Showing 8 changed files with 448 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .github/actions/docker-build-push-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ inputs:
description: List of output destinations (format type=local,dest=path)
required: false
default: ''
platform:
description: "Target platform for the build (e.g., linux/amd64, linux/arm64)"
required: false
default: ''

runs:
using: composite
Expand Down Expand Up @@ -94,3 +98,4 @@ runs:
target: ${{ inputs.target }}
provenance: ${{ inputs.provenance }}
outputs: ${{ inputs.outputs }}
platforms: ${{ inputs.platform }}
97 changes: 94 additions & 3 deletions .github/workflows/build-proto-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,104 @@
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:
paths-ignore:
# do not run if only markdown or other administrative files have been updated
- "*.md"
- "CODEOWNERS"
- "LICENSE"
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()
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
85 changes: 85 additions & 0 deletions Dockerfile.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# syntax=docker/dockerfile:1

ARG UBUNTU_VERSION=22.04
ARG TFSERVING_VERSION=2.9.0
ARG GRPC_VERSION=1.46.3
ARG PROTOBUF_VERSION=4.21.1
ARG SIX_VERSION=1.16.0
ARG GRPCIO_TOOLS_VERSION=1.47.0

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

ARG TFSERVING_VERSION
ARG GRPC_VERSION
ARG PROTOBUF_VERSION
ARG SIX_VERSION
ARG GRPCIO_TOOLS_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 <<EOF
pip install --no-cache-dir \
grpcio==${GRPC_VERSION} \
protobuf==${PROTOBUF_VERSION} \
six==${SIX_VERSION}
pip install --no-dependencies \
grpcio-tools==${GRPCIO_TOOLS_VERSION}
EOF
# 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 -p $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 <<EOF
mkdir -p ./proto_utils
python3 -m grpc_tools.protoc -I . --python_out=./proto_utils --grpc_python_out=./proto_utils videocapture.proto
EOF
COPY apis/wrappers/vdo_proto_utils.py ./proto_utils
# Build keyvalue proto
WORKDIR /build/param
COPY apis/keyvaluestore.proto ./
RUN <<EOF
mkdir -p ./proto_utils
python3 -m grpc_tools.protoc -I . --python_out=./proto_utils --grpc_python_out=./proto_utils keyvaluestore.proto
EOF
# Saving required libraries versions into a file
RUN pip freeze | grep -E '^(grpcio|protobuf|six)==' > /build/requirements.txt
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ If you are new to the world of ACAPs take a moment to check out
- [gRPC socket](#grpc-socket)
- [Examples](#examples)
- [Building ACAP Runtime](#building-acap-runtime)
- [Building protofiles for Python](#building-protofiles-for-python)
- [Test suite](#test-suite)
- [Contributing](#contributing)
- [License](#license)
Expand Down Expand Up @@ -234,6 +235,16 @@ docker buildx build --file Dockerfile --build-arg ARCH=<ARCH> --tag acap-runtime
where `<ARCH>` is either `armv7hf` or `aarch64`.
## 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

0 comments on commit 444a334

Please sign in to comment.