From 78939c09bcaf4e1ffc2e9c347595b55dc687fe0e Mon Sep 17 00:00:00 2001 From: Marios Orphanou Date: Fri, 14 Mar 2025 17:14:10 +0200 Subject: [PATCH 1/3] Running XDCR --- .dockerignore | 10 ++++++++++ Dockerfile | 45 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 29 ++++++++++++++++++++++++++++ runDiffer.sh | 17 ++++++++++------- xdcr-differ-pod.yaml | 12 ++++++++++++ 5 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 xdcr-differ-pod.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a0d0c78 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.DS_Store +.project +fileDiff/ +mutationDiff/ +source/ +target/ +xdcrDiffer +go.mod +go.sum +xdcrDiffer.log \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ebcdabc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +ARG BUILDER_IMAGE=docker-registry-proxy.corp.amdocs.com/golang:1.24 + +ARG FINAL_IMAGE=docker-registry-proxy.corp.amdocs.com/redhat/ubi9:9.5 + +ARG http_proxy +ARG https_proxy +ARG no_proxy + + +FROM $BUILDER_IMAGE as builder + +ENV http_proxy=${http_proxy} +ENV https_proxy=${https_proxy} +ENV no_proxy=${no_proxy} + + +ENV LANG=en_US.utf8 +ENV LC_ALL=en_US.utf8 + +ARG TARGETARCH +ARG TARGETOS + +ENV GOOS=$TARGETOS +ENV GOARCH=$TARGETARCH +ENV CGO_ENABLED=0 + +COPY . . + +RUN make all + +RUN echo "xdcrdiffer:x:10001:10001::/:/xdcrDiffer" > /passwd + +RUN go build -ldflags='-s -w -extldflags "-static"' -v \ + -o xdcrDiffer main.go + +RUN chmod +x ./runDiffer.sh + +FROM $FINAL_IMAGE as final + +COPY --from=builder /go/xdcrDiffer / +COPY --from=builder /go/runDiffer.sh / +COPY --from=builder /passwd /etc/passwd + +USER xdcrdiffer +ENTRYPOINT ["/runDiffer.sh"] diff --git a/README.md b/README.md index 3cb6991..35f798f 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ If an XDCR is ongoing, it is quite possible that the tool will show documents as - [Getting Started](#getting-started) * [Prerequisites](#prerequisites) * [Compiling](#compiling) + * [Building with Docker](#building-with-docker) + + [Multiple platform using docker buildx](#multiple-platform-using-docker-buildx) * [Running](#running) + [Preparing Couchbase Clusters](#preparing-couchbase-clusters) + [runDiffer](#rundiffer) @@ -46,6 +48,33 @@ It can be compiled using the accompanying make file. ~/xdcrDiffer$ make ``` +### Building with Docker + +Docker build: +``` +docker build -t xdcr-differ:1.0.0 . +``` + +#### Multiple platform using docker buildx + +Creating the builder: +(for additional configuration -> https://docs.docker.com/build/buildkit/configure/) + +CTX=mycontext +docker buildx ls | grep -w ${CTX} || docker buildx create --name ${CTX} + +Docker buildx build for local/developer machine only: +``` +docker buildx build --builder mycontext --platform "linux/arm64" --load -t xdcr-differ:1.0.0 . +``` + +Docker buildx build and image push: +``` +docker buildx build --builder mycontext --platform "linux/amd64,linux/arm64" --push -t /xdcr-differ:1.0.0 . +``` + + + ### Running #### Preparing Couchbase Clusters Before running the differ to examine consistencies between two clusters, it is *highly recommended* to first set the Metadata Purge Interval to a low value, and then once that period has elapsed, run compaction on both clusters to ensure that tombstones are removed. Compaction will also ensure that the differ will only receive the minimum amount of data necessary, which will help minimize the storage requirement for the diff tool. diff --git a/runDiffer.sh b/runDiffer.sh index 618f88d..f105483 100755 --- a/runDiffer.sh +++ b/runDiffer.sh @@ -61,13 +61,16 @@ EOF } function waitForBgJobs { - local mainPid=$1 - local mainPidCnt=$(ps -ef | grep -v grep | grep -c $mainPid) - local jobsCnt=$(jobs -l | grep -c "Running") - while (((($jobsCnt > 0)) && (($mainPidCnt > 0)))); do - sleep 1 - jobsCnt=$(jobs -l | grep -c "Running") - mainPidCnt=$(ps -ef | grep -v grep | grep -c $mainPid) + local pid=$1 + # Check if the PID is provided + if [[ -z "$pid" ]]; then + echo "Usage: wait_for_pid " + return 1 + fi + # Loop until the process no longer exists + while kill -0 "$pid" 2>/dev/null; do + echo "Waiting for PID $pid to terminate..." + sleep 20 done } diff --git a/xdcr-differ-pod.yaml b/xdcr-differ-pod.yaml new file mode 100644 index 0000000..cbf8215 --- /dev/null +++ b/xdcr-differ-pod.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Pod +metadata: + name: xdcr-differ-pod + labels: + app: xdcr-differ +spec: + containers: + - name: xdcr-differ + imagePullPolicy: IfNotPresent + image: ilcepoc0950.corp.amdocs.com/xdcr-differ:1.0.1 + command: ["/bin/sleep", "infinity"] \ No newline at end of file From b4130dc20fc1802b58aacc86df85a45a371f74a8 Mon Sep 17 00:00:00 2001 From: CodeJitsu42 Date: Fri, 14 Mar 2025 17:34:14 +0200 Subject: [PATCH 2/3] Update xdcr-differ-pod.yaml --- xdcr-differ-pod.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xdcr-differ-pod.yaml b/xdcr-differ-pod.yaml index cbf8215..bc044bf 100644 --- a/xdcr-differ-pod.yaml +++ b/xdcr-differ-pod.yaml @@ -8,5 +8,5 @@ spec: containers: - name: xdcr-differ imagePullPolicy: IfNotPresent - image: ilcepoc0950.corp.amdocs.com/xdcr-differ:1.0.1 - command: ["/bin/sleep", "infinity"] \ No newline at end of file + image: myRepo/xdcr-differ:1.0.1 + command: ["/bin/sleep", "infinity"] From f5aa58fd9f5878aedb87051579af06d18b6ff7ca Mon Sep 17 00:00:00 2001 From: Marios Orphanou Date: Fri, 28 Mar 2025 14:45:50 +0200 Subject: [PATCH 3/3] tls --- runDiffer.sh | 11 +++++++++-- xdcr-differ-pod.yaml | 11 ++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/runDiffer.sh b/runDiffer.sh index f105483..0b7f3b2 100755 --- a/runDiffer.sh +++ b/runDiffer.sh @@ -24,7 +24,7 @@ function findExec() { function printHelp() { findExec - cat <