Skip to content

Commit

Permalink
fix: setup proxy variables in the start (#32451)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **Chores**
- Improved proxy settings, IP retrieval with timeout, and curl request
timeouts in the deployment process.
	- Enhanced Redis compatibility checks and installation steps.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
pratapaprasanna committed May 10, 2024
1 parent d4937d3 commit 9ade3d6
Showing 1 changed file with 77 additions and 73 deletions.
150 changes: 77 additions & 73 deletions deploy/docker/fs/opt/appsmith/entrypoint.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,34 @@ export MONGODB_TMP_KEY_PATH="$TMP/mongodb-key" # export for use in supervisor p

mkdir -pv "$SUPERVISORD_CONF_TARGET" "$WWW_PATH"

# ip is a reserved keyword for tracking events in Mixpanel. Instead of showing the ip as is Mixpanel provides derived properties.
# As we want derived props alongwith the ip address we are sharing the ip address in separate keys
# https://help.mixpanel.com/hc/en-us/articles/360001355266-Event-Properties
if [[ -n ${APPSMITH_SEGMENT_CE_KEY-} ]]; then
ip="$(set -o pipefail; curl -sS https://cs.appsmith.com/api/v1/ip | grep -Eo '\d+(\.\d+){3}' || echo "unknown")"
curl \
--user "$APPSMITH_SEGMENT_CE_KEY:" \
--header 'Content-Type: application/json' \
--data '{
"userId":"'"$ip"'",
"event":"Instance Start",
"properties": {
"ip": "'"$ip"'",
"ipAddress": "'"$ip"'"
}
}' \
https://api.segment.io/v1/track \
|| true
fi

if [[ -n "${FILESTORE_IP_ADDRESS-}" ]]; then

## Trim APPSMITH_FILESTORE_IP and FILE_SHARE_NAME
FILESTORE_IP_ADDRESS="$(echo "$FILESTORE_IP_ADDRESS" | xargs)"
FILE_SHARE_NAME="$(echo "$FILE_SHARE_NAME" | xargs)"
setup_proxy_variables() {
export NO_PROXY="${NO_PROXY-localhost,127.0.0.1}"

echo "Running appsmith for cloudRun"
echo "creating mount point"
mkdir -p "$stacks_path"
echo "Mounting File Sytem"
mount -t nfs -o nolock "$FILESTORE_IP_ADDRESS:/$FILE_SHARE_NAME" /appsmith-stacks
echo "Mounted File Sytem"
echo "Setting HOSTNAME for Cloudrun"
export HOSTNAME="cloudrun"
fi
# Ensure `localhost` and `127.0.0.1` are in always present in `NO_PROXY`.
local no_proxy_lines
no_proxy_lines="$(echo "$NO_PROXY" | tr , \\n)"
if ! echo "$no_proxy_lines" | grep -q '^localhost$'; then
export NO_PROXY="localhost,$NO_PROXY"
fi
if ! echo "$no_proxy_lines" | grep -q '^127.0.0.1$'; then
export NO_PROXY="127.0.0.1,$NO_PROXY"
fi

# If one of HTTPS_PROXY or https_proxy are set, copy it to the other. If both are set, prefer HTTPS_PROXY.
if [[ -n ${HTTPS_PROXY-} ]]; then
export https_proxy="$HTTPS_PROXY"
elif [[ -n ${https_proxy-} ]]; then
export HTTPS_PROXY="$https_proxy"
fi

function get_maximum_heap() {
resource=$(ulimit -u)
echo "Resource : $resource"
if [[ "$resource" -le 256 ]]; then
maximum_heap=128
elif [[ "$resource" -le 512 ]]; then
maximum_heap=256
fi
# If one of HTTP_PROXY or http_proxy are set, copy it to the other. If both are set, prefer HTTP_PROXY.
if [[ -n ${HTTP_PROXY-} ]]; then
export http_proxy="$HTTP_PROXY"
elif [[ -n ${http_proxy-} ]]; then
export HTTP_PROXY="$http_proxy"
fi
}

function setup_backend_heap_arg() {
if [[ ! -z ${maximum_heap} ]]; then
export APPSMITH_JAVA_HEAP_ARG="-Xmx${maximum_heap}m"
fi
}

init_env_file() {
CONF_PATH="/appsmith-stacks/configuration"
Expand Down Expand Up @@ -105,32 +81,61 @@ init_env_file() {
set +o allexport
}

setup_proxy_variables() {
export NO_PROXY="${NO_PROXY-localhost,127.0.0.1}"
init_env_file
setup_proxy_variables

# Ensure `localhost` and `127.0.0.1` are in always present in `NO_PROXY`.
local no_proxy_lines
no_proxy_lines="$(echo "$NO_PROXY" | tr , \\n)"
if ! echo "$no_proxy_lines" | grep -q '^localhost$'; then
export NO_PROXY="localhost,$NO_PROXY"
fi
if ! echo "$no_proxy_lines" | grep -q '^127.0.0.1$'; then
export NO_PROXY="127.0.0.1,$NO_PROXY"
fi
# ip is a reserved keyword for tracking events in Mixpanel. Instead of showing the ip as is Mixpanel provides derived properties.
# As we want derived props alongwith the ip address we are sharing the ip address in separate keys
# https://help.mixpanel.com/hc/en-us/articles/360001355266-Event-Properties
if [[ -n ${APPSMITH_SEGMENT_CE_KEY-} ]]; then
ip="$(set -o pipefail; curl --connect-timeout 5 -sS https://cs.appsmith.com/api/v1/ip | grep -Eo '\d+(\.\d+){3}' || echo "unknown")"
curl \
--connect-timeout 5 \
--user "$APPSMITH_SEGMENT_CE_KEY:" \
--header 'Content-Type: application/json' \
--data '{
"userId":"'"$ip"'",
"event":"Instance Start",
"properties": {
"ip": "'"$ip"'",
"ipAddress": "'"$ip"'"
}
}' \
https://api.segment.io/v1/track \
|| true
fi

# If one of HTTPS_PROXY or https_proxy are set, copy it to the other. If both are set, prefer HTTPS_PROXY.
if [[ -n ${HTTPS_PROXY-} ]]; then
export https_proxy="$HTTPS_PROXY"
elif [[ -n ${https_proxy-} ]]; then
export HTTPS_PROXY="$https_proxy"
fi
if [[ -n "${FILESTORE_IP_ADDRESS-}" ]]; then

# If one of HTTP_PROXY or http_proxy are set, copy it to the other. If both are set, prefer HTTP_PROXY.
if [[ -n ${HTTP_PROXY-} ]]; then
export http_proxy="$HTTP_PROXY"
elif [[ -n ${http_proxy-} ]]; then
export HTTP_PROXY="$http_proxy"
fi
## Trim APPSMITH_FILESTORE_IP and FILE_SHARE_NAME
FILESTORE_IP_ADDRESS="$(echo "$FILESTORE_IP_ADDRESS" | xargs)"
FILE_SHARE_NAME="$(echo "$FILE_SHARE_NAME" | xargs)"

echo "Running appsmith for cloudRun"
echo "creating mount point"
mkdir -p "$stacks_path"
echo "Mounting File Sytem"
mount -t nfs -o nolock "$FILESTORE_IP_ADDRESS:/$FILE_SHARE_NAME" /appsmith-stacks
echo "Mounted File Sytem"
echo "Setting HOSTNAME for Cloudrun"
export HOSTNAME="cloudrun"
fi


function get_maximum_heap() {
resource=$(ulimit -u)
echo "Resource : $resource"
if [[ "$resource" -le 256 ]]; then
maximum_heap=128
elif [[ "$resource" -le 512 ]]; then
maximum_heap=256
fi
}

function setup_backend_heap_arg() {
if [[ ! -z ${maximum_heap} ]]; then
export APPSMITH_JAVA_HEAP_ARG="-Xmx${maximum_heap}m"
fi
}

unset_unused_variables() {
Expand Down Expand Up @@ -360,6 +365,7 @@ check_redis_compatible_page_size() {
page_size="$(getconf PAGE_SIZE)"
if [[ $page_size -gt 4096 ]]; then
curl \
--connect-timeout 5 \
--silent \
--user "$APPSMITH_SEGMENT_CE_KEY:" \
--header 'Content-Type: application/json' \
Expand All @@ -369,7 +375,7 @@ check_redis_compatible_page_size() {
echo "Compile Redis stable with page size of $page_size"
apt-get update
apt-get install --yes build-essential
curl --location https://download.redis.io/redis-stable.tar.gz | tar -xz -C /tmp
curl --connect-timeout 5 --location https://download.redis.io/redis-stable.tar.gz | tar -xz -C /tmp
pushd /tmp/redis-stable
make
make install
Expand Down Expand Up @@ -469,8 +475,6 @@ function capture_infra_details(){
# Main Section
print_appsmith_info
init_loading_pages
init_env_file
setup_proxy_variables
unset_unused_variables

check_mongodb_uri
Expand Down

0 comments on commit 9ade3d6

Please sign in to comment.