Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion build-all-multiplatform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fi

COMPONENTS=$*
if [ -z "$COMPONENTS" ]; then
COMPONENTS="postgres debezium"
COMPONENTS="postgres debezium mongodb"
fi;

if [ -z "$MULTIPLATFORM_PLATFORMS" ]; then
Expand All @@ -31,6 +31,8 @@ DEBEZIUM_SINGLEPLATFORM_VERSIONS="1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8"

POSTGRES_VERSIONS="12 13 14"
POSTGRES_MULTIPLATFORM_VERSIONS="15 16 17 18 12-alpine 13-alpine 14-alpine 15-alpine 16-alpine 17-alpine 18-alpine"
MONGODB_VERSIONS="6"
MONGODB_MULTIPLATFORM_VERSIONS="6"

docker buildx prune -f || true
if shouldBuild "postgres"; then
Expand All @@ -52,3 +54,13 @@ if shouldBuild "debezium"; then
fi;
done
fi;

if shouldBuild "mongodb"; then
for MONGODB_VERSION in $MONGODB_MULTIPLATFORM_VERSIONS; do
./build-mongodb-multiplatform.sh "$MONGODB_VERSION" "${MULTIPLATFORM_PLATFORMS}"
done

for MONGODB_VERSION in $MONGODB_VERSIONS; do
./build-mongodb-multiplatform.sh "$MONGODB_VERSION" "linux/amd64"
done
fi;
6 changes: 6 additions & 0 deletions build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ if [ -z "$DEBEZIUM_VERSIONS" ]; then
DEBEZIUM_VERSIONS="$DEBEZIUM_VERSION"
fi
POSTGRES_VERSIONS="12 12-alpine 13 13-alpine 14 14-alpine 15 15-alpine 16 16-alpine 17 17-alpine 18 18-alpine"
MONGODB_VERSIONS="6"

for POSTGRES_VERSION in $POSTGRES_VERSIONS; do
./build-postgres.sh "$POSTGRES_VERSION"
done

for MONGODB_VERSION in $MONGODB_VERSIONS; do
./build-mongodb.sh "$MONGODB_VERSION"
done


for DBZ in $DEBEZIUM_VERSIONS; do
./build-debezium.sh "$DBZ"
done
60 changes: 60 additions & 0 deletions build-mongodb-multiplatform.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

set -eo pipefail

function usage() {
MSG=$1

echo ""
echo "$MSG"
echo ""
echo "Usage: build-mongodb-multiplatform <version> <platform>";
echo ""
echo " Where platform can be for example:"
echo " linux/amd64"
echo " linux/amd64,linux/arm64"
echo " linux/arm64"
echo ""
exit 1;
}

if [[ -z "$1" ]]; then
usage "A version must be specified."
fi

if [[ -z "$2" ]]; then
usage "Platform must be specified."
fi
PLATFORM=$2

if [ -z "${DEBEZIUM_DOCKER_REGISTRY_PRIMARY_NAME}" ]; then
DEBEZIUM_DOCKER_REGISTRY_PRIMARY_NAME=quay.io/debezium
fi;

echo ""
echo "****************************************************************"
echo "** Building ${DEBEZIUM_DOCKER_REGISTRY_PRIMARY_NAME}/mongodb:$1 for $PLATFORM"
echo "****************************************************************"
TAGS+=("-t ${DEBEZIUM_DOCKER_REGISTRY_PRIMARY_NAME}/mongodb:$1")
if [ -n "${DEBEZIUM_DOCKER_REGISTRY_SECONDARY_NAME}" ]; then
TAGS+=("-t ${DEBEZIUM_DOCKER_REGISTRY_SECONDARY_NAME}/mongodb:$1")
fi;

PUSH_FLAG="--push"
if [[ "$DRY_RUN" == "true" ]]; then
PUSH_FLAG=""
fi

echo "****************************************************************"
echo "Running docker buildx build $PUSH_FLAG --platform \"${PLATFORM}\" \
--progress=plain \
--build-arg DEBEZIUM_DOCKER_REGISTRY_PRIMARY_NAME=\"$DEBEZIUM_DOCKER_REGISTRY_PRIMARY_NAME\" \
${TAGS[*]} \
\"mongodb/$1\""
echo "****************************************************************"

# shellcheck disable=SC2068
docker buildx build $PUSH_FLAG --platform "${PLATFORM}" \
--build-arg DEBEZIUM_DOCKER_REGISTRY_PRIMARY_NAME="${DEBEZIUM_DOCKER_REGISTRY_PRIMARY_NAME}" \
${TAGS[@]} \
"mongodb/$1"
32 changes: 32 additions & 0 deletions build-mongodb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

set -eo pipefail

if [[ -z "$1" ]]; then
echo ""
echo "A version must be specified."
echo ""
echo "Usage: build-mongodb <version>";
echo ""
exit 1;
fi

if [ -z "${DEBEZIUM_DOCKER_REGISTRY_PRIMARY_NAME}" ]; then
DEBEZIUM_DOCKER_REGISTRY_PRIMARY_NAME=quay.io/debezium
fi;

echo ""
echo "****************************************************************"
echo "** Building ${DEBEZIUM_DOCKER_REGISTRY_PRIMARY_NAME}/mongodb:$1"
echo "****************************************************************"
docker build -t "${DEBEZIUM_DOCKER_REGISTRY_PRIMARY_NAME}/mongodb:$1" "mongodb/$1"


if [[ "$PUSH_IMAGES" == "true" || "$DRY_RUN" == "false" ]]; then
echo "Pushing the image into the registry"
docker push "${DEBEZIUM_DOCKER_REGISTRY_PRIMARY_NAME}/mongodb:$1"
if [ -n "${DEBEZIUM_DOCKER_REGISTRY_SECONDARY_NAME}" ]; then
docker tag "${DEBEZIUM_DOCKER_REGISTRY_PRIMARY_NAME}/mongodb:$1" "${DEBEZIUM_DOCKER_REGISTRY_SECONDARY_NAME}/mongodb:$1"
docker push "${DEBEZIUM_DOCKER_REGISTRY_SECONDARY_NAME}/mongodb:$1"
fi;
fi
16 changes: 16 additions & 0 deletions mongodb/6.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM mirror.gcr.io/library/mongo:6.0

LABEL maintainer="Debezium Community"

RUN openssl rand -base64 756 > /etc/mongodb.keyfile &&\
chown mongodb /etc/mongodb.keyfile &&\
chmod 400 /etc/mongodb.keyfile

# Copy custom entrypoint script
COPY --chmod=+x mongodb-debezium-entrypoint.sh /usr/local/bin/mongodb-debezium-entrypoint.sh

# Switch to non-root user
USER mongodb

# Override the default entrypoint
ENTRYPOINT ["/usr/local/bin/mongodb-debezium-entrypoint.sh"]
100 changes: 100 additions & 0 deletions mongodb/6.0/mongodb-debezium-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/env sh

set -ex

PIDFILE="/tmp/mongod.pid"
INIT_DIR="/docker-entrypoint-initdb.d"
METADATA_DIR="/data/db/.metadata"
REPLICA_FILE="$METADATA_DIR/.replicaset"
LOG_PATH="/tmp/mongod.log"
DB_PATH="/data/db"
PORT=27017

# Default values
: "${MONGO_INITDB_DATABASE:=admin}"
: "${RS_NAME:=rs0}"
: "${HOSTNAME:=$(hostname)}"
: "${MONGODB_KEYFILE:=/etc/mongodb.keyfile}"
: "${MONGO_INITDB_ROOT_USERNAME:=admin}"
: "${MONGO_INITDB_ROOT_PASSWORD:=admin}"
: "${RETRIES:=30}"


if command -v mongosh >/dev/null 2>&1; then
MONGO_SHELL="mongosh"
elif command -v mongo >/dev/null 2>&1; then
MONGO_SHELL="mongo"
else
echo "No MongoDB shell found (mongosh or mongo). Exiting."
exit 127
fi


if [ ! -f "$REPLICA_FILE" ]; then
echo "=> Starting MongoDB without auth for initialization..."
mongod --fork --dbpath "$DB_PATH" --port "$PORT" --logpath "$LOG_PATH" --pidfilepath "$PIDFILE"

echo "=> Waiting for MongoDB to start..."

while true; do
if ! { [ -s "$PIDFILE" ] && ps "$(cat "$PIDFILE")" > /dev/null 2>&1; }; then
echo "ERROR: mongod process did not stay running. Check logs for errors."
exit 1
fi

if $MONGO_SHELL --host 127.0.0.1 --port "$PORT" --quiet "$MONGO_INITDB_DATABASE" --eval 'quit(0)' > /dev/null 2>&1; then
break
fi

RETRIES=$((RETRIES - 1))
if [ "$RETRIES" -le 0 ]; then
echo "ERROR: mongod did not accept connections quickly enough. Check logs for errors."
exit 1
fi

sleep 1
done

echo "=> Creating root user..."
$MONGO_SHELL admin --eval "db.createUser({user:'$MONGO_INITDB_ROOT_USERNAME',pwd:'$MONGO_INITDB_ROOT_PASSWORD',roles:[{role:'root',db:'admin'}]})"

echo "=> Shutting down temporary MongoDB..."
mongod --shutdown

echo "=> Starting MongoDB with replica set and auth..."
mongod --fork --logpath "$LOG_PATH" --keyFile "$MONGODB_KEYFILE" --replSet "$RS_NAME" --shardsvr --dbpath "$DB_PATH" --port "$PORT"

echo "=> Initiating replica set..."
CONFIG="{_id:\"$RS_NAME\",version:1,members:[{_id:0,host:\"$HOSTNAME:$PORT\"}]}"
$MONGO_SHELL -u "$MONGO_INITDB_ROOT_USERNAME" -p "$MONGO_INITDB_ROOT_PASSWORD" --authenticationDatabase admin --eval "printjson(rs.initiate($CONFIG))"

echo "=> Running initialization scripts from $INIT_DIR..."
if [ -d "$INIT_DIR" ]; then
for f in "$INIT_DIR"/*; do
case "$f" in
*.sh)
echo "=> Executing shell script: $f"
. "$f"
;;
*.js)
echo "=> Executing MongoDB script: $f"
$MONGO_SHELL -u "$MONGO_INITDB_ROOT_USERNAME" -p "$MONGO_INITDB_ROOT_PASSWORD" --authenticationDatabase admin "$MONGO_INITDB_DATABASE" "$f"
;;
*)
echo "=> Ignoring file: $f"
;;
esac
done
fi

echo "=> Finalizing setup..."
mkdir -p "$METADATA_DIR"
touch "$REPLICA_FILE"
mongod --shutdown

echo "=> Starting MongoDB normally..."
exec mongod --auth --keyFile "$MONGODB_KEYFILE" --replSet "$RS_NAME" --dbpath "$DB_PATH" --port "$PORT" --bind_ip_all
else
echo "=> MongoDB already initialized, starting normally..."
exec mongod --auth --keyFile "$MONGODB_KEYFILE" --replSet "$RS_NAME" --dbpath "$DB_PATH" --port "$PORT" --bind_ip_all
fi
Loading