mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 10:41:32 +00:00
145 lines
4.0 KiB
Bash
Executable File
145 lines
4.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
#
|
|
# Copyright (C) Wendepunkt Medical Innovations, Inc - All Rights Reserved.
|
|
# Unauthorized copying of this file, via any medium is strictly prohibited.
|
|
# Proprietary and confidential
|
|
#
|
|
# For information: dev@signalytic.ca
|
|
#
|
|
|
|
# basic path info
|
|
LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|
PROJECT_ROOT="$(realpath $LOCATION)"
|
|
|
|
# determine version name from git
|
|
# use ci tag name if available (e.g. "v1.2")
|
|
if [ $CI_COMMIT_TAG ]; then
|
|
VERSION_NAME="$CI_COMMIT_TAG"
|
|
# otherwise if ci, use BRANCH-COMMIT
|
|
elif [ $CI_COMMIT_BRANCH ]; then
|
|
VERSION_NAME="$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA"
|
|
# if not ci, try to use git
|
|
elif command -v git &> /dev/null; then
|
|
VERSION_NAME=$(git describe --always --tags --dirty)
|
|
# fallback
|
|
else
|
|
VERSION_NAME="latest"
|
|
fi
|
|
|
|
# configurable options (override with env vars as needed)
|
|
PACKAGE_NAME=${PACKAGE_NAME-"streamline-emr"}
|
|
OUTPUT_DIR=${OUTPUT_DIR-"$PROJECT_ROOT/build-packages"}
|
|
PACKAGE_IMAGES=${PACKAGE_IMAGES:-1}
|
|
IMAGE_TAG=${IMAGE_TAG:-${VERSION_NAME}}
|
|
IMAGES_LIST=${IMAGES_LIST:-${PROJECT_ROOT}/images.csv}
|
|
|
|
echo "packaging $PACKAGE_NAME"
|
|
echo " output dir: $OUTPUT_DIR"
|
|
echo " package images: $PACKAGE_IMAGES"
|
|
echo " image tag: $IMAGE_TAG"
|
|
|
|
# work from the project root
|
|
pushd $PROJECT_ROOT > /dev/null
|
|
|
|
# Exit on error:
|
|
set -e
|
|
trap 'echo "Error: Last command failed with exit code $?."' ERR
|
|
|
|
# generate version name
|
|
# use ci tag name if available (e.g. "v1.2")
|
|
if [ $CI_COMMIT_TAG ]; then
|
|
VERSION_NAME="$CI_COMMIT_TAG"
|
|
|
|
# otherwise if ci, use BRANCH-COMMIT
|
|
# Note: commit count is harder to get to from CI - can't reproduce the git
|
|
# describe functionality as easily
|
|
elif [ $CI_COMMIT_BRANCH ]; then
|
|
VERSION_NAME="$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA"
|
|
|
|
# if not ci, try to use git
|
|
elif command -v git &> /dev/null; then
|
|
VERSION_NAME=$(git describe --always --tags --dirty)
|
|
|
|
# fallback
|
|
else
|
|
VERSION_NAME="unknown"
|
|
fi
|
|
|
|
# build for each relevant platform
|
|
for platform in "linux/amd64" "linux/arm64"; do
|
|
echo "preparing package for platform $platform"
|
|
if [ "$platform" == "linux/amd64" ];then
|
|
pkg_arch="x86_64"
|
|
elif [ "$platform" == "linux/arm64" ];then
|
|
pkg_arch="aarch64"
|
|
else
|
|
echo "unexpected platform '$platform'"
|
|
exit 1
|
|
fi
|
|
OUTPUT_NAME="$PACKAGE_NAME-$VERSION_NAME-${pkg_arch}"
|
|
OUTPUT_FILE="$OUTPUT_NAME.tar.bz2"
|
|
OUTPUT_PATH="$OUTPUT_DIR/$OUTPUT_FILE"
|
|
|
|
# create a new temp directory to stage files
|
|
for i in {1..9999};do
|
|
STAGING_DIR="tmp-staging-$i"
|
|
if [ ! -d $STAGING_DIR ]; then
|
|
break
|
|
fi
|
|
done
|
|
if [ -d $STAGING_DIR ]; then
|
|
echo "Failed to generate temp staging dir"
|
|
exit 1
|
|
fi
|
|
|
|
# add files
|
|
PACKAGE_ROOT=${STAGING_DIR}/${OUTPUT_NAME}
|
|
IMAGES_DIR=${PACKAGE_ROOT}/images
|
|
mkdir -p ${IMAGES_DIR}
|
|
cp ${PROJECT_ROOT}/install.sh ${PACKAGE_ROOT}/
|
|
cp -a ${PROJECT_ROOT}/root ${PACKAGE_ROOT}/
|
|
echo "${VERSION_NAME}" > ${PACKAGE_ROOT}/root/var/signalytic/clientapps/streamline/streamline-emr/version
|
|
|
|
if [ "${PACKAGE_IMAGES}" = "1" ]; then
|
|
# add images
|
|
i=0
|
|
# read image list from file (e.g. 'images-aarch64')
|
|
# images are listed as SAVED_TAG=SOURCE_IMAGE
|
|
for image in $(cat ${IMAGES_LIST});do
|
|
IFS=, read -r img_platform dest source <<< "${image}"
|
|
# package only if the platforms match
|
|
if [ "${img_platform}" = "${platform}" ]; then
|
|
echo "pulling image '${source}' (${platform})"
|
|
docker pull --platform ${platform} ${source}:${IMAGE_TAG}
|
|
echo "tagging image as '${dest}:latest'"
|
|
docker tag ${source}:${IMAGE_TAG} ${dest}:latest
|
|
i=$((i+1))
|
|
name="image${i}.img"
|
|
path="${IMAGES_DIR}/${name}"
|
|
echo "saving to '${path}'"
|
|
docker save -o ${path} ${dest}:latest
|
|
fi
|
|
done
|
|
else
|
|
echo "skipping image packaging as requested"
|
|
fi
|
|
|
|
# setup output directory and cleanup old files if necessary
|
|
mkdir -p $OUTPUT_DIR
|
|
rm -rf $OUTPUT_PATH
|
|
|
|
pushd $STAGING_DIR > /dev/null
|
|
tar -cjf $OUTPUT_PATH ${OUTPUT_NAME}
|
|
popd > /dev/null
|
|
|
|
# cleanup staging files
|
|
rm -r $STAGING_DIR
|
|
|
|
echo "output: $OUTPUT_PATH"
|
|
done
|
|
|
|
popd > /dev/null
|
|
|
|
exit 0
|