From 39bed57a948e0ce5688585d2d601f8d039b2f34e Mon Sep 17 00:00:00 2001 From: Filipp Ozinov Date: Thu, 27 Mar 2025 23:19:32 +0400 Subject: [PATCH 1/9] Created a dockerfile for it --- Dockerfile | 25 +++++++++++++++++++++++++ docker-compose-tests.yaml | 13 ++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7f6376a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM python:3.12.4-slim-bookworm + +WORKDIR /app + +# Copy requirements files +COPY requirements.txt requirements-dev.txt ./ + +# Install dependencies +RUN pip install --no-cache-dir -r requirements.txt \ + && pip install --no-cache-dir -r requirements-dev.txt + +# Copy the application +COPY . . + +# Create directory for binlog data +RUN mkdir -p /app/binlog + +# Make the main script executable +RUN chmod +x /app/main.py + +# Set the entrypoint to the main script +ENTRYPOINT ["/app/main.py"] + +# Default command (can be overridden in docker-compose) +CMD ["--help"] diff --git a/docker-compose-tests.yaml b/docker-compose-tests.yaml index 77d996f..4d680fe 100644 --- a/docker-compose-tests.yaml +++ b/docker-compose-tests.yaml @@ -45,13 +45,16 @@ services: - ./test_mariadb.cnf:/etc/mysql/my.cnf:ro # Adjust path to MariaDB config location if needed replicator: - image: python:3.12.4-slim-bookworm - command: bash -c "pip install -r /app/requirements.txt && pip install -r /app/requirements-dev.txt && touch /tmp/ready && tail -f /dev/null" + build: + context: . + dockerfile: Dockerfile + network_mode: host + volumes: + - ./:/app/ + entrypoint: ["/bin/bash"] + command: ["-c", "touch /tmp/ready && tail -f /dev/null"] healthcheck: test: [ 'CMD-SHELL', 'test -f /tmp/ready' ] interval: 2s retries: 100 start_period: 10s - network_mode: host - volumes: - - ./:/app/ From e4682e6700e19abe7e1687799a3786d74d1aacb9 Mon Sep 17 00:00:00 2001 From: Filipp Ozinov Date: Thu, 27 Mar 2025 23:27:34 +0400 Subject: [PATCH 2/9] Publish to dockerhub --- .github/workflows/release.yaml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 1943bce..7a99f81 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,4 +1,4 @@ -name: Publish to PyPI +name: Publish to PyPI and Docker Hub on: push: @@ -42,3 +42,23 @@ jobs: run: | poetry build poetry publish + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: | + ${{ secrets.DOCKERHUB_USERNAME }}/mysql-ch-replicator:latest + ${{ secrets.DOCKERHUB_USERNAME }}/mysql-ch-replicator:${{ env.version }} + cache-from: type=gha + cache-to: type=gha,mode=max From 4f0d6058a8378dc9fa25e6e097c8b247cb3aa65b Mon Sep 17 00:00:00 2001 From: Filipp Ozinov Date: Thu, 27 Mar 2025 23:31:23 +0400 Subject: [PATCH 3/9] Try fix tests --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 9fb7c22..e676ba2 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -17,4 +17,4 @@ jobs: run: > ls -la && docker compose -f docker-compose-tests.yaml up --force-recreate --no-deps --wait -d && - sudo docker exec -w /app/ -i `docker ps | grep python | awk '{print $1;}'` python3 -m pytest -x -v -s test_mysql_ch_replicator.py + sudo docker exec -w /app/ -i `docker ps | grep mysql_ch_replicator-replicator | awk '{print $1;}'` python3 -m pytest -x -v -s test_mysql_ch_replicator.py From cd7721f0ba248f854026fa14bfa277a7579c60f9 Mon Sep 17 00:00:00 2001 From: Filipp Ozinov Date: Thu, 27 Mar 2025 23:38:50 +0400 Subject: [PATCH 4/9] Try to fix tests --- docker-compose-tests.yaml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docker-compose-tests.yaml b/docker-compose-tests.yaml index 4d680fe..6fa4033 100644 --- a/docker-compose-tests.yaml +++ b/docker-compose-tests.yaml @@ -17,6 +17,12 @@ services: - 9123:9123 volumes: - ./tests_override.xml:/bitnami/clickhouse/etc/conf.d/override.xml:ro + healthcheck: + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:9123/ping"] + interval: 5s + timeout: 3s + retries: 5 + start_period: 10s mysql_db: image: mysql:8.4.3 @@ -30,6 +36,12 @@ services: - ./test_mysql.cnf:/etc/mysql/my.cnf:ro networks: - default + healthcheck: + test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p$$MYSQL_ROOT_PASSWORD"] + interval: 5s + timeout: 3s + retries: 5 + start_period: 10s mariadb_db: image: mariadb:11.5.2 @@ -43,6 +55,12 @@ services: - 9307:3306 volumes: - ./test_mariadb.cnf:/etc/mysql/my.cnf:ro # Adjust path to MariaDB config location if needed + healthcheck: + test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p$$MARIADB_ROOT_PASSWORD"] + interval: 5s + timeout: 3s + retries: 5 + start_period: 10s replicator: build: @@ -58,3 +76,10 @@ services: interval: 2s retries: 100 start_period: 10s + depends_on: + clickhouse_db: + condition: service_healthy + mysql_db: + condition: service_healthy + mariadb_db: + condition: service_healthy From 792ed2c776b457d95f0831777c28311d66821bd8 Mon Sep 17 00:00:00 2001 From: Filipp Ozinov Date: Thu, 27 Mar 2025 23:40:53 +0400 Subject: [PATCH 5/9] Try to fix tests --- docker-compose-tests.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose-tests.yaml b/docker-compose-tests.yaml index 6fa4033..0e9eb86 100644 --- a/docker-compose-tests.yaml +++ b/docker-compose-tests.yaml @@ -18,7 +18,7 @@ services: volumes: - ./tests_override.xml:/bitnami/clickhouse/etc/conf.d/override.xml:ro healthcheck: - test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:9123/ping"] + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://default:admin@localhost:9123/ping"] interval: 5s timeout: 3s retries: 5 @@ -37,7 +37,7 @@ services: networks: - default healthcheck: - test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p$$MYSQL_ROOT_PASSWORD"] + test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-padmin"] interval: 5s timeout: 3s retries: 5 @@ -56,7 +56,7 @@ services: volumes: - ./test_mariadb.cnf:/etc/mysql/my.cnf:ro # Adjust path to MariaDB config location if needed healthcheck: - test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p$$MARIADB_ROOT_PASSWORD"] + test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-padmin"] interval: 5s timeout: 3s retries: 5 From 0df1cc06eaf2ac5cfc2c446ea3cbf2e79656d73f Mon Sep 17 00:00:00 2001 From: Filipp Ozinov Date: Thu, 27 Mar 2025 23:45:10 +0400 Subject: [PATCH 6/9] Try to fix tests --- docker-compose-tests.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose-tests.yaml b/docker-compose-tests.yaml index 0e9eb86..11598f4 100644 --- a/docker-compose-tests.yaml +++ b/docker-compose-tests.yaml @@ -18,7 +18,7 @@ services: volumes: - ./tests_override.xml:/bitnami/clickhouse/etc/conf.d/override.xml:ro healthcheck: - test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://default:admin@localhost:9123/ping"] + test: ["CMD-SHELL", "curl -s -f http://localhost:9123/ping || exit 1"] interval: 5s timeout: 3s retries: 5 @@ -37,7 +37,7 @@ services: networks: - default healthcheck: - test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-padmin"] + test: ["CMD-SHELL", "mysql -h localhost -u root -padmin -e 'SELECT 1' || exit 1"] interval: 5s timeout: 3s retries: 5 @@ -56,7 +56,7 @@ services: volumes: - ./test_mariadb.cnf:/etc/mysql/my.cnf:ro # Adjust path to MariaDB config location if needed healthcheck: - test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-padmin"] + test: ["CMD-SHELL", "mysql -h localhost -u root -padmin -e 'SELECT 1' || exit 1"] interval: 5s timeout: 3s retries: 5 From 18664db1ec8dfae381752422b38489e2ca4f8c9d Mon Sep 17 00:00:00 2001 From: Filipp Ozinov Date: Thu, 27 Mar 2025 23:47:49 +0400 Subject: [PATCH 7/9] Try to fix tests --- docker-compose-tests.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose-tests.yaml b/docker-compose-tests.yaml index 11598f4..f42a214 100644 --- a/docker-compose-tests.yaml +++ b/docker-compose-tests.yaml @@ -18,7 +18,7 @@ services: volumes: - ./tests_override.xml:/bitnami/clickhouse/etc/conf.d/override.xml:ro healthcheck: - test: ["CMD-SHELL", "curl -s -f http://localhost:9123/ping || exit 1"] + test: ["CMD-SHELL", "nc -z localhost 9123 || exit 1"] interval: 5s timeout: 3s retries: 5 @@ -37,7 +37,7 @@ services: networks: - default healthcheck: - test: ["CMD-SHELL", "mysql -h localhost -u root -padmin -e 'SELECT 1' || exit 1"] + test: ["CMD-SHELL", "nc -z localhost 3306 || exit 1"] interval: 5s timeout: 3s retries: 5 @@ -56,7 +56,7 @@ services: volumes: - ./test_mariadb.cnf:/etc/mysql/my.cnf:ro # Adjust path to MariaDB config location if needed healthcheck: - test: ["CMD-SHELL", "mysql -h localhost -u root -padmin -e 'SELECT 1' || exit 1"] + test: ["CMD-SHELL", "nc -z localhost 3306 || exit 1"] interval: 5s timeout: 3s retries: 5 From fe01317a93c85d0c032caae85f228a1ea1f06963 Mon Sep 17 00:00:00 2001 From: Filipp Ozinov Date: Thu, 27 Mar 2025 23:50:20 +0400 Subject: [PATCH 8/9] Try to fix tests --- docker-compose-tests.yaml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/docker-compose-tests.yaml b/docker-compose-tests.yaml index f42a214..6ee880b 100644 --- a/docker-compose-tests.yaml +++ b/docker-compose-tests.yaml @@ -18,11 +18,11 @@ services: volumes: - ./tests_override.xml:/bitnami/clickhouse/etc/conf.d/override.xml:ro healthcheck: - test: ["CMD-SHELL", "nc -z localhost 9123 || exit 1"] - interval: 5s - timeout: 3s - retries: 5 - start_period: 10s + test: ["CMD-SHELL", "sleep 15"] + interval: 15s + timeout: 1s + retries: 1 + start_period: 0s mysql_db: image: mysql:8.4.3 @@ -37,11 +37,11 @@ services: networks: - default healthcheck: - test: ["CMD-SHELL", "nc -z localhost 3306 || exit 1"] - interval: 5s - timeout: 3s - retries: 5 - start_period: 10s + test: ["CMD-SHELL", "sleep 15"] + interval: 15s + timeout: 1s + retries: 1 + start_period: 0s mariadb_db: image: mariadb:11.5.2 @@ -56,11 +56,11 @@ services: volumes: - ./test_mariadb.cnf:/etc/mysql/my.cnf:ro # Adjust path to MariaDB config location if needed healthcheck: - test: ["CMD-SHELL", "nc -z localhost 3306 || exit 1"] - interval: 5s - timeout: 3s - retries: 5 - start_period: 10s + test: ["CMD-SHELL", "sleep 15"] + interval: 15s + timeout: 1s + retries: 1 + start_period: 0s replicator: build: From 2aa93d012fc63a4d98e5ce8359157a2c84c9c2ce Mon Sep 17 00:00:00 2001 From: Filipp Ozinov Date: Thu, 27 Mar 2025 23:52:18 +0400 Subject: [PATCH 9/9] Try to fix tests --- docker-compose-tests.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docker-compose-tests.yaml b/docker-compose-tests.yaml index 6ee880b..2177c89 100644 --- a/docker-compose-tests.yaml +++ b/docker-compose-tests.yaml @@ -18,11 +18,11 @@ services: volumes: - ./tests_override.xml:/bitnami/clickhouse/etc/conf.d/override.xml:ro healthcheck: - test: ["CMD-SHELL", "sleep 15"] - interval: 15s + test: ["CMD", "true"] + interval: 5s timeout: 1s retries: 1 - start_period: 0s + start_period: 15s mysql_db: image: mysql:8.4.3 @@ -37,11 +37,11 @@ services: networks: - default healthcheck: - test: ["CMD-SHELL", "sleep 15"] - interval: 15s + test: ["CMD", "true"] + interval: 5s timeout: 1s retries: 1 - start_period: 0s + start_period: 15s mariadb_db: image: mariadb:11.5.2 @@ -56,11 +56,11 @@ services: volumes: - ./test_mariadb.cnf:/etc/mysql/my.cnf:ro # Adjust path to MariaDB config location if needed healthcheck: - test: ["CMD-SHELL", "sleep 15"] - interval: 15s + test: ["CMD", "true"] + interval: 5s timeout: 1s retries: 1 - start_period: 0s + start_period: 15s replicator: build: