Skip to content

Commit 60e3ef2

Browse files
Sam-Bate-ITVRaj-StepSecurity
authored andcommitted
#62: add option for specifying image
1 parent 3889dcb commit 60e3ef2

File tree

6 files changed

+24
-9
lines changed

6 files changed

+24
-9
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ jobs:
2323
- name: Start MongoDB Server
2424
uses: ./
2525
with:
26+
mongodb-image: 'public.ecr.aws/docker/library/mongo'
2627
mongodb-version: ${{ matrix.mongodb-version }}

.github/workflows/test-auth.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
- name: Start MongoDB Server v${{ matrix.mongodb-version }}
2828
uses: ./
2929
with:
30+
mongodb-image: 'public.ecr.aws/docker/library/mongo'
3031
mongodb-version: ${{ matrix.mongodb-version }}
3132
mongodb-db: ${{ matrix.mongodb-db }}
3233
mongodb-username: ${{ matrix.mongodb-username }}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
- name: Start MongoDB Server v${{ matrix.mongodb-version }}
2525
uses: ./
2626
with:
27+
mongodb-image: 'public.ecr.aws/docker/library/mongo'
2728
mongodb-version: ${{ matrix.mongodb-version }}
2829
mongodb-replica-set: mongodb-test-rs
2930

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
- name: Start MongoDB Server v${{ matrix.mongodb-version }}
2525
uses: ./
2626
with:
27+
mongodb-image: 'public.ecr.aws/docker/library/mongo'
2728
mongodb-version: ${{ matrix.mongodb-version }}
2829

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

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
- name: Start MongoDB
3636
uses: step-security/[email protected]
3737
with:
38+
# Here we are using an image from Amazon's ECR rather than the default image from Docker Hub
39+
mongodb-image: 'public.ecr.aws/docker/library/mongo'
3840
mongodb-version: ${{ matrix.mongodb-version }}
3941

4042
- run: npm install

start-mongodb.sh

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
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
# validate subscription status
1314
API_URL="https://agent.api.stepsecurity.io/v1/github/$GITHUB_REPOSITORY/actions/subscription"
@@ -29,6 +30,13 @@ fi
2930
# `mongosh` is used starting from MongoDB 5.x
3031
MONGODB_CLIENT="mongosh --quiet"
3132

33+
if [ -z "$MONGODB_IMAGE" ]; then
34+
echo ""
35+
echo "Missing MongoDB image in the [mongodb-image] input. Received value: $MONGODB_IMAGE"
36+
echo ""
37+
38+
exit 2
39+
fi
3240

3341
if [ -z "$MONGODB_VERSION" ]; then
3442
echo ""
@@ -38,6 +46,7 @@ if [ -z "$MONGODB_VERSION" ]; then
3846
exit 2
3947
fi
4048

49+
echo "::group::Using mogo image $MONGODB_IMAGE:$MONGODB_VERSION"
4150

4251
echo "::group::Selecting correct MongoDB client"
4352
if [ "`echo $MONGODB_VERSION | cut -c 1`" -le "4" ]; then
@@ -100,7 +109,7 @@ if [ -z "$MONGODB_REPLICA_SET" ]; then
100109
echo " - container-name [$MONGODB_CONTAINER_NAME]"
101110
echo ""
102111

103-
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
112+
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
104113

105114
if [ $? -ne 0 ]; then
106115
echo "Error starting MongoDB Docker container"
@@ -121,7 +130,7 @@ echo " - replica set [$MONGODB_REPLICA_SET]"
121130
echo ""
122131

123132

124-
docker run --name $MONGODB_CONTAINER_NAME --publish $MONGODB_PORT:$MONGODB_PORT --detach mongo:$MONGODB_VERSION --port $MONGODB_PORT --replSet $MONGODB_REPLICA_SET
133+
docker run --name $MONGODB_CONTAINER_NAME --publish $MONGODB_PORT:$MONGODB_PORT --detach $MONGODB_IMAGE:$MONGODB_VERSION --port $MONGODB_PORT --replSet $MONGODB_REPLICA_SET
125134

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

0 commit comments

Comments
 (0)