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 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 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..2177c89 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", "true"] + interval: 5s + timeout: 1s + retries: 1 + start_period: 15s 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", "true"] + interval: 5s + timeout: 1s + retries: 1 + start_period: 15s mariadb_db: image: mariadb:11.5.2 @@ -43,15 +55,31 @@ services: - 9307:3306 volumes: - ./test_mariadb.cnf:/etc/mysql/my.cnf:ro # Adjust path to MariaDB config location if needed + healthcheck: + test: ["CMD", "true"] + interval: 5s + timeout: 1s + retries: 1 + start_period: 15s 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/ + depends_on: + clickhouse_db: + condition: service_healthy + mysql_db: + condition: service_healthy + mariadb_db: + condition: service_healthy