Modify MySQL healthcheck to wait for script completion. Updated the d…#570
Modify MySQL healthcheck to wait for script completion. Updated the d…#570savemyfiles wants to merge 4 commits intowso2:masterfrom
Conversation
…ocker-compose healthcheck for MySQL to ensure dependent services like IS-AS-KM start only after the database initialization scripts have completed.
WalkthroughMySQL healthchecks in three docker-compose files now require successful Changes
Sequence Diagram(s)(omitted — changes are confined to container healthchecks and do not introduce multi-component control flow requiring a sequence diagram) Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| command: [--ssl=0] | ||
| healthcheck: | ||
| test: ["CMD", "sh", "-c", "mysqladmin ping -uroot -proot && [ -f /var/lib/mysql/initialization-complete.flag ]"] | ||
| test: ["CMD", "mysql", "-h", "localhost", "-uroot", "-proot", "-D", "WSO2AM_SHARED_DB", "-e", "SELECT 1 FROM UM_ORG LIMIT 1;"] |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's explore the structure and find the initialization scripts
find . -type f -name "docker-compose*.yml" | head -20Repository: wso2/docker-apim
Length of output: 229
🏁 Script executed:
# Find SQL and shell scripts in the conf directory
fd -e sql -e sh . ./conf --max-results 20Repository: wso2/docker-apim
Length of output: 153
🏁 Script executed:
# Check if the conf/mysql/scripts directory exists and what's in it
ls -la docker-compose/apim-is-as-km-with-analytics/conf/mysql/scripts 2>/dev/null || echo "Path not found, searching..."
find . -path "*conf/mysql/scripts*" -type fRepository: wso2/docker-apim
Length of output: 1039
🏁 Script executed:
# Examine the mysql_shared.sql file to see if WSO2AM_SHARED_DB and UM_ORG are created
cat "./docker-compose/apim-is-as-km-with-analytics/conf/mysql/scripts/mysql_shared.sql" | head -100Repository: wso2/docker-apim
Length of output: 4978
🏁 Script executed:
# Check the z_health_check.sh script
cat "./docker-compose/apim-is-as-km-with-analytics/conf/mysql/scripts/z_health_check.sh"Repository: wso2/docker-apim
Length of output: 924
🏁 Script executed:
# Search for initialization-complete.flag references
rg -n "initialization-complete.flag" 2>/dev/null || echo "No matches found"Repository: wso2/docker-apim
Length of output: 781
🏁 Script executed:
# Check if the docker-compose.yml file has the healthcheck at line 32
sed -n '25,40p' "./docker-compose/apim-is-as-km-with-analytics/docker-compose.yml"Repository: wso2/docker-apim
Length of output: 599
🏁 Script executed:
# Search for UM_ORG table in the SQL files
rg -n "UM_ORG" ./docker-compose/apim-is-as-km-with-analytics/conf/mysql/scripts/Repository: wso2/docker-apim
Length of output: 4160
🏁 Script executed:
# Check the full mysql_shared.sql file to see where UM_ORG is created (if at all)
wc -l ./docker-compose/apim-is-as-km-with-analytics/conf/mysql/scripts/mysql_shared.sqlRepository: wso2/docker-apim
Length of output: 145
🏁 Script executed:
# Search for UM_ORG in ALL SQL files across all docker-compose directories
rg -n "UM_ORG" --type sqlRepository: wso2/docker-apim
Length of output: 11556
🏁 Script executed:
# Check if z_health_check.sh is mounted in the reviewed docker-compose file
sed -n '15,35p' "./docker-compose/apim-is-as-km-with-analytics/docker-compose.yml"Repository: wso2/docker-apim
Length of output: 620
🏁 Script executed:
# Check the mysql service volumes section in the reviewed file
rg -n "volumes:" -A 10 "./docker-compose/apim-is-as-km-with-analytics/docker-compose.yml" | grep -E "^[0-9]+:" | head -30Repository: wso2/docker-apim
Length of output: 107
🏁 Script executed:
# Compare all three docker-compose files' mysql healthcheck sections
echo "=== apim-is-as-km-with-analytics ===" && \
sed -n '32p' "./docker-compose/apim-is-as-km-with-analytics/docker-compose.yml" && \
echo "=== apim-with-analytics ===" && \
sed -n '32p' "./docker-compose/apim-with-analytics/docker-compose.yml" && \
echo "=== apim-with-mi ===" && \
sed -n '32p' "./docker-compose/apim-with-mi/docker-compose.yml"Repository: wso2/docker-apim
Length of output: 516
Inconsistent healthcheck implementation across docker-compose files.
The new SQL-based healthcheck in this file differs from the other docker-compose configurations, which still use mysqladmin ping && [ -f /var/lib/mysql/initialization-complete.flag ]. This creates maintenance burden and potential confusion.
Additionally, z_health_check.sh still exists and creates /var/lib/mysql/initialization-complete.flag as the final initialization step (the z_ prefix ensures it runs last), but this flag is no longer checked by the healthcheck. Either:
- Update all docker-compose files (apim-with-analytics, apim-with-mi) to use the SQL query approach, or
- Keep the flag-based approach consistently across all setups and remove the SQL query healthcheck
The z_health_check.sh script should not create an unused flag file.
…ation-complete.flag
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Fix all issues with AI agents
In @docker-compose/apim-is-as-km-with-analytics/docker-compose.yml:
- Line 32: The healthcheck block currently has the `test` and `interval` on the
same line causing a YAML syntax error; update the `healthcheck` entry so that
`test:` remains a single key (with its array value) and `interval:` is moved to
its own line indented at the same level as `test:` (e.g., under `healthcheck:`
alongside `test:`) so `test` and `interval` are separate keys; ensure
indentation matches other healthcheck keys (like `retries` or `timeout`) to
restore valid docker-compose YAML.
In @docker-compose/apim-with-analytics/docker-compose.yml:
- Line 32: The YAML has a syntax error because the healthcheck `test` array and
the `interval` key are on the same line; in the `healthcheck` block split
`test:` and `interval:` onto separate lines with `interval:` indented at the
same level as `test:` (e.g., under `healthcheck`), keeping the existing `["CMD",
"sh", "-c", "mysqladmin ping -uroot -proot && [ -f
/var/lib/mysql/initialization-complete.flag ] && mysql -h localhost -uroot
-proot -D WSO2AM_SHARED_DB -e 'SELECT 1 FROM UM_ORG LIMIT 1;'"]` value for
`test` and placing `interval: 30s` on its own line beneath it so the YAML parses
correctly.
In @docker-compose/apim-with-mi/docker-compose.yml:
- Line 32: The healthcheck in docker-compose.yml has `test` and `interval` on
the same line causing a YAML syntax error; edit the `healthcheck` block so
`test:` remains as the array value (the current ["CMD", "sh", "-c", "..."]) and
move `interval:` onto its own line with the same indentation level as `test`
(e.g., under `healthcheck`), ensuring `interval: 30s` is a separate mapping
entry; verify the block uses proper YAML indentation so `test` and `interval`
are sibling keys within `healthcheck`.
- Around line 32-33: The healthcheck block defines the same key twice: remove
the duplicate "interval" entry so only a single "interval" exists under the
healthcheck for the service that contains the "test" command (the healthcheck
with test ["CMD", "sh", "-c", "mysqladmin ping -uroot -proot && [ -f
/var/lib/mysql/initialization-complete.flag ] && mysql -h localhost -uroot
-proot -D WSO2AM_SHARED_DB -e 'SELECT 1 FROM UM_ORG LIMIT 1;'"]). Ensure you
keep one "interval" line (the correct value) and delete the other to avoid YAML
parsing errors.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
docker-compose/apim-is-as-km-with-analytics/docker-compose.ymldocker-compose/apim-with-analytics/docker-compose.ymldocker-compose/apim-with-mi/docker-compose.yml
🧰 Additional context used
🪛 YAMLlint (1.37.1)
docker-compose/apim-with-mi/docker-compose.yml
[error] 32-32: syntax error: expected , but found ''
(syntax)
docker-compose/apim-with-analytics/docker-compose.yml
[error] 32-32: syntax error: expected , but found ''
(syntax)
docker-compose/apim-is-as-km-with-analytics/docker-compose.yml
[error] 32-32: syntax error: expected , but found ''
(syntax)
🔇 Additional comments (3)
docker-compose/apim-is-as-km-with-analytics/docker-compose.yml (1)
32-32: The healthcheck is correctly implemented.The
UM_ORGtable is created and populated in themysql_shared.sqlinitialization script. The table is defined with proper schema and includes an initial 'Super' organization record, ensuring theSELECT 1 FROM UM_ORG LIMIT 1;query will succeed once initialization completes.docker-compose/apim-with-mi/docker-compose.yml (1)
32-32: TheUM_ORGtable is correctly created during initialization.Confirmed: The initialization script
docker-compose/apim-with-mi/conf/mysql/scripts/mysql_shared.sqlcreates theUM_ORGtable withCREATE TABLE IF NOT EXISTS UM_ORG, along with initial data (Super organization). The healthcheck properly waits for the/var/lib/mysql/initialization-complete.flagbefore running the SELECT query, ensuring the table exists before dependent services start.docker-compose/apim-with-analytics/docker-compose.yml (1)
32-32: Verify that the UM_ORG table exists after initialization.The healthcheck queries
SELECT 1 FROM UM_ORG LIMIT 1;from theWSO2AM_SHARED_DBdatabase. The initialization script at./conf/mysql/scripts/mysql_shared.sqlcreates this table withCREATE TABLE IF NOT EXISTS UM_ORG (...)and populates it with initial data. Theapi-managerservice will not start until the MySQL healthcheck passes, ensuring the table exists before dependent services attempt to connect.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @docker-compose/apim-is-as-km-with-analytics/docker-compose.yml:
- Around line 33-34: The mysql service healthcheck contains a duplicate key
"interval: 30s"; remove the redundant entry so the healthcheck block for the
mysql service only declares interval once (locate the mysql service's
healthcheck section in the docker-compose.yml and delete the extra "interval:
30s" line).
🧹 Nitpick comments (2)
docker-compose/apim-with-analytics/docker-compose.yml (1)
31-33: Harden the MySQL healthcheck (timeouts + reduce password exposure) and verifyUM_ORGis always present.The new query check is directionally good for “init scripts completed”, but it can (a) hang longer than needed without client connect timeouts, and (b) fail forever if
UM_ORGisn’t guaranteed for the targeted product/version/profile. Also,-prootleaks in process listings.Proposed update
healthcheck: - test: ["CMD", "sh", "-c", "mysqladmin ping -uroot -proot && [ -f /var/lib/mysql/initialization-complete.flag ] && mysql -h localhost -uroot -proot -D WSO2AM_SHARED_DB -e 'SELECT 1 FROM UM_ORG LIMIT 1;'"] + test: ["CMD", "sh", "-c", "MYSQL_PWD=$$MYSQL_ROOT_PASSWORD mysqladmin ping -uroot --silent --connect-timeout=5 && [ -f /var/lib/mysql/initialization-complete.flag ] && MYSQL_PWD=$$MYSQL_ROOT_PASSWORD mysql -h localhost -uroot --connect-timeout=5 -D WSO2AM_SHARED_DB -e 'SELECT 1 FROM UM_ORG LIMIT 1;'"] interval: 30sdocker-compose/apim-is-as-km-with-analytics/docker-compose.yml (1)
31-33: Same healthcheck hardening concerns as the other compose file (timeouts/password) + validateUM_ORGassumption.Consider the same
MYSQL_PWD+--connect-timeoutadjustments here as well (see suggested diff in the other file’s comment) to avoid long hangs and reduce password exposure, and confirmUM_ORGis always created by the init scripts for the versions/profiles you ship.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
docker-compose/apim-is-as-km-with-analytics/docker-compose.ymldocker-compose/apim-with-analytics/docker-compose.ymldocker-compose/apim-with-mi/docker-compose.yml
🚧 Files skipped from review as they are similar to previous changes (1)
- docker-compose/apim-with-mi/docker-compose.yml
…ocker-compose healthcheck for MySQL to ensure dependent services like IS-AS-KM start only after the database initialization scripts have completed.
Purpose
Goals
Approach
User stories
Release note
Documentation
Training
Certification
Marketing
Automation tests
Security checks
Samples
Related PRs
Migrations (if applicable)
Test environment
Learning
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.