Skip to content

Commit

Permalink
Devguide: Fix and enhance local EdgeHub build (#6077)
Browse files Browse the repository at this point in the history
The devguide specified a set of commands to build EdgeHub locally. These stopped working when we made the change to build the rocksdb `.so` file every build. 

To fix this I created two scripts:
1. buildRocksDb.sh: This is the current bash logic in the devops template which builds rocksdb and copies out the binary
2. buildLocalEdgeHub.sh: This uses buildRocksDB.sh, along with another set of scripts to build a local EdgeHub image.

Passing  build (waiting for results):
https://msazure.visualstudio.com/One/_build/results?buildId=51582888&view=results

***Please replace this line with your PR description and read PR checklist below***

## Azure IoT Edge PR checklist:
  • Loading branch information
and-rewsmith authored Feb 7, 2022
1 parent ca22a6b commit 5dd965f
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 13 deletions.
8 changes: 1 addition & 7 deletions builds/misc/templates/build-rocksdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ stages:
arch: arm64v8
postfix: arm64
steps:
- bash: |
build_image=rocksdb-build:master-$(postfix)-$(Build.BuildNumber) && \
mkdir -p $(Build.ArtifactStagingDirectory)/librocksdb && \
cd $(System.DefaultWorkingDirectory)/edge-util/docker/linux/$(arch) && \
docker build --tag ${build_image} . && \
docker run --rm -v $(Build.ArtifactStagingDirectory)/librocksdb:/artifacts \
${build_image} cp /publish/librocksdb.so.$(postfix) /artifacts
- script: scripts/linux/buildRocksDb.sh --output-dir $(Build.ArtifactStagingDirectory) --postfix $(postfix) --build-number $(Build.BuildNumber) --arch $(arch)
displayName: Build and copy out rocksdb lib
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifacts to VSTS'
Expand Down
8 changes: 2 additions & 6 deletions doc/devguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,9 @@ reportgenerator "-reports:TestResults\*\*.coveragexml" "-targetdir:report"

## Build Edge Hub Container Locally

Sometimes it is useful to build the Edge Hub container locally. If you want to do so you can run the below set of scripts:
Sometimes it is useful to build the Edge Hub container locally. If you want to do so you can run the below script:
```
scripts/linux/buildBranch.sh
scripts/linux/cross-platform-rust-build.sh --os alpine --arch amd64 --build-path mqtt/mqttd
scripts/linux/cross-platform-rust-build.sh --os alpine --arch amd64 --build-path edge-hub/watchdog
scripts/linux/consolidate-build-artifacts.sh --artifact-name "edge-hub"
scripts/linux/buildImage.sh -r "$(registry.address)" -u "$(registry.user)" -p "$(registry.password)" -i "${{ parameters.imageName }}" -n "${{ parameters.namespace }}" -P "${{ parameters.project }}" -v "${{ parameters.version }} --bin-dir target"
./scripts/linux/buildLocalEdgeHub.sh --registry-address "$(registry.address)" --version "$(version)"
```

## Build Manifest Image
Expand Down
63 changes: 63 additions & 0 deletions scripts/linux/buildLocalEdgeHub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

###############################################################################
# This script builds an EdgeHub image locally
###############################################################################

###############################################################################
# Define Environment Variables
###############################################################################
# Get directory of running script
DIR=$(cd "$(dirname "$0")" && pwd)
BUILD_REPOSITORY_LOCALPATH=$(realpath ${BUILD_REPOSITORY_LOCALPATH:-$DIR/../..})
SCRIPT_NAME=$(basename "$0")

###############################################################################
# Print usage information pertaining to this script and exit
###############################################################################
function usage() {
echo "$SCRIPT_NAME [options]"
echo ""
echo "options"
echo "--registry-address Path where to put librocksdb folder containing built artifact."
echo "--version Tag for built edge hub image."
echo " -h, --help Print this help and exit."
exit 1
}

function print_help_and_exit() {
echo "Run $SCRIPT_NAME --help for more information."
exit 1
}

###############################################################################
# Obtain and validate the options supported by this script
###############################################################################
function process_args() {
save_next_arg=0
for arg in "$@"; do
if [ ${save_next_arg} -eq 1 ]; then
REGISTRY_ADDRESS=$arg
save_next_arg=0
elif [ ${save_next_arg} -eq 2 ]; then
VERSION=$arg
save_next_arg=0
else
case "$arg" in
"-h" | "--help") usage ;;
"--registry-address") save_next_arg=1 ;;
"--version") save_next_arg=2 ;;
*) usage ;;
esac
fi
done
}

process_args "$@"

scripts/linux/buildBranch.sh
scripts/linux/cross-platform-rust-build.sh --os alpine --arch amd64 --build-path mqtt/mqttd
scripts/linux/cross-platform-rust-build.sh --os alpine --arch amd64 --build-path edge-hub/watchdog
scripts/linux/consolidate-build-artifacts.sh --artifact-name "edge-hub"
scripts/linux/buildRocksDb.sh --output-dir $(pwd)/target/publish/edge-hub --postfix amd64 --build-number debug --arch amd64
scripts/linux/buildImage.sh -r $REGISTRY_ADDRESS -i "azureiotedge-hub" -n "microsoft" -P "edge-hub" -v $VERSION --bin-dir "target"
73 changes: 73 additions & 0 deletions scripts/linux/buildRocksDb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash

###############################################################################
# This script builds cross compiles rocksdb .so file using docker buildx
###############################################################################

###############################################################################
# Define Environment Variables
###############################################################################
# Get directory of running script
DIR=$(cd "$(dirname "$0")" && pwd)

BUILD_REPOSITORY_LOCALPATH=$(realpath ${BUILD_REPOSITORY_LOCALPATH:-$DIR/../..})
SCRIPT_NAME=$(basename "$0")

###############################################################################
# Print usage information pertaining to this script and exit
###############################################################################
function usage() {
echo "$SCRIPT_NAME [options]"
echo ""
echo "options"
echo "--output-dir Path where to put librocksdb folder containing built artifact."
echo "--postfix Options: amd64, armhf, arm64."
echo "--build-number Build number for which to tag image."
echo "--arch Options: amd64, arm32v7, arm64v8."
echo " -h, --help Print this help and exit."
exit 1
}

function print_help_and_exit() {
echo "Run $SCRIPT_NAME --help for more information."
exit 1
}

###############################################################################
# Obtain and validate the options supported by this script
###############################################################################
function process_args() {
save_next_arg=0
for arg in "$@"; do
if [ ${save_next_arg} -eq 1 ]; then
OUTPUT_DIR=$arg
save_next_arg=0
elif [ ${save_next_arg} -eq 2 ]; then
POSTFIX=$arg
save_next_arg=0
elif [ ${save_next_arg} -eq 3 ]; then
BUILD_NUMBER=$arg
save_next_arg=0
elif [ ${save_next_arg} -eq 4 ]; then
ARCH=$arg
save_next_arg=0
else
case "$arg" in
"-h" | "--help") usage ;;
"--output-dir") save_next_arg=1 ;;
"--postfix") save_next_arg=2 ;;
"--build-number") save_next_arg=3 ;;
"--arch") save_next_arg=4 ;;
*) usage ;;
esac
fi
done
}

process_args "$@"

build_image=rocksdb-build:master-$POSTFIX-$BUILD_NUMBER
mkdir -p $OUTPUT_DIR/librocksdb
cd $BUILD_REPOSITORY_LOCALPATH/edge-util/docker/linux/$ARCH
docker build --tag ${build_image} .
docker run --rm -v $OUTPUT_DIR/librocksdb:/artifacts ${build_image} cp /publish/librocksdb.so.$POSTFIX /artifacts

0 comments on commit 5dd965f

Please sign in to comment.