From 84016f79348666ef6e704eaef8274765f9388f10 Mon Sep 17 00:00:00 2001 From: Radoslav Kirilov Date: Tue, 21 Apr 2026 11:06:37 +0300 Subject: [PATCH 1/2] fix: catch and exit with error when rs initialization fails --- start-mongodb.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/start-mongodb.sh b/start-mongodb.sh index b34b56b..f8a1ccf 100755 --- a/start-mongodb.sh +++ b/start-mongodb.sh @@ -205,10 +205,21 @@ docker exec --tty $MONGODB_CONTAINER_NAME $MONGODB_CLIENT --port $MONGODB_PORT $ }) " +if [ $? -ne 0 ]; then + echo "Error initiating replica set [$MONGODB_REPLICA_SET]" + exit 2 +fi + echo "Success! Initiated replica set [$MONGODB_REPLICA_SET]" echo "::endgroup::" echo "::group::Checking replica set status [$MONGODB_REPLICA_SET]" docker exec --tty $MONGODB_CONTAINER_NAME $MONGODB_CLIENT --port $MONGODB_PORT $MONGODB_ARGS --eval "rs.status()" + +if [ $? -ne 0 ]; then + echo "Error checking replica set status [$MONGODB_REPLICA_SET]" + exit 2 +fi + echo "::endgroup::" From 9faded75c16e21bb015280b84e88d0a7fd17eb07 Mon Sep 17 00:00:00 2001 From: Radoslav Kirilov Date: Tue, 21 Apr 2026 11:14:23 +0300 Subject: [PATCH 2/2] feat: support new `mongodb-extra-env` to pass ENV vars required to allow using the workaround listed https://github.com/docker-library/mongo/discussions/748#discussioncomment-16076069 --- action-types.yml | 2 ++ action.yml | 6 ++++++ start-mongodb.sh | 14 ++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/action-types.yml b/action-types.yml index e567ea3..6dde1a6 100644 --- a/action-types.yml +++ b/action-types.yml @@ -26,3 +26,5 @@ inputs: type: string docker-network-alias: type: string + mongodb-extra-env: + type: string diff --git a/action.yml b/action.yml index bd0b05f..3e15d84 100644 --- a/action.yml +++ b/action.yml @@ -71,6 +71,11 @@ inputs: required: false default: '' + mongodb-extra-env: + description: 'Extra environment variables to pass to the MongoDB container, one KEY=VALUE per line (e.g. "GLIBC_TUNABLES=glibc.pthread.rseq=1")' + required: false + default: '' + runs: using: 'docker' image: 'Dockerfile' @@ -88,4 +93,5 @@ runs: - ${{ inputs.mongodb-replica-set-host }} - ${{ inputs.docker-network }} - ${{ inputs.docker-network-alias }} + - ${{ inputs.mongodb-extra-env }} post-entrypoint: /stop-mongodb.sh diff --git a/start-mongodb.sh b/start-mongodb.sh index f8a1ccf..025103e 100755 --- a/start-mongodb.sh +++ b/start-mongodb.sh @@ -14,6 +14,7 @@ MONGODB_AUTHSOURCE=${10} MONGODB_REPLICA_SET_HOST=${11:-"localhost"} DOCKER_NETWORK=${12} DOCKER_NETWORK_ALIAS=${13:-$MONGODB_CONTAINER_NAME} +MONGODB_EXTRA_ENV=${14} # If DOCKER_NETWORK not provided, try to detect the default GitHub Actions network if [ -z "$DOCKER_NETWORK" ]; then @@ -26,6 +27,17 @@ if [ -n "$DOCKER_NETWORK" ]; then NETWORK_ARGS="--network $DOCKER_NETWORK --network-alias $DOCKER_NETWORK_ALIAS" fi +# Build extra -e flags from newline-separated KEY=VALUE pairs +EXTRA_ENV_ARGS="" +if [ -n "$MONGODB_EXTRA_ENV" ]; then + while IFS= read -r env_line; do + [ -z "$env_line" ] && continue + EXTRA_ENV_ARGS="$EXTRA_ENV_ARGS -e $env_line" + done <