Skip to content

Commit

Permalink
balena-build-block: Allow to specify the deploy dir
Browse files Browse the repository at this point in the history
This allows to use the script outside of the Jenkins context.

Change-type: patch
Signed-off-by: Alex Gonzalez <[email protected]>
  • Loading branch information
alexgg committed Jun 18, 2022
1 parent 45d04e8 commit 4094af3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions automation/entry_scripts/balena-build-block.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ source "${script_dir}/balena-lib.inc"
[ -z "${PACKAGES}" ] && echo "list of packages to install without dependencies" && exit 1
[ -z "${RELEASE_VERSION}" ] && echo "A release version needs to be defined" && exit 1
[ -z "${WORKSPACE}" ] && echo "Workspace needs to be defined" && exit 1
DEPLOY_DIR="${DEPLOY_DIR:-"${WORKSPACE}/deploy-jenkins"}"

[ -z "${PACKAGE_TYPE}" ] && PACKAGE_TYPE="ipk"

Expand Down Expand Up @@ -63,10 +64,10 @@ echo "LABEL ${BALENA_HOSTOS_BLOCK_REQUIRES_REBOOT}=1" >> "${TMPDIR}/Dockerfile"
echo "LABEL ${BALENA_HOSTOS_BLOCK_STORE}=data" >> "${TMPDIR}/Dockerfile"

# Copy local package feed to context if available from previous build step
if [ -d "${WORKSPACE}/deploy-jenkins/${PACKAGE_TYPE}" ]; then
if [ -d "${DEPLOY_DIR}/${PACKAGE_TYPE}" ]; then
ARCH_LIST=""
mkdir -p "${TMPDIR}/feed"
cp -r "${WORKSPACE}/deploy-jenkins/${PACKAGE_TYPE}" "${TMPDIR}/feed/"
cp -r "${DEPLOY_DIR}/${PACKAGE_TYPE}" "${TMPDIR}/feed/"
# Extract package architecture list from feed
# Each architecture is one directory
while IFS=$'\n' read -r dir; do
Expand All @@ -75,7 +76,7 @@ if [ -d "${WORKSPACE}/deploy-jenkins/${PACKAGE_TYPE}" ]; then
else
ARCH_LIST="${ARCH_LIST} ${dir}"
fi
done< <(find "${WORKSPACE}/deploy-jenkins/${PACKAGE_TYPE}" -mindepth 1 -maxdepth 1 -type d | xargs -I{} basename {})
done< <(find "${DEPLOY_DIR}/${PACKAGE_TYPE}" -mindepth 1 -maxdepth 1 -type d | xargs -I{} basename {})
else
proto=${FEED_URL%:*}
if [ -z "${FEED_URL}" ] || [ "${proto}" = "file" ]; then
Expand All @@ -91,8 +92,8 @@ docker rmi -f $(docker images --filter "label=${BALENA_HOSTOS_BLOCK_CLASS}" --fo

if balena build --logs --nocache --deviceType "${MACHINE}" --arch "${ARCH}" --buildArg PACKAGES="${PACKAGES}" --buildArg ARCH_LIST="${ARCH_LIST}" --buildArg NAMESPACE="${NAMESPACE:-resin}"; then
image_id=$(docker images --filter "label=${BALENA_HOSTOS_BLOCK_CLASS}" --format "{{.ID}}")
mkdir -p "${WORKSPACE}/deploy-jenkins"
docker save "${image_id}" > "${WORKSPACE}/deploy-jenkins/${APPNAME}-${RELEASE_VERSION}.docker"
mkdir -p "${DEPLOY_DIR}"
docker save "${image_id}" > "${DEPLOY_DIR}/${APPNAME}-${RELEASE_VERSION}.docker"
else
echo "[ERROR] Fail to build"
exit 1
Expand Down

0 comments on commit 4094af3

Please sign in to comment.