Skip to content

Commit

Permalink
more die-fast error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
accetto committed Nov 19, 2023
1 parent bb9ad74 commit f432ece
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ die() {
local -i code=${2:-1}
local place="${3:-$0}"

echo -e "EXITING '${place}' with code ${code}: ${message}" >&2
echo -e "EXITING at line "${BASH_LINENO[0]}" in '${place}' with code ${code}: ${message}" >&2
exit ${code}
}

Expand Down
2 changes: 1 addition & 1 deletion ci-builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ die() {
local -i code=${2:-1}
local place="${3:-$0}"

echo -e "\nEXITING '${place}' with code ${code}: ${message}\n" >&2
echo -e "\nEXITING at line "${BASH_LINENO[0]}" in '${place}' with code ${code}: ${message}\n" >&2
exit ${code}
}

Expand Down
6 changes: 5 additions & 1 deletion docker/hooks/build
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ main() {
now="$(date --utc +%FT%TZ)"
echo "Current timestamp: ${now}" ; echo

### no quotes around ${params}!
set -x
### no quotes around 'params'
docker build ${params} \
-f "${DOCKERFILE_PATH}" \
--build-arg BASEIMAGE="${BASEIMAGE}" \
Expand Down Expand Up @@ -93,7 +93,11 @@ main() {
${FEATURES_FIREFOX_PLUS:+--build-arg ARG_MERGE_STAGE_BROWSER_BASE="stage_firefox_plus"} \
\
-t "${DOCKER_REPO}:${DOCKER_TAG}${target_stage:+_${target_stage}}" "${_build_context}"

exit_code=$?
set +x

if [[ ${exit_code} -ne 0 ]] ; then die "Failed to build image '${DOCKER_REPO}:${DOCKER_TAG}'" ${exit_code} ; fi
}

main $@
Expand Down
2 changes: 1 addition & 1 deletion docker/hooks/env.rc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ die() {
local -i code=${2:-1}
local place="${3:-$0}"

echo -e "EXITING '${place}' with code ${code}: ${message}" >&2
echo -e "EXITING at line "${BASH_LINENO[0]}" in '${place}' with code ${code}: ${message}" >&2
exit ${code}
}

Expand Down
7 changes: 6 additions & 1 deletion docker/hooks/pre_build
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ main() {
fi

### build a temporary helper image for getting the current version sticker values

### no quotes around ${params}!
set -x
### no quotes around 'params'
docker build ${params} \
-f "${DOCKERFILE_PATH}" \
--build-arg BASEIMAGE="${BASEIMAGE}" \
Expand All @@ -84,8 +85,12 @@ main() {
${FEATURES_FIREFOX_PLUS:+--build-arg ARG_MERGE_STAGE_BROWSER_BASE="stage_firefox_plus"} \
\
-t "${DOCKER_REPO}":"${DOCKER_TAG}${helper_suffix}" "${_build_context}"

exit_code=$?
set +x

if [[ ${exit_code} -ne 0 ]] ; then set +x; die "Failed to build image '${DOCKER_REPO}:${DOCKER_TAG}${helper_suffix}'" ${exit_code} ; fi

### get the actual verbose version sticker value from the helper image and store it as the current one
### note that some apps require display to report their versions correctly (e.g. Ristretto or Screenshooter)
# version_sticker="$( docker run --rm ${DOCKER_REPO}:${DOCKER_TAG}${helper_suffix} --skip-vnc --version-sticker-verbose )"
Expand Down
19 changes: 19 additions & 0 deletions docker/hooks/push
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ deployment_push() {
local target
local repo="${_deploy_repo##*/}"
local keeper_repo_tag="${_deploy_builder_tags[0]}"
local -i exit_code=0

if [[ -n "${repo}" && "${repo}" != "${_prohibited_repo_name}" ]] ; then

Expand All @@ -27,7 +28,13 @@ deployment_push() {
echo ; echo "Deploying image '${target}'"
docker tag "${DOCKER_REPO}:${keeper_repo_tag}" "${target}"
docker push "${target}"
exit_code=$?
docker rmi "${target}"

if [[ ${exit_code} -ne 0 ]] ; then
docker logout
die "Unable to push image '${target}'" ${exit_code}
fi
fi
done

Expand All @@ -40,6 +47,7 @@ main() {
local target
local repo="${DOCKER_REPO##*/}"
local keeper_repo_tag="${_deploy_builder_tags[0]}"
local -i exit_code=0

if [[ -f "${_build_context}/${_scrap_demand_stop_building}" ]] ; then
echo "Skipping push on demand."
Expand Down Expand Up @@ -78,13 +86,24 @@ main() {

# first element is the master repo (a keeper)
docker push "${DOCKER_REPO}:${t}"
exit_code=$?

if [[ ${exit_code} -ne 0 ]] ; then
docker logout
die "Unable to push image '${DOCKER_REPO}:${t}'" ${exit_code}
fi
else
target="${DOCKER_REPO}:${t}"

docker tag "${DOCKER_REPO}:${keeper_repo_tag}" "${target}"
docker push "${target}"
exit_code=$?
docker rmi "${target}"

if [[ ${exit_code} -ne 0 ]] ; then
docker logout
die "Unable to push image '${target}'" ${exit_code}
fi
fi
done

Expand Down

0 comments on commit f432ece

Please sign in to comment.