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

chore: Switch to vanilla Caddy, when rate limiting is disabled #33387

Merged
merged 8 commits into from
May 24, 2024

Conversation

pratapaprasanna
Copy link
Contributor

@pratapaprasanna pratapaprasanna commented May 13, 2024

Depends-on: 33591
Fixes: #31997

@pratapaprasanna pratapaprasanna changed the title [wip]: make xcaddy configurable based on env [feat]: make xcaddy configurable based on env May 14, 2024
@pratapaprasanna pratapaprasanna marked this pull request as ready for review May 14, 2024 10:21
Copy link
Contributor

coderabbitai bot commented May 14, 2024

Walkthrough

Walkthrough

The changes primarily focus on refining the configuration and setup processes for the Caddy server within the Appsmith deployment scripts. Key updates include handling the RATE_LIMIT environment variable more dynamically, introducing a setup_caddy() function, and modifying script calls to use environment variables. Additionally, a CI test script was updated to reflect these changes in environment variable handling.

Changes

File Path Change Summary
.../caddy-reconfigure.mjs
.../entrypoint.sh
Enhanced handling of the RATE_LIMIT environment variable in caddy-reconfigure.mjs and added setup_caddy() function in entrypoint.sh.
.../run-caddy.sh Replaced direct calls to /opt/caddy/caddy with $_APPSMITH_CADDY for managing Caddy operations.
.github/workflows/ci-test-custom-script.yml Updated the environment variable from _APPSMITH_RATE_LIMIT to APPSMITH_RATE_LIMIT for CI tests.

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between a6aaa0e and 6b66526.
Files selected for processing (1)
  • deploy/docker/fs/opt/appsmith/entrypoint.sh (2 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] 471-471: Double quote to prevent globbing and word splitting.

Additional comments not posted (1)
deploy/docker/fs/opt/appsmith/entrypoint.sh (1)

464-464: Quote the command to prevent globbing and word splitting.

-  "$_APPSMITH_CADDY" start --config "$TMP/Caddyfile"
+  "${_APPSMITH_CADDY}" start --config "$TMP/Caddyfile"

This modification ensures that the command is properly quoted, which is crucial for preventing errors in paths that might contain spaces or special characters.


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.

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: 5

Out of diff range and nitpick comments (2)
deploy/docker/fs/opt/appsmith/caddy-reconfigure.mjs (1)

Line range hint 266-284: Ensure proper error handling when writing to the Caddyfile.

try {
  fs.mkdirSync(dirname(CaddyfilePath), { recursive: true });
  fs.writeFileSync(CaddyfilePath, parts.join("\n"));
  spawnSync("/opt/caddy/caddy", ["fmt", "--overwrite", CaddyfilePath]);
  spawnSync("/opt/caddy/caddy", ["reload", "--config", CaddyfilePath]);
} catch (error) {
  console.error("Error configuring Caddy:", error);
}
deploy/docker/fs/opt/appsmith/entrypoint.sh (1)

Line range hint 136-136: Use -n instead of ! -z for better readability.

if [[ -n ${maximum_heap} ]]; then
  export APPSMITH_JAVA_HEAP_ARG="-Xmx${maximum_heap}m"
fi

Comment on lines 51 to 55
RUN set -o xtrace \
&& mkdir -p /opt/basecaddy \
&& version="$(curl --write-out '%{redirect_url}' 'https://github.com/caddyserver/caddy/releases/latest' | sed 's,.*/v,,')" \
&& curl --location "https://github.com/caddyserver/caddy/releases/download/v$version/caddy_${version}_linux_$(uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/').tar.gz" \
| tar -xz -C /opt/basecaddy
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid masking return values by separating declaration and assignment.

RUN set -o xtrace \
  && mkdir -p /opt/basecaddy \
-  && version="$(curl --write-out '%{redirect_url}' 'https://github.com/caddyserver/caddy/releases/latest' | sed 's,.*/v,,')" \
+  && curl --write-out '%{redirect_url}' 'https://github.com/caddyserver/caddy/releases/latest' | sed 's,.*/v,,') \
+  && version="${version}" \
  && curl --location "https://github.com/caddyserver/caddy/releases/download/v$version/caddy_${version}_linux_$(uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/').tar.gz" \
  | tar -xz -C /opt/basecaddy

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
RUN set -o xtrace \
&& mkdir -p /opt/basecaddy \
&& version="$(curl --write-out '%{redirect_url}' 'https://github.com/caddyserver/caddy/releases/latest' | sed 's,.*/v,,')" \
&& curl --location "https://github.com/caddyserver/caddy/releases/download/v$version/caddy_${version}_linux_$(uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/').tar.gz" \
| tar -xz -C /opt/basecaddy
RUN set -o xtrace \
&& mkdir -p /opt/basecaddy \
&& curl --write-out '%{redirect_url}' 'https://github.com/caddyserver/caddy/releases/latest' | sed 's,.*/v,,') \
&& version="${version}" \
&& curl --location "https://github.com/caddyserver/caddy/releases/download/v$version/caddy_${version}_linux_$(uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/').tar.gz" \
| tar -xz -C /opt/basecaddy

Comment on lines 13 to 21
const RATE_LIMIT_ENV = (process.env._APPSMITH_RATE_LIMIT)

if (RATE_LIMIT_ENV == "disabled") {
var RATE_LIMIT = undefined
}
else {
// Rate limit, numeric value defining the requests-per-second allowed.
var RATE_LIMIT = parseInt(process.env._APPSMITH_RATE_LIMIT || 100, 10)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Use const or let instead of var for block-scoped variables.

const RATE_LIMIT_ENV = (process.env._APPSMITH_RATE_LIMIT);

if (RATE_LIMIT_ENV == "disabled") {
-  var RATE_LIMIT = undefined;
+  let RATE_LIMIT = undefined;
} else {
  // Rate limit, numeric value defining the requests-per-second allowed.
-  var RATE_LIMIT = parseInt(process.env._APPSMITH_RATE_LIMIT || 100, 10);
+  let RATE_LIMIT = parseInt(process.env._APPSMITH_RATE_LIMIT || 100, 10);
}

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
const RATE_LIMIT_ENV = (process.env._APPSMITH_RATE_LIMIT)
if (RATE_LIMIT_ENV == "disabled") {
var RATE_LIMIT = undefined
}
else {
// Rate limit, numeric value defining the requests-per-second allowed.
var RATE_LIMIT = parseInt(process.env._APPSMITH_RATE_LIMIT || 100, 10)
}
const RATE_LIMIT_ENV = (process.env._APPSMITH_RATE_LIMIT);
if (RATE_LIMIT_ENV == "disabled") {
let RATE_LIMIT = undefined;
} else {
// Rate limit, numeric value defining the requests-per-second allowed.
let RATE_LIMIT = parseInt(process.env._APPSMITH_RATE_LIMIT || 100, 10);
}

Comment on lines 50 to 152
{
debug
admin 127.0.0.1:2019
persist_config off
acme_ca_root /etc/ssl/certs/ca-certificates.crt
servers {
trusted_proxies static 0.0.0.0/0
}
}

(file_server) {
file_server {
precompressed br gzip
disable_canonical_uris
}
}

(reverse_proxy) {
reverse_proxy {
to 127.0.0.1:{args[0]}
header_up -Forwarded
header_up X-Appsmith-Request-Id {http.request.uuid}
}
}

(all-config) {
log {
output stdout
}
skip_log /api/v1/health

# The internal request ID header should never be accepted from an incoming request.
request_header -X-Appsmith-Request-Id

# Ref: https://stackoverflow.com/a/38191078/151048
# We're only accepting v4 UUIDs today, in order to not make it too lax unless needed.
@valid-request-id expression {header.X-Request-Id}.matches("(?i)^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$")
header @valid-request-id X-Request-Id {header.X-Request-Id}
@invalid-request-id expression !{header.X-Request-Id}.matches("(?i)^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$")
header @invalid-request-id X-Request-Id invalid_request_id
request_header @invalid-request-id X-Request-Id invalid_request_id

header {
-Server
Content-Security-Policy "frame-ancestors ${frameAncestorsPolicy}"
X-Content-Type-Options "nosniff"
X-Appsmith-Request-Id {http.request.uuid}
}

request_body {
max_size ${process.env.APPSMITH_CODEC_SIZE || 150}MB
}

handle {
root * {$WWW_PATH}
try_files /loading.html /index.html
import file_server
}
root * /opt/appsmith/editor
@file file
handle @file {
import file_server
skip_log
}

handle /static/* {
error 404
}

handle /info {
root * /opt/appsmith
rewrite * /info.json
import file_server
}

@backend path /api/* /oauth2/* /login/*
handle @backend {
import reverse_proxy 8080
}

handle /rts/* {
import reverse_proxy 8091
}

redir /supervisor /supervisor/
handle_path /supervisor/* {
import reverse_proxy 9001
}

handle_errors {
respond "{err.status_code} {err.status_text}" {err.status_code}
header -Server
}
}

# We bind to http on 80, so that localhost requests don't get redirected to https.
:80 {
import all-config
}
`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider refactoring the repeated Caddyfile configuration blocks to avoid duplication.

if (RATE_LIMIT == undefined) {
  parts.push(`
  {
    debug
    admin 127.0.0.1:2019
    persist_config off
    acme_ca_root /etc/ssl/certs/ca-certificates.crt
    servers {
      trusted_proxies static 0.0.0.0/0
    }
  }
  ...
  `);
} else {
  parts.push(`
  {
    debug
    admin 127.0.0.1:2019
    persist_config off
    acme_ca_root /etc/ssl/certs/ca-certificates.crt
    servers {
      trusted_proxies static 0.0.0.0/0
    }
    order rate_limit before basicauth
  }
  ...
  `);
}

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 (RATE_LIMIT == undefined ) {
parts.push(`
{
debug
admin 127.0.0.1:2019
persist_config off
acme_ca_root /etc/ssl/certs/ca-certificates.crt
servers {
trusted_proxies static 0.0.0.0/0
}
}
(file_server) {
file_server {
precompressed br gzip
disable_canonical_uris
}
}
(reverse_proxy) {
reverse_proxy {
to 127.0.0.1:{args[0]}
header_up -Forwarded
header_up X-Appsmith-Request-Id {http.request.uuid}
}
}
(all-config) {
log {
output stdout
}
skip_log /api/v1/health
# The internal request ID header should never be accepted from an incoming request.
request_header -X-Appsmith-Request-Id
# Ref: https://stackoverflow.com/a/38191078/151048
# We're only accepting v4 UUIDs today, in order to not make it too lax unless needed.
@valid-request-id expression {header.X-Request-Id}.matches("(?i)^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$")
header @valid-request-id X-Request-Id {header.X-Request-Id}
@invalid-request-id expression !{header.X-Request-Id}.matches("(?i)^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$")
header @invalid-request-id X-Request-Id invalid_request_id
request_header @invalid-request-id X-Request-Id invalid_request_id
header {
-Server
Content-Security-Policy "frame-ancestors ${frameAncestorsPolicy}"
X-Content-Type-Options "nosniff"
X-Appsmith-Request-Id {http.request.uuid}
}
request_body {
max_size ${process.env.APPSMITH_CODEC_SIZE || 150}MB
}
handle {
root * {$WWW_PATH}
try_files /loading.html /index.html
import file_server
}
root * /opt/appsmith/editor
@file file
handle @file {
import file_server
skip_log
}
handle /static/* {
error 404
}
handle /info {
root * /opt/appsmith
rewrite * /info.json
import file_server
}
@backend path /api/* /oauth2/* /login/*
handle @backend {
import reverse_proxy 8080
}
handle /rts/* {
import reverse_proxy 8091
}
redir /supervisor /supervisor/
handle_path /supervisor/* {
import reverse_proxy 9001
}
handle_errors {
respond "{err.status_code} {err.status_text}" {err.status_code}
header -Server
}
}
# We bind to http on 80, so that localhost requests don't get redirected to https.
:80 {
import all-config
}
`)
if (RATE_LIMIT == undefined) {
parts.push(`
{
debug
admin 127.0.0.1:2019
persist_config off
acme_ca_root /etc/ssl/certs/ca-certificates.crt
servers {
trusted_proxies static 0.0.0.0/0
}
...
`);
} else {
parts.push(`
{
debug
admin 127.0.0.1:2019
persist_config off
acme_ca_root /etc/ssl/certs/ca-certificates.crt
servers {
trusted_proxies static 0.0.0.0/0
}
order rate_limit before basicauth
...
`);
}

Comment on lines 450 to 455
setup_caddy() {
if [[ $_APPSMITH_RATE_LIMIT == "disabled" ]]; then
echo "rate limiting is disabled"
mv /opt/basecaddy/caddy /opt/caddy/caddy
fi
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Double quote to prevent globbing and word splitting.

setup_caddy() {
  if [[ "$_APPSMITH_RATE_LIMIT" == "disabled" ]]; then
    echo "rate limiting is disabled"
    mv /opt/basecaddy/caddy /opt/caddy/caddy
  fi
}

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
setup_caddy() {
if [[ $_APPSMITH_RATE_LIMIT == "disabled" ]]; then
echo "rate limiting is disabled"
mv /opt/basecaddy/caddy /opt/caddy/caddy
fi
}
setup_caddy() {
if [[ "$_APPSMITH_RATE_LIMIT" == "disabled" ]]; then
echo "rate limiting is disabled"
mv /opt/basecaddy/caddy /opt/caddy/caddy
fi
}

sharat87 and others added 3 commits May 14, 2024 16:24
…ake/xcaddy/configurable

# Conflicts:
#	deploy/docker/fs/opt/appsmith/caddy-reconfigure.mjs
@pratapaprasanna pratapaprasanna self-assigned this May 14, 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.

We need to reverse the boolean check we added in the reconfigure script, it's inverted currently. Rest are minor recommended fixes and we should be ready to merge.

exec /opt/caddy/caddy run --config "$TMP/Caddyfile"
exec "$_APPSMITH_CADDY" run --config "$TMP/Caddyfile"
Copy link
Member

Choose a reason for hiding this comment

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

Small nitpick, let's not lose the final newline. A final newline character at the end of files is usually recommended since some old tools have problem dealing with files that don't have a final newline character.

Ref:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is because of the vi editor I use I guess. I dont do that deliberately Let me take care going forward

@@ -16,6 +16,6 @@ gzip --keep --force "$(basename "$WWW_PATH/index.html")"
popd

# Caddy may already be running for the loading page.
/opt/caddy/caddy stop --config "$TMP/Caddyfile" || true
$_APPSMITH_CADDY stop --config "$TMP/Caddyfile" || true
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$_APPSMITH_CADDY stop --config "$TMP/Caddyfile" || true
"$_APPSMITH_CADDY" stop --config "$TMP/Caddyfile" || true

@@ -217,4 +217,4 @@ function isCertExpired(path) {
const cert = new X509Certificate(fs.readFileSync(path, "utf-8"))
console.log(path, cert)
return new Date(cert.validTo) < new Date()
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Let's not remove the final newline.

Suggested change
}
}

const CaddyfilePath = process.env.TMP + "/Caddyfile"

// Rate limit environment.
const isRateLimitingDisabled = process.env.APPSMITH_RATE_LIMIT === "disabled"
Copy link
Member

Choose a reason for hiding this comment

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

Looks like I've unfortunately applied this condition in reverse. It's named isRateLimitingDisabled, but is actually used in later code like it's isRateLimitingEnabled. Let's rename it and change === to !==.

init_loading_pages(){
export XDG_DATA_HOME=/appsmith-stacks/data # so that caddy saves tls certs and other data under stacks/data/caddy
export XDG_CONFIG_HOME=/appsmith-stacks/configuration
mkdir -p "$XDG_DATA_HOME" "$XDG_CONFIG_HOME"
cp templates/loading.html "$WWW_PATH"
node caddy-reconfigure.mjs
/opt/caddy/caddy start --config "$TMP/Caddyfile"
$_APPSMITH_CADDY start --config "$TMP/Caddyfile"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$_APPSMITH_CADDY start --config "$TMP/Caddyfile"
"$_APPSMITH_CADDY" start --config "$TMP/Caddyfile"

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

@@ -447,13 +447,21 @@ runEmbeddedPostgres=1
init_postgres || runEmbeddedPostgres=0
}

setup_caddy() {
if [[ "$APPSMITH_RATE_LIMIT" == "disabled" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Quote the variable to prevent globbing and word splitting.

-  if [[ "$APPSMITH_RATE_LIMIT" == "disabled" ]]; then
+  if [[ "${APPSMITH_RATE_LIMIT}" == "disabled" ]]; 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 [[ "$APPSMITH_RATE_LIMIT" == "disabled" ]]; then
if [[ "${APPSMITH_RATE_LIMIT}" == "disabled" ]]; then

init_loading_pages(){
export XDG_DATA_HOME=/appsmith-stacks/data # so that caddy saves tls certs and other data under stacks/data/caddy
export XDG_CONFIG_HOME=/appsmith-stacks/configuration
mkdir -p "$XDG_DATA_HOME" "$XDG_CONFIG_HOME"
cp templates/loading.html "$WWW_PATH"
node caddy-reconfigure.mjs
/opt/caddy/caddy start --config "$TMP/Caddyfile"
"$_APPSMITH_CADDY" start --config "$TMP/Caddyfile"
Copy link
Contributor

Choose a reason for hiding this comment

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

Quote the command to prevent globbing and word splitting.

-  "$_APPSMITH_CADDY" start --config "$TMP/Caddyfile"
+  "${_APPSMITH_CADDY}" start --config "$TMP/Caddyfile"

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
"$_APPSMITH_CADDY" start --config "$TMP/Caddyfile"
"${_APPSMITH_CADDY}" start --config "$TMP/Caddyfile"

Copy link
Member

Choose a reason for hiding this comment

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

Line 190 and 191 are still using hard-coded Caddy. Can we change them to use the env variable please?

Can we also test with if the container built with changes in this PR, starts when all Docker capabilities are dropped please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea my bad. Sorry

sharat87
sharat87 previously approved these changes May 17, 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. Do you want to merge just the base.dockerfile first, let the base image be built, and then merge the rest of it? If yes, let me know and I'll pick just that file's changes and push to release.

@sharat87
Copy link
Member

@pratapaprasanna, also, can we ensure the "Semantic PR" check passes on PRs please? It checks that PR titles should start with feat: or fix: or chore: or test: or ci:. Having this correct helps us generate our release notes correctly. Like, entries with chore: or test: or ci: will be automatically removed from release notes. So if we don't want our PR to show up for users reading release notes, we use one of those that's most appropriate.

I'm fixing the title for this PR, please feel free to change if you disagree. Thanks!

@sharat87 sharat87 changed the title [feat]: make xcaddy configurable based on env chore: make xcaddy configurable based on env May 17, 2024
@sharat87 sharat87 changed the title chore: make xcaddy configurable based on env chore: Switch to vanilla Caddy, when rate limiting is disabled May 17, 2024
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label May 17, 2024
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

@@ -474,6 +482,7 @@ function capture_infra_details(){

# Main Section
print_appsmith_info
setup_caddy
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure setup_caddy is called before init_loading_pages to properly configure Caddy before starting it.

setup_caddy
init_loading_pages
print_appsmith_info
unset_unused_variables

This sequence ensures that the Caddy server is configured before any pages are loaded, which is crucial for proper application behavior.

Comment on lines +450 to +456
setup_caddy() {
if [[ "$APPSMITH_RATE_LIMIT" == "disabled" ]]; then
export _APPSMITH_CADDY="/opt/caddy/caddy_vanilla"
else
export _APPSMITH_CADDY="/opt/caddy/caddy"
fi
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure consistent environment variable naming.

-  if [[ "$APPSMITH_RATE_LIMIT" == "disabled" ]]; then
+  if [[ "${APPSMITH_RATE_LIMIT}" == "disabled" ]]; then

This change ensures that the variable is properly quoted to prevent globbing and word splitting, aligning with best practices in shell scripting.


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
setup_caddy() {
if [[ "$APPSMITH_RATE_LIMIT" == "disabled" ]]; then
export _APPSMITH_CADDY="/opt/caddy/caddy_vanilla"
else
export _APPSMITH_CADDY="/opt/caddy/caddy"
fi
}
setup_caddy() {
if [[ "${APPSMITH_RATE_LIMIT}" == "disabled" ]]; then
export _APPSMITH_CADDY="/opt/caddy/caddy_vanilla"
else
export _APPSMITH_CADDY="/opt/caddy/caddy"
fi
}

@github-actions github-actions bot added Bug Something isn't working Community Reported issues reported by community members DevOps Pod Issues related to devops K8s Kubernetes related issues Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage Production and removed Bug Something isn't working labels May 24, 2024
@pratapaprasanna pratapaprasanna merged commit bf05e0f into release May 24, 2024
17 checks passed
@pratapaprasanna pratapaprasanna deleted the make/xcaddy/configurable branch May 24, 2024 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Reported issues reported by community members DevOps Pod Issues related to devops K8s Kubernetes related issues Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage Production skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]:Operation not permitted Error When Starting Instance on Kubernetes
2 participants