Lachee 6d910d6f2f Revert "Specified base image in building"
This reverts commit 4a719b91eb40d2a51d6c768bfb401d28f05ec8ba.
2025-05-18 14:54:14 +10:00

102 lines
2.5 KiB
Bash
Executable File

#!/bin/sh
# Ensure UNITY_VERSION is set, pull from arguments if not
if [ -z "${UNITY_VERSION}" ]; then
if [ -n "$1" ]; then
UNITY_VERSION=$1
else
echo "Error: UNITY_VERSION is not set."
exit 1
fi
fi
# Ensure UNITY_PLATFORM is set, pull from arguments if not
if [ -z "${UNITY_PLATFORM}" ]; then
if [ -n "$2" ]; then
UNITY_PLATFORM=$2
else
echo "Error: UNITY_PLATFORM is not set."
exit 1
fi
fi
# Ensure IMAGE is set, pull from arguments if not
if [ -z "${IMAGE}" ]; then
if [ -n "$3" ]; then
IMAGE=$3
else
echo "Error: IMAGE is not set."
exit 1
fi
fi
# Ensure GAME_CI_VERSION is set, default to 3 if not
if [ -z "${GAMECI_VERSION}" ]; then
GAMECI_VERSION=3
fi
# Ensure IMAGE_OS is set, default to ubuntu if not
if [ -z "${GAMECI_OS}" ]; then
# windows-il2cpp requires windows OS
if [ "${UNITY_PLATFORM}" = "windows-il2cpp" ]; then
GAMECI_OS="windows"
else
GAMECI_OS="ubuntu"
fi
# TODO: MacOS probably requires a mac image.
# Might be worth just putting this in the strategy at this point
fi
# Ensure PLATFORM is set, default to the current system if not
if [ -z "${PLATFORM}" ]; then
PLATFORM=$(uname -m)
case "${PLATFORM}" in
x86_64) PLATFORM="linux/amd64" ;;
arm64) PLATFORM="linux/arm64" ;;
*)
echo "Error: Unsupported platform ${PLATFORM}."
exit 1
;;
esac
fi
BASE_IMAGE=unityci/editor:${GAMECI_OS}-${UNITY_VERSION}-${UNITY_PLATFORM}-${GAMECI_VERSION}
SHORT_TAG=${GAMECI_OS}-${UNITY_VERSION}-${UNITY_PLATFORM}
TAG=${SHORT_TAG}-runner
FULL_IMAGE=${IMAGE}:${TAG}
ADDITIONAL_TAGS=""
if [ "${ONLY_RUNNER_TAG}" != "true" ]; then
ADDITIONAL_TAGS="$ADDITIONAL_TAGS -t ${IMAGE}:${SHORT_TAG}"
ADDITIONAL_TAGS="$ADDITIONAL_TAGS -t ${IMAGE}:${SHORT_TAG}-${GAMECI_VERSION}"
fi
echo "Building Docker image ${FULL_IMAGE}"
echo "- Platfrom: ${PLATFORM}"
echo "- Base: ${BASE_IMAGE}"
echo "- Tag: ${TAG}"
echo "- Image: ${IMAGE}:${TAG}"
echo "- Additional Tags: ${ADDITIONAL_TAGS}"
docker build \
--platform ${PLATFORM} \
--build-arg BASE_IMAGE=${BASE_IMAGE} \
${ADDITIONAL_TAGS} \
-t ${FULL_IMAGE} \
${DOCKER_BUILD_ARGS} \
.
if [ $? -ne 0 ]; then
echo "Error: Docker build failed."
exit 1
fi
# Export IMAGE and TAG for GitHub Actions
if [ -n "$GITHUB_OUTPUT" ]; then
echo "IMAGE=${IMAGE}" >> $GITHUB_OUTPUT
echo "TAG=${TAG}" >> $GITHUB_OUTPUT
echo "FULL_IMAGE=${FULL_IMAGE}" >> $GITHUB_OUTPUT
fi