Skip to content

Commit

Permalink
build: build the right architecture locally (#1662)
Browse files Browse the repository at this point in the history
## Description:
We would build amd64 even on our arm64 M1/M2 machines; this fixes that
by building the local architecture by default for images and
engine/core/files artifact expander servers

## Is this change user facing?
NO
  • Loading branch information
h4ck3rk3y authored Oct 31, 2023
1 parent 77f2f69 commit aeb4128
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
10 changes: 9 additions & 1 deletion core/files_artifacts_expander/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set -euo pipefail # Bash "strict mode"
script_dirpath="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
expander_root_dirpath="$(dirname "${script_dirpath}")"
git_repo_dirpath="$(dirname "$(dirname "${expander_root_dirpath}")")"
uname_arch=$(uname -m)
# ==================================================================================================
# Constants
# ==================================================================================================
Expand All @@ -15,7 +16,14 @@ source "${script_dirpath}/_constants.env"
BUILD_DIRNAME="build"

DEFAULT_SKIP_DOCKER_IMAGE_BUILDING=false
DEFAULT_ARCHITECTURE_TO_BUILD=amd64

DEFAULT_ARCHITECTURE_TO_BUILD="unknown"

if [ "$uname_arch" == "x86_64" ] || [ "$uname_arch" == "amd64" ]; then
DEFAULT_ARCHITECTURE_TO_BUILD="amd64"
elif [ "$uname_arch" == "aarch64" ] || [ "$uname_arch" == "arm64" ]; then
DEFAULT_ARCHITECTURE_TO_BUILD="arm64"
fi

MAIN_GO_FILEPATH="${expander_root_dirpath}/main.go"
MAIN_BINARY_OUTPUT_FILENAME="files-artifacts-expander"
Expand Down
10 changes: 9 additions & 1 deletion core/server/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -euo pipefail # Bash "strict mode"
script_dirpath="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
server_root_dirpath="$(dirname "${script_dirpath}")"
git_repo_dirpath="$(dirname "$(dirname "${server_root_dirpath}")")"
uname_arch=$(uname -m)
# ==================================================================================================
# Constants
# ==================================================================================================
Expand All @@ -13,7 +14,14 @@ source "${script_dirpath}/_constants.env"
BUILD_DIRNAME="build"

DEFAULT_SKIP_DOCKER_IMAGE_BUILDING=false
DEFAULT_ARCHITECTURE_TO_BUILD=amd64

DEFAULT_ARCHITECTURE_TO_BUILD="unknown"

if [ "$uname_arch" == "x86_64" ] || [ "$uname_arch" == "amd64" ]; then
DEFAULT_ARCHITECTURE_TO_BUILD="amd64"
elif [ "$uname_arch" == "aarch64" ] || [ "$uname_arch" == "arm64" ]; then
DEFAULT_ARCHITECTURE_TO_BUILD="arm64"
fi

MAIN_DIRNAME="api_container"
MAIN_GO_FILEPATH="${server_root_dirpath}/${MAIN_DIRNAME}/main.go"
Expand Down
11 changes: 9 additions & 2 deletions engine/server/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail # Bash "strict mode"
script_dirpath="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
engine_root_dirpath="$(dirname "${script_dirpath}")"
git_repo_dirpath="$(dirname "$(dirname "${engine_root_dirpath}")")"

uname_arch=$(uname -m)
# ==================================================================================================
# Constants
# ==================================================================================================
Expand All @@ -14,7 +14,14 @@ source "${script_dirpath}/_constants.env"
BUILD_DIRNAME="build"

DEFAULT_SKIP_DOCKER_IMAGE_BUILDING=false
DEFAULT_ARCHITECTURE_TO_BUILD=amd64

DEFAULT_ARCHITECTURE_TO_BUILD="unknown"

if [ "$uname_arch" == "x86_64" ] || [ "$uname_arch" == "amd64" ]; then
DEFAULT_ARCHITECTURE_TO_BUILD="amd64"
elif [ "$uname_arch" == "aarch64" ] || [ "$uname_arch" == "arm64" ]; then
DEFAULT_ARCHITECTURE_TO_BUILD="arm64"
fi

MAIN_DIRNAME="engine"
MAIN_GO_FILEPATH="${engine_root_dirpath}/${MAIN_DIRNAME}/main.go"
Expand Down
12 changes: 11 additions & 1 deletion scripts/docker-image-builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,22 @@ if [ -z "${image_tags}" ]; then
show_helptext_and_exit
fi

uname_arch=$(uname -m)

architecture="amd64"

if [ "$uname_arch" == "x86_64" ] || [ "$uname_arch" == "amd64" ]; then
architecture="amd64"
elif [ "$uname_arch" == "aarch64" ] || [ "$uname_arch" == "arm64" ]; then
architecture="arm64"
fi

# Argument processing
if "${push_to_registry_container}"; then
buildx_platform_arg='linux/arm64/v8,linux/amd64'
push_flag='--push'
else
buildx_platform_arg='linux/amd64' # TODO: infer the local arch if that's reasonable
buildx_platform_arg="linux/${architecture}"
push_flag='--load'
fi
echo "Building docker image for architecture '${buildx_platform_arg}' with flag '${push_flag}'"
Expand Down

0 comments on commit aeb4128

Please sign in to comment.