orenccl commented on code in PR #103:
URL:
https://github.com/apache/gravitino-playground/pull/103#discussion_r1835717045
##########
playground.sh:
##########
@@ -18,44 +18,107 @@
# under the License.
#
-set -x
-
playground_dir="$(dirname "${BASH_SOURCE-$0}")"
playground_dir="$(
- cd "${playground_dir}" >/dev/null
+ cd "${playground_dir}" >/dev/null || exit 1
pwd
)"
+playgroundRuntimeName="gravitino-playground"
+runtime=""
+
+requiredDiskSpaceGB=25
+requiredRamGB=8
+requiredCpuCores=2
+requiredPorts=(8090 9001 3307 19000 19083 60070 13306 15342 18080 18888 19090
13000)
+
testDocker() {
- echo "INFO: Testing Docker environment by running hello-world..."
- docker run --pull always hello-world >/dev/null 2>&1
+ echo "[INFO] Testing Docker environment by running hello-world..."
+ # Use always to test network connection
+ docker run --rm --pull always hello-world:linux >/dev/null 2>&1
+
if [ $? -eq 0 ]; then
- echo "INFO: Docker is working correctly!"
+ echo "[INFO] Docker check passed: Docker is working correctly!"
else
- echo "ERROR: There was an issue running the hello-world container. Please
check your Docker installation."
+ echo "[ERROR] Docker check failed: There was an issue running the
hello-world container. Please check your Docker installation."
exit 1
fi
}
-testK8s() {
- echo "Testing K8s environment ..."
- kubectl cluster-info
- if [ $? -eq 0 ]; then
- echo "INFO: K8s is working correctly!"
+checkDockerCompose() {
+ isExist=$(which docker compose)
+
+ if [ ${isExist} ]; then
+ echo "[INFO] Docker compose check passed: Docker compose is working
correctly!"
else
- echo "ERROR: There was an issue running kubectl cluster-info, please check
you K8s cluster."
+ echo "[ERROR] Docker compose check failed: No docker service environment
found. Please install docker compose."
exit 1
fi
}
+checkDockerDisk() {
+ # Step 1: Get Docker Root Directory
+ local dockerRootDir="$(docker info 2>/dev/null | grep "Docker Root Dir" |
awk '{print $NF}')"
-checkCompose() {
- isExist=$(which docker-compose)
- if [ $isExist ]; then
- true # Placeholder, do nothing
+ # Step 2: Check if the Docker directory exists
+ if [ -z "${dockerRootDir}" ]; then
+ echo "[ERROR] Docker disk check failed: Docker is not running or Docker
Root Directory not found."
+ exit 1
+ fi
+
+ local availableSpaceKB
+
+ if [ -d "${dockerRootDir}" ]; then
+ # Check available space in the Docker directory's partition
+ availableSpaceKB=$(df --output=avail "${dockerRootDir}" | awk 'NR==2
{print $1}')
else
- echo "ERROR: No docker service environment found. Please install
docker-compose."
- exit
+ # Check available space in the root partition if the directory doesn't
exist (special case for WSL)
+ availableSpaceKB=$(df --output=avail / | awk 'NR==2 {print $1}')
+ fi
+
+ # Step 3: Check if available space is greater than required
+ local availableSpaceGB=$((${availableSpaceKB} / 1024 / 1024))
+
+ if [ "${availableSpaceGB}" -ge "${requiredDiskSpaceGB}" ]; then
+ echo "[INFO] Docker disk check passed: ${availableSpaceGB} GB available."
+ else
+ echo "[ERROR] Docker disk check failed: ${availableSpaceGB} GB available,
${requiredDiskSpaceGB} GB or more required."
+ exit 1
+ fi
+}
+
+checkDockerRam() {
+ local totalRamBytes=$(docker info --format '{{.MemTotal}}')
+ # Convert from bytes to GB
+ local totalRamGB=$((totalRamBytes / 1024 / 1024 / 1024))
+
+ if [ "${totalRamGB}" -ge "${requiredRamGB}" ]; then
+ echo "[INFO] Docker RAM check passed: ${totalRamGB} GB available."
+ else
+ echo "[ERROR] Docker RAM check failed: Only ${totalRamGB} GB available,
${requiredRamGB} GB or more required."
+ exit 1
+ fi
+}
+
+checkDockerCpu() {
+ local cpuCores=$(docker info --format '{{.NCPU}}')
+
+ if [ "${cpuCores}" -ge "${requiredCpuCores}" ]; then
+ echo "[INFO] Docker CPU check passed: ${cpuCores} cores available."
+ else
+ echo "[ERROR] Docker CPU check failed: Only ${cpuCores} cores available,
${requiredCpuCores} cores or more required."
+ exit 1
+ fi
+}
+
+testK8s() {
+ echo "[INFO] Testing K8s environment..."
+ kubectl cluster-info
Review Comment:
Before the `start`, `status`, or `stop` commands are run, the
`checkCurrentRuntime` function will be executed.
The `checkCurrentRuntime` function checks whether `kubectl` is present.


--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]