diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ac8c0d4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,35 @@ +name: CI + +on: + pull_request: + branches: + - "*" + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}-ci + cancel-in-progress: true + +jobs: + build: + name: Build + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v1 + + - name: Print version info + id: semver + run: | + make version + + - name: Set up QEMU + id: qemu + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build + run: | + make container \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 91e1d6b..dfeb90f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,7 @@ LABEL org.opencontainers.image.source https://github.com/kubedb/mysql-init-docke RUN apk add --no-cache bash COPY scripts /tmp/scripts +RUN chmod +x /tmp/scripts/*.sh COPY init-script /init-script COPY --from=0 /tini /tmp/scripts/tini diff --git a/init-script/run.sh b/init-script/run.sh index 43b1dbf..a9b062e 100755 --- a/init-script/run.sh +++ b/init-script/run.sh @@ -3,3 +3,9 @@ rm -rf /var/lib/mysql/lost+found rm -rf /run-scripts/* cp /tmp/scripts/* /scripts +if [[ "$PITR_RESTORE" == "true" ]]; then + if [[ "$HOSTNAME" != *"-0" ]]; then + rm /var/lib/mysql/auto.cnf + fi +fi + diff --git a/scripts/copy-data.sh b/scripts/copy-data.sh new file mode 100755 index 0000000..c121f98 --- /dev/null +++ b/scripts/copy-data.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +ROOT_DIR="$ROOT_DIR" +TOTAL_DIR_TO_COPY="$TOTAL_DIR_TO_COPY" +DATA_DIR="$DATA_DIR" + +if [ -z "$ROOT_DIR" ] || [ -z "$TOTAL_DIR_TO_COPY" ]; then + echo "ROOT_DIR and TOTAL_DIR_TO_COPY must be set." + exit 1 +fi +Size1=$(du -s "$ROOT_DIR" | cut -f1) +echo "DATA DIRECTORY SIZE: ", $Size1 +for (( i = 1; i <= $TOTAL_DIR_TO_COPY; i++ ));do + if [[ -d "$ROOT_DIR$i" ]];then + Size2=$(du -s "$ROOT_DIR$i" | cut -f1) + echo $Size1, " ", $Size2 + if [[ "$Size1" == "$Size2" ]];then + continue + fi + fi + # not deleting any data + # because the sole purpose of this script is to copy the data + # rm -rf "$ROOT_DIR$i"/* + rm "$ROOT_DIR/mysql.sock" + cp -rvL "$ROOT_DIR/"* "$ROOT_DIR$i"/ + if [[ $? -ne 0 ]]; then + echo "Error occurred while copying to $ROOT_DIR$i" + exit 1 + fi +done + +exit 0 \ No newline at end of file diff --git a/scripts/directory-exist.sh b/scripts/directory-exist.sh new file mode 100755 index 0000000..7a5ace0 --- /dev/null +++ b/scripts/directory-exist.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +file="/var/lib/mysql/join-in-cluster" + +if [ -e "$file" ]; then + echo -n "Not Empty" +else + echo -n "Empty" +fi \ No newline at end of file diff --git a/scripts/run.sh b/scripts/run.sh index 3155a5f..3a7b9b8 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -13,8 +13,24 @@ # HOST_ADDRESS_TYPE = Address type of HOST_ADDRESS (one of DNS, IPV4, IPv6) # POD_IP = IP address used to create whitelist CIDR. For HOST_ADDRESS_TYPE=DNS, it will be status.PodIP. # POD_IP_TYPE = Address type of POD_IP (one of IPV4, IPv6) +# PRIMARY_TYPE = defines single/multi primary env | sort | grep "POD\|HOST\|NAME" +RECOVERY_DONE_FILE="/tmp/recovery.done" +if [[ "$PITR_RESTORE" == "true" ]]; then + while true; do + sleep 2 + echo "Point In Time Recovery In Progress. Waiting for $RECOVERY_DONE_FILE file" + if [[ -e "$RECOVERY_DONE_FILE" ]]; then + echo "$RECOVERY_DONE_FILE found." + break + fi + done +fi + +if [[ -e "$RECOVERY_DONE_FILE" ]]; then + rm $RECOVERY_DONE_FILE +fi args=$@ script_name=${0##*/} @@ -104,6 +120,48 @@ mkdir -p /etc/mysql/group-replication.conf.d/ echo "!includedir /etc/mysql/group-replication.conf.d/" >>/etc/mysql/my.cnf mkdir -p /etc/mysql/conf.d/ echo "!includedir /etc/mysql/conf.d/" >>/etc/mysql/my.cnf +if [[ "$PRIMARY_TYPE" == "Multi-Primary" ]]; then +cat >>/etc/mysql/group-replication.conf.d/group.cnf <>/etc/mysql/group-replication.conf.d/group.cnf <>/etc/mysql/my.cnf <