Skip to content

Commit 9202bc8

Browse files
committed
feat: mongodb-replica-set-host input
1 parent ad5ad1f commit 9202bc8

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

action-types.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ inputs:
2020
type: string
2121
mongodb-authsource:
2222
type: string
23+
mongodb-replica-set-host:
24+
type: string
25+
docker-network:
26+
type: string
27+
docker-network-alias:
28+
type: string

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ inputs:
5656
required: false
5757
default: 'admin'
5858

59+
mongodb-replica-set-host:
60+
description: 'MongoDB replica set host, must be accessible from both internal container and external usage (default: "localhost"')
61+
required: false
62+
default: 'localhost'
63+
5964
docker-network:
6065
description: 'Docker network to attach the MongoDB container to. If not provided, will try to use the default GitHub Actions network if available (github_network_<rand>).'
6166
required: false
@@ -80,6 +85,7 @@ runs:
8085
- ${{ inputs.mongodb-container-name }}
8186
- ${{ inputs.mongodb-key }}
8287
- ${{ inputs.mongodb-authsource }}
88+
- ${{ inputs.mongodb-replica-set-host }}
8389
- ${{ inputs.docker-network }}
8490
- ${{ inputs.docker-network-alias }}
8591
post-entrypoint: /stop-mongodb.sh

start-mongodb.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ MONGODB_PASSWORD=$7
1111
MONGODB_CONTAINER_NAME=$8
1212
MONGODB_KEY=$9
1313
MONGODB_AUTHSOURCE=${10}
14-
DOCKER_NETWORK=${11}
15-
DOCKER_NETWORK_ALIAS=${12:-$MONGODB_CONTAINER_NAME}
14+
MONGODB_REPLICA_SET_HOST=${11:-"localhost"}
15+
DOCKER_NETWORK=${12}
16+
DOCKER_NETWORK_ALIAS=${13:-$MONGODB_CONTAINER_NAME}
1617

1718
# If DOCKER_NETWORK not provided, try to detect the default GitHub Actions network
1819
if [ -z "$DOCKER_NETWORK" ]; then
@@ -199,7 +200,7 @@ docker exec --tty $MONGODB_CONTAINER_NAME $MONGODB_CLIENT --port $MONGODB_PORT $
199200
\"_id\": \"$MONGODB_REPLICA_SET\",
200201
\"members\": [ {
201202
\"_id\": 0,
202-
\"host\": \"localhost:$MONGODB_PORT\"
203+
\"host\": \"$MONGODB_REPLICA_SET_HOST:$MONGODB_PORT\"
203204
} ]
204205
})
205206
"

stop-mongodb.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ MONGODB_PASSWORD=$7
1111
MONGODB_CONTAINER_NAME=$8
1212
MONGODB_KEY=$9
1313
MONGODB_AUTHSOURCE=${10}
14-
DOCKER_NETWORK=${11}
15-
DOCKER_NETWORK_ALIAS=${12}
14+
MONGODB_REPLICA_SET_HOST=${11:-"localhost"}
15+
DOCKER_NETWORK=${12}
16+
DOCKER_NETWORK_ALIAS=${13:-$MONGODB_CONTAINER_NAME}
1617

1718
# Best-effort cleanup, do not fail the job if cleanup fails
1819
set +e

0 commit comments

Comments
 (0)