diff --git a/core/files_artifacts_expander/scripts/build.sh b/core/files_artifacts_expander/scripts/build.sh index 7f18864805..fcbb3fc019 100755 --- a/core/files_artifacts_expander/scripts/build.sh +++ b/core/files_artifacts_expander/scripts/build.sh @@ -19,6 +19,10 @@ DEFAULT_SKIP_DOCKER_IMAGE_BUILDING=false DEFAULT_ARCHITECTURE_TO_BUILD="unknown" +DOCKER_DEBUG_IMAGE_NAME_SUFFIX="debug" +DEFAULT_DEBUG_IMAGE=false + + if [ "$uname_arch" == "x86_64" ] || [ "$uname_arch" == "amd64" ]; then DEFAULT_ARCHITECTURE_TO_BUILD="amd64" elif [ "$uname_arch" == "aarch64" ] || [ "$uname_arch" == "arm64" ]; then @@ -29,9 +33,19 @@ MAIN_GO_FILEPATH="${expander_root_dirpath}/main.go" MAIN_BINARY_OUTPUT_FILENAME="files-artifacts-expander" MAIN_BINARY_OUTPUT_FILEPATH="${expander_root_dirpath}/${BUILD_DIRNAME}/${MAIN_BINARY_OUTPUT_FILENAME}" -# ============================================================================= -# Main Code -# ============================================================================= +# ================================================================================================== +# Arg Parsing & Validation +# ================================================================================================== +show_helptext_and_exit() { + echo "Usage: $(basename "${0}") skip_docker_image_building, architecture_to_build, debug_image..." + echo "" + echo " skip_docker_image_building Whether build the Docker image" + echo " architecture_to_build The desired architecture for the project's binaries" + echo " debug_image Whether images should contains the debug server and run in debug mode, this will use the Dockerfile.debug image to build the container" + echo "" + exit 1 # Exit with an error so that if this is accidentally called by CI, the script will fail +} + skip_docker_image_building="${1:-"${DEFAULT_SKIP_DOCKER_IMAGE_BUILDING}"}" if [ "${skip_docker_image_building}" != "true" ] && [ "${skip_docker_image_building}" != "false" ]; then echo "Error: Invalid skip-docker-image-building arg '${skip_docker_image_building}'" >&2 @@ -42,6 +56,15 @@ if [ "${architecture_to_build}" != "amd64" ] && [ "${architecture_to_build}" != echo "Error: Invalid architecture-to-build arg '${architecture_to_build}'" >&2 fi +debug_image="${3:-"${DEFAULT_DEBUG_IMAGE}"}" +if [ "${debug_image}" != "true" ] && [ "${debug_image}" != "false" ]; then + echo "Error: Invalid debug_image arg: '${debug_image}'" >&2 + show_helptext_and_exit +fi + +# ============================================================================= +# Main Code +# ============================================================================= # Checks if dockerignore file is in the root path if ! [ -f "${expander_root_dirpath}"/.dockerignore ]; then echo "Error: No .dockerignore file found in files artifacts expander root '${expander_root_dirpath}'; this is required so Docker caching is enabled and the image builds remain quick" >&2 @@ -86,6 +109,11 @@ fi dockerfile_filepath="${expander_root_dirpath}/Dockerfile" image_name="${IMAGE_ORG_AND_REPO}:${docker_tag}" +# specifying that this is a image for debugging +if "${debug_image}"; then + image_name="${image_name}-${DOCKER_DEBUG_IMAGE_NAME_SUFFIX}" +fi + load_not_push_image=false docker_build_script_cmd="${git_repo_dirpath}/scripts/docker-image-builder.sh ${load_not_push_image} ${dockerfile_filepath} ${image_name}" if ! eval "${docker_build_script_cmd}"; then