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 18, 2023
1 parent 10fbd28 commit d1d7394
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 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
25 changes: 21 additions & 4 deletions docker/hooks/build
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ main() {

nodejs | nodejs-* | nodejs-current | nodejs-current-* )

### no quotes around 'params'
### no quotes around ${params}!
set -x
docker build ${params} \
-f "${DOCKERFILE_PATH}" \
--build-arg BASEIMAGE="${BASEIMAGE}" \
Expand Down Expand Up @@ -104,7 +105,11 @@ main() {
${FEATURES_VSCODE:+--build-arg ARG_FINAL_STAGE_BASE="stage_vscode"} \
\
-t "${DOCKER_REPO}":"${DOCKER_TAG}" "${_build_context}"

exit_code=$?
set +x

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

### --------------------------
Expand All @@ -113,8 +118,8 @@ main() {

postman | postman-* )

### no quotes around ${params}!
set -x
### no quotes around 'params'
docker build ${params} \
-f "${DOCKERFILE_PATH}" \
--build-arg BASEIMAGE="${BASEIMAGE}" \
Expand Down Expand Up @@ -146,7 +151,11 @@ main() {
${FEATURES_POSTMAN:+--build-arg ARG_FINAL_STAGE_BASE="stage_postman"} \
\
-t "${DOCKER_REPO}":"${DOCKER_TAG}" "${_build_context}"

exit_code=$?
set +x

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

### -------------------------
Expand All @@ -155,8 +164,8 @@ main() {

python | python-* )

### no quotes around ${params}!
set -x
### no quotes around 'params'
docker build ${params} \
-f "${DOCKERFILE_PATH}" \
--build-arg BASEIMAGE="${BASEIMAGE}" \
Expand Down Expand Up @@ -188,7 +197,11 @@ main() {
${FEATURES_VSCODE:+--build-arg ARG_FINAL_STAGE_BASE="stage_vscode"} \
\
-t "${DOCKER_REPO}":"${DOCKER_TAG}" "${_build_context}"

exit_code=$?
set +x

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

### -------------------------
Expand All @@ -197,8 +210,8 @@ main() {

vscode | vscode-* )

### no quotes around ${params}!
set -x
### no quotes around 'params'
docker build ${params} \
-f "${DOCKERFILE_PATH}" \
--build-arg BASEIMAGE="${BASEIMAGE}" \
Expand Down Expand Up @@ -228,7 +241,11 @@ main() {
${FEATURES_VSCODE:+--build-arg ARG_FINAL_STAGE_BASE="stage_vscode"} \
\
-t "${DOCKER_REPO}":"${DOCKER_TAG}" "${_build_context}"

exit_code=$?
set +x

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

* )
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
24 changes: 20 additions & 4 deletions docker/hooks/pre_build
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ main() {

nodejs | nodejs-* | nodejs-current | nodejs-current-* )

### no quotes around ${params}!
set -x
### no quotes around 'params'
docker build ${params} \
-f "${DOCKERFILE_PATH}" \
--build-arg BASEIMAGE="${BASEIMAGE}" \
Expand Down Expand Up @@ -97,7 +97,11 @@ main() {
${FEATURES_VSCODE:+--build-arg ARG_FINAL_STAGE_BASE="stage_vscode"} \
\
-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
;;

### --------------------------
Expand All @@ -106,8 +110,8 @@ main() {

postman | postman-* )

### no quotes around ${params}!
set -x
### no quotes around 'params'
docker build ${params} \
-f "${DOCKERFILE_PATH}" \
--build-arg BASEIMAGE="${BASEIMAGE}" \
Expand Down Expand Up @@ -135,7 +139,11 @@ main() {
${FEATURES_POSTMAN:+--build-arg ARG_FINAL_STAGE_BASE="stage_postman"} \
\
-t "${DOCKER_REPO}":"${DOCKER_TAG}${helper_suffix}" "${_build_context}"

exit_code=$?
set +x

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

### -------------------------
Expand All @@ -144,8 +152,8 @@ main() {

python | python-* )

### no quotes around ${params}!
set -x
### no quotes around 'params'
docker build ${params} \
-f "${DOCKERFILE_PATH}" \
--build-arg BASEIMAGE="${BASEIMAGE}" \
Expand Down Expand Up @@ -173,7 +181,11 @@ main() {
${FEATURES_VSCODE:+--build-arg ARG_FINAL_STAGE_BASE="stage_vscode"} \
\
-t "${DOCKER_REPO}":"${DOCKER_TAG}${helper_suffix}" "${_build_context}"

exit_code=$?
set +x

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

### -------------------------
Expand All @@ -182,8 +194,8 @@ main() {

vscode | vscode-* )

### no quotes around ${params}!
set -x
### no quotes around 'params'
docker build ${params} \
-f "${DOCKERFILE_PATH}" \
--build-arg BASEIMAGE="${BASEIMAGE}" \
Expand All @@ -209,7 +221,11 @@ main() {
${FEATURES_VSCODE:+--build-arg ARG_FINAL_STAGE_BASE="stage_vscode"} \
\
-t "${DOCKER_REPO}":"${DOCKER_TAG}${helper_suffix}" "${_build_context}"

exit_code=$?
set +x

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

* )
Expand Down
20 changes: 20 additions & 0 deletions docker/hooks/push
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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 @@ -26,9 +27,16 @@ deployment_push() {
target="${_deploy_repo}:${t}"

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 @@ -41,6 +49,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 @@ -79,13 +88,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 d1d7394

Please sign in to comment.