Skip to content

Commit 9faded7

Browse files
committed
feat: support new mongodb-extra-env to pass ENV vars
required to allow using the workaround listed docker-library/mongo#748 (reply in thread)
1 parent 84016f7 commit 9faded7

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

action-types.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ inputs:
2626
type: string
2727
docker-network-alias:
2828
type: string
29+
mongodb-extra-env:
30+
type: string

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ inputs:
7171
required: false
7272
default: ''
7373

74+
mongodb-extra-env:
75+
description: 'Extra environment variables to pass to the MongoDB container, one KEY=VALUE per line (e.g. "GLIBC_TUNABLES=glibc.pthread.rseq=1")'
76+
required: false
77+
default: ''
78+
7479
runs:
7580
using: 'docker'
7681
image: 'Dockerfile'
@@ -88,4 +93,5 @@ runs:
8893
- ${{ inputs.mongodb-replica-set-host }}
8994
- ${{ inputs.docker-network }}
9095
- ${{ inputs.docker-network-alias }}
96+
- ${{ inputs.mongodb-extra-env }}
9197
post-entrypoint: /stop-mongodb.sh

start-mongodb.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ MONGODB_AUTHSOURCE=${10}
1414
MONGODB_REPLICA_SET_HOST=${11:-"localhost"}
1515
DOCKER_NETWORK=${12}
1616
DOCKER_NETWORK_ALIAS=${13:-$MONGODB_CONTAINER_NAME}
17+
MONGODB_EXTRA_ENV=${14}
1718

1819
# If DOCKER_NETWORK not provided, try to detect the default GitHub Actions network
1920
if [ -z "$DOCKER_NETWORK" ]; then
@@ -26,6 +27,17 @@ if [ -n "$DOCKER_NETWORK" ]; then
2627
NETWORK_ARGS="--network $DOCKER_NETWORK --network-alias $DOCKER_NETWORK_ALIAS"
2728
fi
2829

30+
# Build extra -e flags from newline-separated KEY=VALUE pairs
31+
EXTRA_ENV_ARGS=""
32+
if [ -n "$MONGODB_EXTRA_ENV" ]; then
33+
while IFS= read -r env_line; do
34+
[ -z "$env_line" ] && continue
35+
EXTRA_ENV_ARGS="$EXTRA_ENV_ARGS -e $env_line"
36+
done <<EOF
37+
$MONGODB_EXTRA_ENV
38+
EOF
39+
fi
40+
2941
# Echo selected network info for visibility
3042
echo "::group::Selecting Docker network"
3143
if [ -n "$DOCKER_NETWORK" ]; then
@@ -117,6 +129,7 @@ if [ -z "$MONGODB_REPLICA_SET" ]; then
117129
-e MONGO_INITDB_DATABASE=$MONGODB_DB \
118130
-e MONGO_INITDB_ROOT_USERNAME=$MONGODB_USERNAME \
119131
-e MONGO_INITDB_ROOT_PASSWORD=$MONGODB_PASSWORD \
132+
$EXTRA_ENV_ARGS \
120133
--detach $MONGODB_IMAGE:$MONGODB_VERSION --port $MONGODB_PORT
121134

122135
if [ $? -ne 0 ]; then
@@ -169,6 +182,7 @@ docker run --name $MONGODB_CONTAINER_NAME \
169182
-e MONGO_INITDB_ROOT_PASSWORD=$MONGODB_PASSWORD \
170183
-e MONGO_KEY=$MONGODB_KEY \
171184
-e MONGO_KEY_FILE=/tmp/mongo-keyfile \
185+
$EXTRA_ENV_ARGS \
172186
--detach \
173187
--entrypoint bash \
174188
$MONGODB_IMAGE:$MONGODB_VERSION \

0 commit comments

Comments
 (0)