|
@@ -7,24 +7,67 @@
|
|
|
# SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
|
#
|
|
|
|
|
|
-# This script will utilize Docker to build on either AMD64 or AARCH64 architectures. The script will
|
|
|
-# also build on both Ubuntu 20.04 (focal) and Ubuntu 22.04 (jammy) systems because of the dependencies
|
|
|
-# on OpenSSL 1.1.1 and Open 3.0 respectively
|
|
|
+# This script will utilize Docker to build on either AMD64 or AARCH64 architectures.
|
|
|
|
|
|
-DOCKER_IMAGE_NAME_BASE=aws_gamelift_server_sdk
|
|
|
DOCKER_BUILD_SCRIPT=docker_build_linux.sh
|
|
|
+TARGET_BUILD_FOLDER=build
|
|
|
+
|
|
|
+#
|
|
|
+# Collect the required arguments for this ubuntu docker-base build script
|
|
|
+#
|
|
|
+
|
|
|
+# Get the base docker image name
|
|
|
+DOCKER_IMAGE_NAME_BASE=$1
|
|
|
+if [ "${DOCKER_IMAGE_NAME_BASE}" == "" ]
|
|
|
+then
|
|
|
+ echo "Missing argument 1: Docker image name for this process"
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
+
|
|
|
+# Get the ubuntu base version (20.04|22.04)
|
|
|
+UBUNTU_BASE=$2
|
|
|
+if [ "${UBUNTU_BASE}" == "" ]
|
|
|
+then
|
|
|
+ echo "Missing argument 2: Ubuntu docker tag"
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
|
|
|
# Determine the host architecture
|
|
|
CURRENT_HOST_ARCH=$(uname -m)
|
|
|
|
|
|
-# Get the path within the source tarball to the root of the source folder for the build
|
|
|
-SDK_SRC_SUBPATH=${1:-.}
|
|
|
-
|
|
|
# Use the host architecture if not supplied
|
|
|
-TARGET_ARCH=${2:-$(uname -m)}
|
|
|
+TARGET_ARCH=${3:-$(uname -m)}
|
|
|
+
|
|
|
+# Recompute the DOWNLOADED_PACKAGE_FOLDERS to apply to $WORKSPACE/temp inside the Docker script
|
|
|
+DEP_PACKAGES_FOLDERNAMES_ONLY=${DOWNLOADED_PACKAGE_FOLDERS//$TEMP_FOLDER\//}
|
|
|
+DEP_PACKAGES_DOCKER_FOLDERNAMES=${DOWNLOADED_PACKAGE_FOLDERS//$TEMP_FOLDER/"/data/workspace/temp"}
|
|
|
+
|
|
|
+echo "Executing docker-based build from the following arguments"
|
|
|
+echo " DOCKER_IMAGE_NAME_BASE = ${DOCKER_IMAGE_NAME_BASE}"
|
|
|
+echo " UBUNTU_BASE = ${UBUNTU_BASE}"
|
|
|
+echo " DOCKER_BUILD_SCRIPT = ${DOCKER_BUILD_SCRIPT}"
|
|
|
+echo " TARGET_BUILD_FOLDER = ${TARGET_BUILD_FOLDER}"
|
|
|
+echo " TARGET_ARCH = ${TARGET_ARCH}"
|
|
|
+echo " TEMP_FOLDER = ${TEMP_FOLDER}"
|
|
|
+echo " DOWNLOADED_PACKAGE_FOLDERS = ${DEP_PACKAGES_FOLDERNAMES_ONLY}"
|
|
|
|
|
|
-# Prepare the target install path
|
|
|
-INSTALL_PACKAGE_PATH=${TEMP_FOLDER}/install/
|
|
|
+
|
|
|
+
|
|
|
+#
|
|
|
+# Make sure docker is installed
|
|
|
+#
|
|
|
+DOCKER_VERSION=$(docker --version)
|
|
|
+if [ $? -ne 0 ]
|
|
|
+then
|
|
|
+ echo "Required package docker is not installed"
|
|
|
+ echo "Follow instructions on https://docs.docker.com/engine/install/ubuntu/ to install docker properly"
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
+echo "Detected Docker Version $DOCKER_VERSION"
|
|
|
+
|
|
|
+#
|
|
|
+# Check the target architecture and determine if the necessary cross compilation requirements are met
|
|
|
+#
|
|
|
|
|
|
# If the host and target architecture does not match, make sure the necessary cross compilation packages are installed
|
|
|
if [ "${CURRENT_HOST_ARCH}" != ${TARGET_ARCH} ]
|
|
@@ -66,16 +109,6 @@ else
|
|
|
echo "Building ${TARGET_ARCH} natively."
|
|
|
fi
|
|
|
|
|
|
-# Make sure docker is installed
|
|
|
-DOCKER_VERSION=$(docker --version)
|
|
|
-if [ $? -ne 0 ]
|
|
|
-then
|
|
|
- echo "Required package docker is not installed"
|
|
|
- echo "Follow instructions on https://docs.docker.com/engine/install/ubuntu/ to install docker properly"
|
|
|
- exit 1
|
|
|
-fi
|
|
|
-echo "Detected Docker Version $DOCKER_VERSION"
|
|
|
-
|
|
|
|
|
|
# Setup the docker arguments
|
|
|
if [ "${TARGET_ARCH}" = "x86_64" ]
|
|
@@ -84,7 +117,6 @@ then
|
|
|
|
|
|
DOCKER_INPUT_ARCHITECTURE=amd64
|
|
|
TARGET_DOCKER_PLATFORM_ARG=linux/amd64
|
|
|
- DOCKER_BUILD_ARG=1
|
|
|
|
|
|
elif [ "${TARGET_ARCH}" = "aarch64" ]
|
|
|
then
|
|
@@ -92,125 +124,101 @@ then
|
|
|
|
|
|
DOCKER_INPUT_ARCHITECTURE=arm64v8
|
|
|
TARGET_DOCKER_PLATFORM_ARG=linux/arm64/v8
|
|
|
- DOCKER_BUILD_ARG=3
|
|
|
+
|
|
|
else
|
|
|
echo "Unsupported architecture ${TARGET_ARCH}"
|
|
|
exit 1
|
|
|
fi
|
|
|
|
|
|
-# Prepare to build on both Ubuntu 20.04 and Ubuntu 22.04 based docker images
|
|
|
-
|
|
|
+#
|
|
|
+# Prepare the docker base context based on ${TEMP_FOLDER}
|
|
|
mkdir -p ${TEMP_FOLDER}
|
|
|
cp -f ${DOCKER_BUILD_SCRIPT} ${TEMP_FOLDER}/
|
|
|
|
|
|
-# Args
|
|
|
-# $1 : Ubuntu version
|
|
|
-# $2 : Include
|
|
|
-# $3 : Docker run platform
|
|
|
+echo "Building on ubuntu public.ecr.aws/ubuntu/ubuntu:${UBUNTU_BASE}"
|
|
|
|
|
|
-function execute_docker() {
|
|
|
+# Build the Docker Image
|
|
|
+DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME_BASE}_${DOCKER_INPUT_ARCHITECTURE}_3p
|
|
|
+echo DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME}
|
|
|
|
|
|
- # Determine the openssl version based on the ubuntu version (20.04/OpenSSL 1.1.1.x vs 22.04/OpenSSL 3.x)
|
|
|
- if [ $1 = "20.04" ]
|
|
|
- then
|
|
|
- echo "Preparing for OpenSSL 1.1.1.x version"
|
|
|
- BIN_SUBFOLDER_NAME=openssl-1
|
|
|
- elif [ $1 = "22.04" ]
|
|
|
- then
|
|
|
- echo "Preparing for OpenSSL 3.x version"
|
|
|
- BIN_SUBFOLDER_NAME=openssl-3
|
|
|
- else
|
|
|
- echo "Unsupported base build image ubuntu version ${1}"
|
|
|
- exit 1
|
|
|
- fi
|
|
|
+echo "Building the docker build script for ${DOCKER_IMAGE_NAME_BASE} on ${DOCKER_INPUT_ARCHITECTURE} for Ubuntu $1"
|
|
|
+echo ""
|
|
|
|
|
|
- # Build the Docker Image
|
|
|
- DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME_BASE}_focal_${DOCKER_INPUT_ARCHITECTURE}_3p
|
|
|
+CMD_DOCKER_BUILD="\
|
|
|
+docker build --build-arg INPUT_DOCKER_BUILD_SCRIPT=${DOCKER_BUILD_SCRIPT}\
|
|
|
+ --build-arg INPUT_ARCHITECTURE=${DOCKER_INPUT_ARCHITECTURE}\
|
|
|
+ --build-arg INPUT_IMAGE=ubuntu:${UBUNTU_BASE}\
|
|
|
+ --build-arg INPUT_DEPENDENT_PACKAGE_FOLDERS=${DEP_PACKAGES_DOCKER_FOLDERNAMES}\
|
|
|
+ -f Dockerfile -t ${DOCKER_IMAGE_NAME}:latest temp "
|
|
|
|
|
|
- echo "Building the docker build script for ${DOCKER_IMAGE_NAME_BASE} on ${DOCKER_INPUT_ARCHITECTURE} for Ubuntu $1"
|
|
|
- echo ""
|
|
|
- echo docker build --build-arg INPUT_DOCKER_BUILD_SCRIPT=${DOCKER_BUILD_SCRIPT} \
|
|
|
- --build-arg INPUT_ARCHITECTURE=${DOCKER_INPUT_ARCHITECTURE} \
|
|
|
- --build-arg INPUT_IMAGE=ubuntu:${1} \
|
|
|
- -f Dockerfile -t ${DOCKER_IMAGE_NAME}:latest temp
|
|
|
- docker build --build-arg INPUT_DOCKER_BUILD_SCRIPT=${DOCKER_BUILD_SCRIPT} \
|
|
|
- --build-arg INPUT_ARCHITECTURE=${DOCKER_INPUT_ARCHITECTURE} \
|
|
|
- --build-arg INPUT_IMAGE=ubuntu:${1} \
|
|
|
- -f Dockerfile -t ${DOCKER_IMAGE_NAME}:latest temp
|
|
|
- if [ $? -ne 0 ]
|
|
|
- then
|
|
|
- echo "Error occurred creating Docker image ${DOCKER_IMAGE_NAME}:latest."
|
|
|
- exit 1
|
|
|
- fi
|
|
|
+echo $CMD_DOCKER_BUILD
|
|
|
+eval $CMD_DOCKER_BUILD
|
|
|
+if [ $? -ne 0 ]
|
|
|
+then
|
|
|
+ echo "Error occurred creating Docker image ${DOCKER_IMAGE_NAME}:latest."
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
|
|
|
- # Run the build script in the docker image
|
|
|
- echo "Running build script in the docker image ${DOCKER_IMAGE_NAME}"
|
|
|
- echo ""
|
|
|
- echo docker run --platform ${TARGET_DOCKER_PLATFORM_ARG} \
|
|
|
- -it --tty \
|
|
|
- ${DOCKER_IMAGE_NAME}:latest /data/workspace/${DOCKER_BUILD_SCRIPT} ${SDK_SRC_SUBPATH}
|
|
|
- docker run --platform ${TARGET_DOCKER_PLATFORM_ARG} \
|
|
|
- --tty \
|
|
|
- ${DOCKER_IMAGE_NAME}:latest /data/workspace/${DOCKER_BUILD_SCRIPT} ${SDK_SRC_SUBPATH}
|
|
|
- if [ $? -ne 0 ]
|
|
|
- then
|
|
|
- echo Failed to build from docker image ${DOCKER_IMAGE_NAME}:latest
|
|
|
- echo "To log into and troubleshoot the docker container, run the following command:"
|
|
|
- echo ""
|
|
|
- echo "docker run --platform ${TARGET_DOCKER_PLATFORM_ARG} -it --tty ${DOCKER_IMAGE_NAME}:latest"
|
|
|
- echo ""
|
|
|
- exit 1
|
|
|
- fi
|
|
|
+# Prepare the target build folder to copy from the docker container on successful run of the docker script
|
|
|
+INSTALL_PACKAGE_PATH=${TEMP_FOLDER}/${TARGET_BUILD_FOLDER}/
|
|
|
|
|
|
- echo "Build Complete"
|
|
|
+# Run the build script in the docker image
|
|
|
+echo "Running build script in the docker image ${DOCKER_IMAGE_NAME}"
|
|
|
+echo ""
|
|
|
|
|
|
- # Copy the build artifacts from the docker image
|
|
|
+CMD_DOCKER_RUN="\
|
|
|
+docker run --platform ${TARGET_DOCKER_PLATFORM_ARG}\
|
|
|
+ --tty\
|
|
|
+ -v ${TEMP_FOLDER}:/data/workspace/temp:ro\
|
|
|
+ ${DOCKER_IMAGE_NAME}:latest /data/workspace/${DOCKER_BUILD_SCRIPT}"
|
|
|
|
|
|
- # Capture the Docker Image ID
|
|
|
- IMAGE_ID=$(docker images -q ${DOCKER_IMAGE_NAME}:latest)
|
|
|
- if [ -z $IMAGE_ID ]
|
|
|
- then
|
|
|
- echo "Error: Cannot find Image ID for ${DOCKER_IMAGE_NAME}"
|
|
|
- exit 1
|
|
|
- fi
|
|
|
+echo $CMD_DOCKER_RUN
|
|
|
+eval $CMD_DOCKER_RUN
|
|
|
+if [ $? -ne 0 ]
|
|
|
+then
|
|
|
+ echo Failed to build from docker image ${DOCKER_IMAGE_NAME}:latest
|
|
|
+ echo "To log into and troubleshoot the docker container, run the following command:"
|
|
|
+ echo ""
|
|
|
+ echo "docker run --platform ${TARGET_DOCKER_PLATFORM_ARG} -it --tty -v ${TEMP_FOLDER}:/data/workspace/temp:ro ${DOCKER_IMAGE_NAME}:latest"
|
|
|
+ echo ""
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
|
|
|
- # Capture the container ID
|
|
|
- echo "Capturing the Container ID"
|
|
|
- CONTAINER_ID=$(docker container ls -l -q --filter "ancestor=${DOCKER_IMAGE_NAME}:latest")
|
|
|
- if [ -z $CONTAINER_ID ]
|
|
|
- then
|
|
|
- echo "Error: Cannot find Container ID for Image ${DOCKER_IMAGE_NAME}"
|
|
|
- exit 1
|
|
|
- fi
|
|
|
+echo "Build Complete"
|
|
|
|
|
|
- DOCKER_BUILD_ROOT=/data/workspace/build/
|
|
|
+# Copy the build artifacts from the docker image
|
|
|
|
|
|
- if [ ! -f ${INSTALL_PACKAGE_PATH}/include ]
|
|
|
- then
|
|
|
- docker cp $CONTAINER_ID:${DOCKER_BUILD_ROOT}/build_static/prefix/include ${INSTALL_PACKAGE_PATH}/
|
|
|
- fi
|
|
|
- if [ ! -f ${INSTALL_PACKAGE_PATH}/cmake ]
|
|
|
- then
|
|
|
- docker cp $CONTAINER_ID:${DOCKER_BUILD_ROOT}/build_static/prefix/cmake ${INSTALL_PACKAGE_PATH}/
|
|
|
- fi
|
|
|
+# Capture the Docker Image ID
|
|
|
+IMAGE_ID=$(docker images -q ${DOCKER_IMAGE_NAME}:latest)
|
|
|
+if [ -z $IMAGE_ID ]
|
|
|
+then
|
|
|
+ echo "Error: Cannot find Image ID for ${DOCKER_IMAGE_NAME}"
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
|
|
|
- docker cp $CONTAINER_ID:${DOCKER_BUILD_ROOT}/build_static/prefix/lib ${INSTALL_PACKAGE_PATH}/lib/${BIN_SUBFOLDER_NAME}
|
|
|
- docker cp $CONTAINER_ID:${DOCKER_BUILD_ROOT}/build_shared/prefix/lib ${INSTALL_PACKAGE_PATH}/bin/${BIN_SUBFOLDER_NAME}
|
|
|
-}
|
|
|
+# Capture the container ID
|
|
|
+echo "Capturing the Container ID"
|
|
|
+CONTAINER_ID=$(docker container ls -l -q --filter "ancestor=${DOCKER_IMAGE_NAME}:latest")
|
|
|
+if [ -z $CONTAINER_ID ]
|
|
|
+then
|
|
|
+ echo "Error: Cannot find Container ID for Image ${DOCKER_IMAGE_NAME}"
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
|
|
|
-rm -rf ${INSTALL_PACKAGE_PATH}
|
|
|
+DOCKER_BUILD_ROOT=/data/workspace/${TARGET_BUILD_FOLDER}
|
|
|
|
|
|
-mkdir -p ${INSTALL_PACKAGE_PATH}
|
|
|
-mkdir -p ${INSTALL_PACKAGE_PATH}/lib
|
|
|
-mkdir -p ${INSTALL_PACKAGE_PATH}/bin
|
|
|
|
|
|
-# Build for Ubuntu 20.04
|
|
|
-execute_docker 20.04
|
|
|
+rm -rf ${INSTALL_PACKAGE_PATH}
|
|
|
+mkdir -p ${INSTALL_PACKAGE_PATH}
|
|
|
|
|
|
-# Build for Ubuntu 22.04
|
|
|
-execute_docker 22.04
|
|
|
+echo "Copying from $CONTAINER_ID:${DOCKER_BUILD_ROOT} to ${TEMP_FOLDER}/"
|
|
|
+docker cp $CONTAINER_ID:${DOCKER_BUILD_ROOT} ${TEMP_FOLDER}/
|
|
|
+if [ $? -ne 0 ]
|
|
|
+then
|
|
|
+ echo "Error copying build from docker image ${DOCKER_IMAGE_NAME}:latest."
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
|
|
|
-echo "Build successful"
|
|
|
+echo "Built ${DOCKER_IMAGE_NAME_BASE} into ${INSTALL_PACKAGE_PATH} successfully"
|
|
|
|
|
|
exit 0
|
|
|
-
|