Skip to content
Snippets Groups Projects
Unverified Commit 589fa6a7 authored by Andrej Shadura's avatar Andrej Shadura
Browse files

Upload delta bundles to hawkBit


The upload is considered successful even if it fails, since the
Apertis hawkBit server is not yet production-ready and may not
respond at all times.

Signed-off-by: default avatarAndrej Shadura <andrew.shadura@collabora.co.uk>
parent 33532a7f
No related branches found
No related tags found
No related merge requests found
Pipeline #94293 passed
......@@ -269,6 +269,13 @@ def buildOStree(architecture, type, board, debosarguments = "", repo = "repo") {
--inline \
--min-fallback-size=1024 \
--filename ${image_name}.delta""")
withCredentials([usernamePassword(credentialsId: 'hawkbit', usernameVariable: 'username', passwordVariable: 'password')]) {
sh(script: """
cd ${PIPELINE_VERSION}/${architecture}/${type}
${WORKSPACE}/scripts/hawkbit-upload.sh -u http://aura.collabora.co.uk:8080 ${username} ${password} distribution "apertis_${release}" "Apertis ${release}" "${PIPELINE_VERSION}" os ${image_name}.delta || true
""")
}
}
def buildOStreeRollbackDelta(architecture, type, board, debosarguments = "", repo = "repo") {
......
#!/bin/sh
set -e
usage() {
echo "$0 [OPTIONS] user password <command>
options:
-u URL base URL of HawkBit update server, default to http://localhost:8080
-h display this help and exit
commands:
- target <target id> <name> <security token> <description>
- distribution <name> <description> <version> <type> artifacts...
type can be 'os', 'app' or 'os_app'
"
exit 1
}
check_error() {
error="$(echo "$1" | jq -r 'if type != "array" then .errorCode // "" else "" end')"
if [ -n "$error" ]
then
echo " ${2-Failed with error}: $error"
exit 1
fi
}
target() {
echo Adding target...
resp="$(curl -sS --user $user:$password $url/rest/v1/targets -X POST \
-H 'Content-Type: application/json;charset=UTF-8' \
-d "[ { \"controllerId\" : \"$1\", \"name\" : \"$2\", \"securityToken\" : \"$3\", \"description\" : \"$4\"} ]")"
check_error "$resp"
echo "Done (target URL: $(echo "$resp" | jq -r '.[]._links.self.href'))"
}
distribution() {
echo Adding distribution...
name="$1"
desc="$2"
ver="$3"
type="$4"
shift 4
case "$type" in
os | os_app)
module_type=os
;;
app)
module_type=application
;;
*)
echo "<type> should be 'os', 'os_app' or 'app'"
exit 1
;;
esac
echo " Checking software module..."
resp="$(curl -sS --user $user:$password "$url/rest/v1/softwaremodules?q=name%3D%3DModule$name%3Bversion%3D%3D$ver")"
check_error "$resp" "Checking software module failed with error"
if [ "$(echo "$resp" | jq -r '.size')" = 0 ]
then
# Create software module
echo " Creating software module..."
resp="$(curl -sS --user $user:$password $url/rest/v1/softwaremodules -X POST \
-H 'Content-Type: application/json;charset=UTF-8' \
-d "[ {\"vendor\" : \"Apertis\", \"name\" : \"Module$name\", \"description\" : \"$desc\", \"type\" : \"$module_type\", \"version\" : \"$ver\" } ]")"
check_error "$resp" "Creating software module failed with error"
module_url="$(echo "$resp" | jq -r '.[]._links.self.href')"
module_id="$(echo "$resp" | jq -r '.[].id')"
else
module_url="$(echo "$resp" | jq -r '.content[0]._links.self.href')"
module_id="$(echo "$resp" | jq -r '.content[0].id')"
fi
# Add artifacts to software module
while [ $# -gt 0 ]
do
echo " Adding artifact: $1"
resp="$(curl -sS --user $user:$password $module_url/artifacts -X POST \
-H 'Content-Type: multipart/form-data' -F "file=@$1")"
error="$(echo "$resp" | jq -r '. | select(.errorCode) | .errorCode')"
if [ -n "$error" ]
then
echo " Upload artifact failed with error: $error"
exit 1
fi
shift
done
echo " Checking distribution..."
resp="$(curl -sS --user $user:$password "$url/rest/v1/distributionsets?q=name%3D%3D$name%3Bversion%3D%3D$ver")"
check_error "$resp" "Checking distribution failed with error"
if [ "$(echo "$resp" | jq -r '.size')" = 1 ]
then
os_module="$(echo "$resp" | jq -r '.content[0].modules[] | select(.type == "os") | .id')"
if [ "$module_id" = "$os_module" ]
then
echo " Distribution set already includes the software module."
echo "Done (target URL: $(echo "$resp" | jq -r '.content[0]._links.self.href'))"
return
fi
if [ -z "$os_module" ]
then
echo " Error: Distribution exists but doesn't reference the software module $module_id"
echo " Cannot proceed."
exit 0
fi
fi
# Create distribution
resp=$(curl -sS --user $user:$password $url/rest/v1/distributionsets/ -X POST \
-H 'Content-Type: application/json;charset=UTF-8' \
-d "[ {\"requiredMigrationStep\" : false, \"name\" : \"$name\", \"description\" : \"$desc\", \"type\" : \"$type\", \"version\" : \"$ver\", \"modules\" : [ {\"id\" : ${module_id}} ] } ]")
check_error "$resp"
echo "Done (target URL: $(echo "$resp" | jq -r '.[]._links.self.href'))"
}
url=http://localhost:8080
while getopts ":hu:" opt
do
case $opt in
u)
url=$OPTARG
;;
h)
usage
;;
\? )
echo Error: Unknown option: -$OPTARG >&2
echo >&2
usage
exit 1
;;
esac
done
shift $((OPTIND -1))
if [ $# -lt 2 ]
then
echo Error: Need the username and the password. >&2
echo >&2
usage
exit 1
fi
user=$1
password=$2
shift 2
case "$1" in
target)
shift
target "$@"
;;
distribution)
shift
distribution "$@"
;;
*)
usage
;;
esac
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment