Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: files artifacts expander image debug tag #2119

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions core/files_artifacts_expander/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading