Skip to content

Commit 2ae9a45

Browse files
committed
#62: add option for specifying image
1 parent 5a87bd8 commit 2ae9a45

8 files changed

+32
-9
lines changed

.github/workflows/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ jobs:
1818
- name: Start MongoDB Server
1919
uses: ./
2020
with:
21+
mongodb-image: 'public.ecr.aws/docker/library/mongo'
2122
mongodb-version: ${{ matrix.mongodb-version }}

.github/workflows/test-auth.yml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
- name: Start MongoDB Server v${{ matrix.mongodb-version }}
2323
uses: ./
2424
with:
25+
mongodb-image: 'public.ecr.aws/docker/library/mongo'
2526
mongodb-version: ${{ matrix.mongodb-version }}
2627
mongodb-db: ${{ matrix.mongodb-db }}
2728
mongodb-username: ${{ matrix.mongodb-username }}

.github/workflows/test-replica-set.yml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
- name: Start MongoDB Server v${{ matrix.mongodb-version }}
2020
uses: ./
2121
with:
22+
mongodb-image: 'public.ecr.aws/docker/library/mongo'
2223
mongodb-version: ${{ matrix.mongodb-version }}
2324
mongodb-replica-set: mongodb-test-rs
2425

.github/workflows/test-single-instance.yml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
- name: Start MongoDB Server v${{ matrix.mongodb-version }}
2020
uses: ./
2121
with:
22+
mongodb-image: 'public.ecr.aws/docker/library/mongo'
2223
mongodb-version: ${{ matrix.mongodb-version }}
2324

2425
- name: Use Node.js ${{ matrix.node-version }}

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ jobs:
6060
- name: Start MongoDB
6161
uses: supercharge/mongodb-github-action@1.11.0
6262
with:
63+
# Here we are using an image from Amazon's ECR rather than the default image from Docker Hub
64+
mongodb-image: 'public.ecr.aws/docker/library/mongo'
6365
mongodb-version: ${{ matrix.mongodb-version }}
6466

6567
- run: npm install

action-types.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# See https://github.com/krzema12/github-actions-typing
22
inputs:
3+
mongodb-image:
4+
type: string
35
mongodb-version:
46
type: string
57
mongodb-replica-set:

action.yml

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ branding:
66
color: 'green'
77

88
inputs:
9+
mongodb-image:
10+
description: 'MongoDB image to use (defaults to using "mongo" from Docker Hub but you could also use an image from another repository such as Amazons "public.ecr.aws/docker/library/mongo")'
11+
required: false
12+
default: 'mongo'
13+
914
mongodb-version:
1015
description: 'MongoDB version to use (default "latest")'
1116
required: false
@@ -45,6 +50,7 @@ runs:
4550
using: 'docker'
4651
image: 'Dockerfile'
4752
args:
53+
- ${{ inputs.mongodb-image }}
4854
- ${{ inputs.mongodb-version }}
4955
- ${{ inputs.mongodb-replica-set }}
5056
- ${{ inputs.mongodb-port }}

start-mongodb.sh

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
#!/bin/sh
22

33
# Map input values from the GitHub Actions workflow to shell variables
4-
MONGODB_VERSION=$1
5-
MONGODB_REPLICA_SET=$2
6-
MONGODB_PORT=$3
7-
MONGODB_DB=$4
8-
MONGODB_USERNAME=$5
9-
MONGODB_PASSWORD=$6
10-
MONGODB_CONTAINER_NAME=$7
4+
MONGODB_IMAGE=$1
5+
MONGODB_VERSION=$2
6+
MONGODB_REPLICA_SET=$3
7+
MONGODB_PORT=$4
8+
MONGODB_DB=$5
9+
MONGODB_USERNAME=$6
10+
MONGODB_PASSWORD=$7
11+
MONGODB_CONTAINER_NAME=$8
1112

1213
# `mongosh` is used starting from MongoDB 5.x
1314
MONGODB_CLIENT="mongosh --quiet"
1415

16+
if [ -z "$MONGODB_IMAGE" ]; then
17+
echo ""
18+
echo "Missing MongoDB image in the [mongodb-image] input. Received value: $MONGODB_IMAGE"
19+
echo ""
20+
21+
exit 2
22+
fi
1523

1624
if [ -z "$MONGODB_VERSION" ]; then
1725
echo ""
@@ -21,6 +29,7 @@ if [ -z "$MONGODB_VERSION" ]; then
2129
exit 2
2230
fi
2331

32+
echo "::group::Using mogo image $MONGODB_IMAGE:$MONGODB_VERSION"
2433

2534
echo "::group::Selecting correct MongoDB client"
2635
if [ "`echo $MONGODB_VERSION | cut -c 1`" -le "4" ]; then
@@ -83,7 +92,7 @@ if [ -z "$MONGODB_REPLICA_SET" ]; then
8392
echo " - container-name [$MONGODB_CONTAINER_NAME]"
8493
echo ""
8594

86-
docker run --name $MONGODB_CONTAINER_NAME --publish $MONGODB_PORT:$MONGODB_PORT -e MONGO_INITDB_DATABASE=$MONGODB_DB -e MONGO_INITDB_ROOT_USERNAME=$MONGODB_USERNAME -e MONGO_INITDB_ROOT_PASSWORD=$MONGODB_PASSWORD --detach mongo:$MONGODB_VERSION --port $MONGODB_PORT
95+
docker run --name $MONGODB_CONTAINER_NAME --publish $MONGODB_PORT:$MONGODB_PORT -e MONGO_INITDB_DATABASE=$MONGODB_DB -e MONGO_INITDB_ROOT_USERNAME=$MONGODB_USERNAME -e MONGO_INITDB_ROOT_PASSWORD=$MONGODB_PASSWORD --detach $MONGODB_IMAGE:$MONGODB_VERSION --port $MONGODB_PORT
8796

8897
if [ $? -ne 0 ]; then
8998
echo "Error starting MongoDB Docker container"
@@ -104,7 +113,7 @@ echo " - replica set [$MONGODB_REPLICA_SET]"
104113
echo ""
105114

106115

107-
docker run --name $MONGODB_CONTAINER_NAME --publish $MONGODB_PORT:$MONGODB_PORT --detach mongo:$MONGODB_VERSION --port $MONGODB_PORT --replSet $MONGODB_REPLICA_SET
116+
docker run --name $MONGODB_CONTAINER_NAME --publish $MONGODB_PORT:$MONGODB_PORT --detach $MONGODB_IMAGE:$MONGODB_VERSION --port $MONGODB_PORT --replSet $MONGODB_REPLICA_SET
108117

109118
if [ $? -ne 0 ]; then
110119
echo "Error starting MongoDB Docker container"

0 commit comments

Comments
 (0)