Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(ci): wait for mysql to accept queries before db migration (#35631)

L1nSn0wb8dea561989a
diff --git a/.github/workflows/db-migration-test.yml b/.github/workflows/db-migration-test.yml
index b1ccf496df8..65f0149a74a 100644
--- a/.github/workflows/db-migration-test.yml
+++ b/.github/workflows/db-migration-test.yml
@@ -110,6 +110,28 @@ jobs:
sed -i 's/DB_PORT=5432/DB_PORT=3306/' .env
sed -i 's/DB_USERNAME=postgres/DB_USERNAME=root/' .env
+ # hoverkraft-tech/[email protected] only waits for `docker compose up -d`
+ # to return (container processes started); it does not wait on healthcheck
+ # status. mysql:8.0's first-time init takes 15-30s, so without an explicit
+ # wait the migration runs while InnoDB is still initialising and gets
+ # killed with "Lost connection during query". Poll a real SELECT until it
+ # succeeds.
+ - name: Wait for MySQL to accept queries
+ run: |
+ set +e
+ for i in $(seq 1 60); do
+ if docker run --rm --network host mysql:8.0 \
+ mysql -h 127.0.0.1 -P 3306 -uroot -pdifyai123456 \
+ -e 'SELECT 1' >/dev/null 2>&1; then
+ echo "MySQL ready after ${i}s"
+ exit 0
+ fi
+ sleep 1
+ done
+ echo "MySQL not ready after 60s; dumping container logs:"
+ docker compose -f docker/docker-compose.middleware.yaml --profile mysql logs --tail=200 db_mysql
+ exit 1
+
- name: Run DB Migration
env:
DEBUG: true
diff --git a/docker/docker-compose.middleware.yaml b/docker/docker-compose.middleware.yaml
index 911da70a737..af3d54dfb32 100644
--- a/docker/docker-compose.middleware.yaml
+++ b/docker/docker-compose.middleware.yaml
@@ -59,19 +59,25 @@ services:
- ${MYSQL_HOST_VOLUME:-./volumes/mysql/data}:/var/lib/mysql
ports:
- "${EXPOSE_MYSQL_PORT:-3306}:3306"
+ # mysqladmin ping passes during mysql:8.0's TCP-listening stage even while
+ # the server is still finalising init, leading to "Lost connection during
+ # query" on the first real query. Verify with a real SELECT instead.
healthcheck:
test:
[
"CMD",
- "mysqladmin",
- "ping",
- "-u",
- "root",
+ "mysql",
+ "-h",
+ "127.0.0.1",
+ "-uroot",
"-p${DB_PASSWORD:-difyai123456}",
+ "-e",
+ "SELECT 1",
]
interval: 1s
timeout: 3s
retries: 30
+ start_period: 20s
# The redis cache.
redis: