2024-04-26 13:26:45 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
infra_file="$TMP/infra.json"
|
|
|
|
|
mount_path="/appsmith-stacks"
|
|
|
|
|
|
|
|
|
|
## Get cloudProvider details
|
|
|
|
|
function get_cloud_provider() {
|
|
|
|
|
release_details=$(uname -r)
|
|
|
|
|
if [[ $release_details == *"amzn"* ]];then
|
2024-05-27 11:46:13 +00:00
|
|
|
# Example: 5.10.192-183.736.amzn2.x86_64
|
2024-04-26 13:26:45 +00:00
|
|
|
cloud_provider="amazon";
|
|
|
|
|
elif [[ $release_details == *"azure"* ]];then
|
2024-05-27 11:46:13 +00:00
|
|
|
# Example: 5.15.0-1059-azure
|
2024-04-26 13:26:45 +00:00
|
|
|
cloud_provider="azure";
|
|
|
|
|
elif [[ $release_details == *"cloud"* ]];then
|
2024-05-27 11:46:13 +00:00
|
|
|
# Example: 6.1.0-18-cloud-amd64
|
2024-04-26 13:26:45 +00:00
|
|
|
cloud_provider="gcp";
|
2024-05-27 11:46:13 +00:00
|
|
|
elif [[ $release_details == *"generic"* ]];then
|
|
|
|
|
# Example: 6.8.0-31-generic
|
|
|
|
|
cloud_provider="digitalocean"
|
|
|
|
|
elif [[ $release_details == *"ecs"* ]];then
|
|
|
|
|
cloud_provider="alibaba"
|
|
|
|
|
elif [[ -n "${DYNO}" ]];then
|
|
|
|
|
cloud_provider="heroku"
|
2024-04-26 13:26:45 +00:00
|
|
|
else
|
2024-05-27 11:46:13 +00:00
|
|
|
cloud_provider="others(including local)";
|
2024-04-26 13:26:45 +00:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## Get deployment tool details
|
|
|
|
|
function get_tool() {
|
|
|
|
|
if [[ -z "${KUBERNETES_SERVICE_HOST}" ]]; then
|
2024-05-27 11:46:13 +00:00
|
|
|
dep_tool="likely docker";
|
2024-04-26 13:26:45 +00:00
|
|
|
else
|
|
|
|
|
dep_tool="kubernetes";
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## Check if EFS is mounted
|
|
|
|
|
function check_for_efs() {
|
|
|
|
|
findmnt --mountpoint $mount_path | grep nfs && {
|
|
|
|
|
efs="present"
|
|
|
|
|
} || {
|
|
|
|
|
efs="absent"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## Check hostname
|
|
|
|
|
function get_hostname() {
|
|
|
|
|
hostname="$(cat /etc/hostname)"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## Get current Time
|
|
|
|
|
function get_current_time(){
|
|
|
|
|
currentTime="$(date -u -Iseconds)"
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 11:46:13 +00:00
|
|
|
## Check if it's a ECS Fargate deployment
|
|
|
|
|
function check_for_fargate() {
|
|
|
|
|
if [[ $cloud_provider == "amazon" && $dep_tool == "likely docker" && $efs == "present" ]]; then
|
|
|
|
|
dep_tool="ecs-fargate"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 13:26:45 +00:00
|
|
|
## Main Block
|
|
|
|
|
get_cloud_provider
|
|
|
|
|
get_tool
|
|
|
|
|
get_hostname
|
|
|
|
|
check_for_efs
|
2024-05-27 11:46:13 +00:00
|
|
|
check_for_fargate
|
2024-04-26 13:26:45 +00:00
|
|
|
get_current_time
|
|
|
|
|
|
|
|
|
|
infra_json='{"cloudProvider":"'"$cloud_provider"'","tool":"'"$dep_tool"'","efs":"'"$efs"'","hostname":"'"$hostname"'", "currentTime": "'"$currentTime"'"}'
|
|
|
|
|
echo "$infra_json"
|
|
|
|
|
|
|
|
|
|
echo $infra_json > $infra_file
|