PromucFlow_constructor/deploy/docker/fs/opt/appsmith/generate-infra-details.sh
Goutham Pratapa 947add2f20
[ops]: get infra details (#32552)
Outputs on having the container up and running

On kubernetes:
```
root@ce32552-appsmith-66fc68d7f-97tjn:/opt/appsmith# cat /tmp/appsmith/infra.json
{"cloudProvider":"amazon","Tool":"kubernetes","EFS":"present","Hostname":"ce32552-appsmith-66fc68d7f-97tjn"}
```

On local setup:
```
root@26327db8d65a:/opt/appsmith# cat /tmp/appsmith/infra.json
{"cloudProvider":"local","Tool":"docker","EFS":"absent","Hostname":"26327db8d65a"}
```

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced infrastructure detection to enhance system insights,
including cloud provider, deployment tools, and host details.
- Enhanced analytics by incorporating deployment properties into event
tracking.

- **Refactor**
- Modified server configuration and initialization to integrate new
deployment properties.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Trisha Anand <trisha@appsmith.com>
2024-04-26 18:56:45 +05:30

62 lines
1.2 KiB
Bash
Executable File

#!/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
cloud_provider="amazon";
elif [[ $release_details == *"azure"* ]];then
cloud_provider="azure";
elif [[ $release_details == *"cloud"* ]];then
cloud_provider="gcp";
else
cloud_provider="local";
fi
}
## Get deployment tool details
function get_tool() {
if [[ -z "${KUBERNETES_SERVICE_HOST}" ]]; then
dep_tool="docker";
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)"
}
## Main Block
get_cloud_provider
get_tool
get_hostname
check_for_efs
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