diff --git a/buildDBImage.sh b/buildDBImage.sh index b46bb49..c41112e 100755 --- a/buildDBImage.sh +++ b/buildDBImage.sh @@ -154,9 +154,9 @@ processManifest() { if [ -f ./config/manifest ] then # Get the correct architecture. - case "$(uname -m)" in - arm64|aarch64) arch="arm64" ;; # Match arm64 or aarch64 for ARM64 files - *) arch="x86|x64|amd64" ;; # Regexp match for x86 and x64 because non-ARM files are identified by both x86 and x64 :( + case "$BUILD_PLATFORM" in + linux/arm64) arch="arm64" ;; # Match arm64 or aarch64 for ARM64 files + linux/amd64) arch="x86|x64|amd64" ;; # Regexp match for x86 and x64 because non-ARM files are identified by both x86 and x64 :( esac grep -i -E "$arch" ./config/manifest | grep -ve "^#" | awk '{print $1,$2,$3,$4,$5}' | while IFS=" " read -r checksum filename filetype version extra do @@ -247,6 +247,9 @@ usage () { echo " -n, --image-name string Repository name for the completed image (Default: oracle/db) " echo " --no-cache Do not use cache when building the image " echo " --no-sum Do not perform file checksums " + echo " --platform string Target build platform. (Default: Host machine platform) " + echo " linux/arm64 " + echo " linux/amd64 " echo " --progress string Display build progress " echo " auto (Default) " echo " plain: Show container output " @@ -275,8 +278,8 @@ usage () { then # The system must be using GNU-getopt to process command line parameters. This is not the default on MacOS. error "An incompatible version of getopt is installed. Cannot process parameters." elif [ -n "$*" ] # Only process command line parameters if options were passed. -then OPTS=de:hkn:qrS:T:t:v: - OPTL=build-arg:,debug,dockerfile-keep,edition:,force-patch:,force-rebuild,force-rm,help,image-name:,no-cache,no-sum,progress:,prune-cache,quiet,read-only-home,remove-components:,rpm:,secret:,source-image:,source-tag:,tag:,version: +then OPTS=de:hkn:p:qrS:T:t:v: + OPTL=build-arg:,debug,dockerfile-keep,edition:,force-patch:,force-rebuild,force-rm,help,image-name:,no-cache,no-sum,platform:,progress:,prune-cache,quiet,read-only-home,remove-components:,rpm:,secret:,source-image:,source-tag:,tag:,version: ARGS=$(getopt -a -o $OPTS -l $OPTL -- "$@") || usage 1 eval set -- "$ARGS" while : @@ -299,6 +302,11 @@ then OPTS=de:hkn:qrS:T:t:v: -n | --image-name ) TARGET="$2"; shift 2 ;; --no-cache ) BUILD_OPTIONS=("${BUILD_OPTIONS[@]}" --no-cache=true); shift ;; --no-sum ) DB_BUILD_OPTIONS=("${DB_BUILD_OPTIONS[@]}" --build-arg SKIP_MD5SUM=1); shift ;; + -p | --platform ) case "${2,,}" in + "linux/arm64" | "linux/amd64" ) BUILD_PLATFORM="$2" ;; + * ) error "--platform must be one of linux/arm64 or linux/amd64" ;; + esac + shift 2 ;; --progress ) case "${2,,}" in auto | plain | tty ) BUILD_OPTIONS=("${BUILD_OPTIONS[@]}" --progress "$2") ;; * ) error "--progress must be one of auto, plain, or tty" ;; @@ -326,13 +334,24 @@ then OPTS=de:hkn:qrS:T:t:v: done fi -# Set defaults for version, edition, tag and source: +# determine host platform, this will be used as a default if "--platform" is not specified +case "$(uname -m)" in + arm64|aarch64) DEFAULT_PLATFORM="linux/arm64" ;; + *) DEFAULT_PLATFORM="linux/amd64" ;; +esac + +# Set defaults for version, edition, tag, source, and platform: ORACLE_VERSION=${ORACLE_VERSION:-19.19} ORACLE_EDITION=${ORACLE_EDITION:-EE} SOURCE=${SOURCE:-oraclelinux} S_TAG=${S_TAG:-8-slim} TARGET=${TARGET:-oracle/db} T_TAG=${T_TAG:-${ORACLE_VERSION}-${ORACLE_EDITION}} +BUILD_PLATFORM=${BUILD_PLATFORM:-${DEFAULT_PLATFORM}} + +if [[ ! -z "${BUILD_PLATFORM}" ]]; then + BUILD_OPTIONS=("${BUILD_OPTIONS[@]}" --platform ${BUILD_PLATFORM}) +fi getVersion getEdition