Skip to content
Merged
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
2 changes: 2 additions & 0 deletions action-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ inputs:
type: string
docker-network-alias:
type: string
mongodb-extra-env:
type: string
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
25 changes: 25 additions & 0 deletions start-mongodb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <<EOF
$MONGODB_EXTRA_ENV
EOF
fi

# Echo selected network info for visibility
echo "::group::Selecting Docker network"
if [ -n "$DOCKER_NETWORK" ]; then
Expand Down Expand Up @@ -117,6 +129,7 @@ if [ -z "$MONGODB_REPLICA_SET" ]; then
-e MONGO_INITDB_DATABASE=$MONGODB_DB \
-e MONGO_INITDB_ROOT_USERNAME=$MONGODB_USERNAME \
-e MONGO_INITDB_ROOT_PASSWORD=$MONGODB_PASSWORD \
$EXTRA_ENV_ARGS \
--detach $MONGODB_IMAGE:$MONGODB_VERSION --port $MONGODB_PORT

if [ $? -ne 0 ]; then
Expand Down Expand Up @@ -169,6 +182,7 @@ docker run --name $MONGODB_CONTAINER_NAME \
-e MONGO_INITDB_ROOT_PASSWORD=$MONGODB_PASSWORD \
-e MONGO_KEY=$MONGODB_KEY \
-e MONGO_KEY_FILE=/tmp/mongo-keyfile \
$EXTRA_ENV_ARGS \
--detach \
--entrypoint bash \
$MONGODB_IMAGE:$MONGODB_VERSION \
Expand Down Expand Up @@ -205,10 +219,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::"
Loading