Fix replication settings

sh don't know 'echo -e', so we use bash instead.
Also, we need to wait for the container to be healthy before trying to
restart it. Otherwise that could corrupt it.
This commit is contained in:
Laurent Indermuehle 2023-01-12 13:49:34 +01:00
parent 35531e741c
commit b9d0e96deb
No known key found for this signature in database
GPG key ID: 93FA944C9F34DD09
2 changed files with 20 additions and 8 deletions

View file

@ -130,18 +130,21 @@ jobs:
steps:
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
# No need to check for service health. GitHub Action took care of it.
- name: Restart MySQL server with settings for replication
run: |
docker exec ${{ job.services.db_primary.id }} sh -c 'echo -e [mysqld]\\nserver-id=1\\nlog-bin=/var/lib/mysql/primary-bin > /etc/mysql/conf.d/replication.cnf'
docker exec ${{ job.services.db_replica1.id }} sh -c 'echo -e [mysqld]\\nserver-id=2\\nlog-bin=/var/lib/mysql/replica1-bin > /etc/mysql/conf.d/replication.cnf'
docker exec ${{ job.services.db_replica2.id }} sh -c 'echo -e [mysqld]\\nserver-id=3\\nlog-bin=/var/lib/mysql/replica2-bin > /etc/mysql/conf.d/replication.cnf'
docker exec ${{ job.services.db_primary.id }} bash -c 'echo -e [mysqld]\\nserver-id=1\\nlog-bin=/var/lib/mysql/primary-bin > /etc/mysql/conf.d/replication.cnf'
docker exec ${{ job.services.db_replica1.id }} bash -c 'echo -e [mysqld]\\nserver-id=2\\nlog-bin=/var/lib/mysql/replica1-bin > /etc/mysql/conf.d/replication.cnf'
docker exec ${{ job.services.db_replica2.id }} bash -c 'echo -e [mysqld]\\nserver-id=3\\nlog-bin=/var/lib/mysql/replica2-bin > /etc/mysql/conf.d/replication.cnf'
docker restart ${{ job.services.db_primary.id }}
docker restart ${{ job.services.db_replica1.id }}
docker restart ${{ job.services.db_replica2.id }}
- name: Wait for the primary to be healthy
run: |
while ! /usr/bin/docker inspect --format="{{if .Config.Healthcheck}}{{print .State.Health.Status}}{{end}}" ${{ job.services.db_primary.id }} && [[ "$SECONDS" -lt 120 ]]; do sleep 1; done
- name: >-
Perform integration testing against
Ansible version ${{ matrix.ansible }}

View file

@ -11,7 +11,7 @@ test-integration:
--publish 3307:3306 \
--health-cmd 'mysqladmin ping -P 3306 -pmsandbox | grep alive || exit 1' \
$(db_engine_version) \
mysqld --server-id 1 --log-bin=/var/lib/mysql/primary-bin
mysqld
podman run \
--detach \
--name replica1 \
@ -21,7 +21,7 @@ test-integration:
--publish 3308:3306 \
--health-cmd 'mysqladmin ping -P 3306 -pmsandbox | grep alive || exit 1' \
$(db_engine_version) \
mysqld --server-id 2 --log-bin=/var/lib/mysql/replica1-bin
mysqld
podman run \
--detach \
--name replica2 \
@ -31,7 +31,16 @@ test-integration:
--publish 3309:3306 \
--health-cmd 'mysqladmin ping -P 3306 -pmsandbox | grep alive || exit 1' \
$(db_engine_version) \
mysqld --server-id 3 --log-bin=/var/lib/mysql/replica2-bin
mysqld
# Setup replication and restart containers
podman exec primary bash -c 'echo -e [mysqld]\\nserver-id=1\\nlog-bin=/var/lib/mysql/primary-bin > /etc/mysql/conf.d/replication.cnf'
podman exec replica1 bash -c 'echo -e [mysqld]\\nserver-id=2\\nlog-bin=/var/lib/mysql/replica1-bin > /etc/mysql/conf.d/replication.cnf'
podman exec replica2 bash -c 'echo -e [mysqld]\\nserver-id=3\\nlog-bin=/var/lib/mysql/replica2-bin > /etc/mysql/conf.d/replication.cnf'
# Don't restart a container unless it is healthy
while ! podman healthcheck run primary && [[ "$$SECONDS" -lt 120 ]]; do sleep 1; done
podman restart primary
podman restart replica1
podman restart replica2
while ! podman healthcheck run primary && [[ "$$SECONDS" -lt 120 ]]; do sleep 1; done
-set -x; ansible-test integration $(target) -v --color --coverage --retry-on-error --continue-on-error --diff --docker --docker-network podman --python $(python); set +x
rm tests/integration/db_engine_version