Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: setup proxy variables in the start #32451

Merged
merged 1 commit into from
May 10, 2024

Conversation

pratapaprasanna
Copy link
Contributor

@pratapaprasanna pratapaprasanna commented Apr 5, 2024

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.

Copy link
Contributor

coderabbitai bot commented Apr 5, 2024

Walkthrough

Walkthrough

The recent changes focus on optimizing network configurations, enhancing Mixpanel event tracking, and improving Redis compatibility in the entrypoint.sh script. Key updates include refactoring proxy setup, adjusting Mixpanel event tracking, setting backend heap arguments, and introducing infrastructure details capture.

Changes

File Path Change Summary
.../appsmith/entrypoint.sh Refactored proxy setup, adjusted Mixpanel event tracking, set backend heap arguments, added capture_infra_details() function, and enhanced Redis compatibility checks.

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 6a6e494 and 96d7266.
Files selected for processing (1)
  • deploy/docker/fs/opt/appsmith/entrypoint.sh (5 hunks)
Additional Context Used
ShellCheck (8)
deploy/docker/fs/opt/appsmith/entrypoint.sh (8)

[warning] 57-57: Declare and assign separately to avoid masking return values.


[warning] 61-61: Declare and assign separately to avoid masking return values.


[warning] 65-65: Declare and assign separately to avoid masking return values.


[warning] 69-69: Declare and assign separately to avoid masking return values.


[warning] 79-79: ShellCheck can't follow non-constant source. Use a directive to specify location.


[info] 80-80: Not following: ./pre-define.env was not specified as input (see shellcheck -x).


[style] 136-136: Use -n instead of ! -z.


[info] 463-463: Double quote to prevent globbing and word splitting.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

deploy/docker/fs/opt/appsmith/entrypoint.sh Show resolved Hide resolved
@@ -369,7 +374,7 @@
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a --connect-timeout setting to the curl command used for downloading Redis source, to maintain consistency with other network requests in the script.

- curl --connect-timeout 5 --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

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
curl --connect-timeout 5 --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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Actionable comments outside the diff hunks (2)
deploy/docker/fs/opt/appsmith/entrypoint.sh (2)

Line range hint 113-125: Consider declaring and assigning variables separately to avoid masking return values. This can help in identifying issues where commands fail but are not properly handled.

- local generated_appsmith_mongodb_password=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13; echo "")
+ local generated_appsmith_mongodb_password
+ generated_appsmith_mongodb_password=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13; echo "")

Apply similar changes to generated_appsmith_encryption_password, generated_appsmith_encription_salt, and generated_appsmith_supervisor_password.


Line range hint 462-462: Ensure variables are double-quoted to prevent globbing and word splitting, which can lead to unexpected behavior.

- su postgres -c "/usr/lib/postgresql/13/bin/createuser $1 -s"
+ su postgres -c "/usr/lib/postgresql/13/bin/createuser \"$1\" -s"

@pratapaprasanna pratapaprasanna force-pushed the use/setup/proxies/from/the/start branch from ddc683e to 02dc538 Compare April 16, 2024 10:33
@github-actions github-actions bot added the Bug Something isn't working label Apr 16, 2024
@pratapaprasanna
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/8704153760.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 32451.
recreate: .

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Copy link

Deploy-Preview-URL: https://ce-32451.dp.appsmith.com

Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Apr 26, 2024
@sharat87 sharat87 removed the Stale label May 1, 2024
Copy link
Member

@sharat87 sharat87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Let's resolve the conflicts (likely due to the URL change to get IP address) and I'll test the DP image once before merging. We should be good.

setup_proxy_variables
init_env_file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these be the other way around?

Suggested change
setup_proxy_variables
init_env_file
init_env_file
setup_proxy_variables

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Out of diff range and nitpick comments (1)
deploy/docker/fs/opt/appsmith/entrypoint.sh (1)

Line range hint 57-57: Consider separating declaration and assignment to avoid masking return values.

- local generated_appsmith_mongodb_password=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13; echo "")
+ local generated_appsmith_mongodb_password
+ generated_appsmith_mongodb_password=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13; echo "")

Apply similar changes for generated_appsmith_encryption_password, generated_appsmith_encription_salt, and generated_appsmith_supervisor_password.

Also applies to: 61-61, 65-65, 69-69

Comment on lines +14 to +39
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The output from the verification script indicates that the entrypoint.sh script was sourced, but it encountered several issues, including permission denials and missing commands. Additionally, the script did not output the expected environment variables (NO_PROXY, HTTPS_PROXY, HTTP_PROXY) after sourcing, which was the primary goal of the test.

Given these issues, it is recommended to adjust the script to handle errors more gracefully and to ensure it outputs the necessary environment variables. A retest in a controlled environment where permissions and commands are not an issue might be necessary to verify the script's functionality thoroughly.

  • The script encountered permission issues and missing commands, which prevented it from functioning as expected.
  • The environment variables were not output after sourcing the script, indicating potential issues in the script's execution or environment setup.
Analysis chain

Refactored proxy setup looks good and should simplify maintenance.


The output from the verification script indicates that the environment variables NO_PROXY, HTTPS_PROXY, and HTTP_PROXY are not being set as expected. This could be due to the script not being executed in an environment where these variables are predefined, or there might be an issue with how the script sets or exports these variables.

To further investigate and ensure the script functions as intended, it would be beneficial to check the behavior of the script in an environment where these proxy variables are predefined. This will help confirm if the script correctly applies the proxy settings during deployment.

This script will help verify if the entrypoint.sh script correctly handles and applies the proxy settings when the environment variables are predefined.


The output from the verification script indicates that the entrypoint.sh script could not be sourced due to a path issue, which prevented the verification of the script's functionality. The environment variables NO_PROXY, HTTPS_PROXY, and HTTP_PROXY were correctly set before attempting to source the script, but without executing the script, we cannot confirm if it functions as intended.

To proceed, we need to correct the path issue and attempt to source the script again to verify its functionality.

This script will help verify if the entrypoint.sh script correctly handles and applies the proxy settings when the environment variables are predefined, addressing the path issue from the previous attempt.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the proxy settings are correctly applied during deployment.

# Test: Check the environment variables after deployment to ensure they are set correctly.
echo "NO_PROXY: $NO_PROXY"
echo "HTTPS_PROXY: $HTTPS_PROXY"
echo "HTTP_PROXY: $HTTP_PROXY"

Length of output: 102



Script:

#!/bin/bash
# Description: Verify the behavior of the proxy settings script in an environment with predefined proxy variables.

# Predefine some proxy variables
export NO_PROXY="localhost,127.0.0.1"
export HTTPS_PROXY="https://proxy.example.com:443"
export HTTP_PROXY="http://proxy.example.com:80"

# Source the script to apply the proxy settings
source /opt/appsmith/entrypoint.sh

# Check the environment variables after sourcing the script to ensure they are set correctly.
echo "NO_PROXY: $NO_PROXY"
echo "HTTPS_PROXY: $HTTPS_PROXY"
echo "HTTP_PROXY: $HTTP_PROXY"

Length of output: 646



Script:

#!/bin/bash
# Description: Correct the path issue and verify the behavior of the proxy settings script in an environment with predefined proxy variables.

# Predefine some proxy variables
export NO_PROXY="localhost,127.0.0.1"
export HTTPS_PROXY="https://proxy.example.com:443"
export HTTP_PROXY="http://proxy.example.com:80"

# Correct the path to the script and source it to apply the proxy settings
source deploy/docker/fs/opt/appsmith/entrypoint.sh

# Check the environment variables after sourcing the script to ensure they are set correctly.
echo "NO_PROXY: $NO_PROXY"
echo "HTTPS_PROXY: $HTTPS_PROXY"
echo "HTTP_PROXY: $HTTP_PROXY"

Length of output: 816

}

function setup_backend_heap_arg() {
if [[ ! -z ${maximum_heap} ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify the condition check for clarity.

- if [[ ! -z ${maximum_heap} ]]; then
+ if [[ -n ${maximum_heap} ]]; then

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if [[ ! -z ${maximum_heap} ]]; then
if [[ -n ${maximum_heap} ]]; then

@pratapaprasanna
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/9031381974.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 32451.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-32451.dp.appsmith.com

@pratapaprasanna pratapaprasanna merged commit 9ade3d6 into release May 10, 2024
13 checks passed
@pratapaprasanna pratapaprasanna deleted the use/setup/proxies/from/the/start branch May 10, 2024 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants