Skip to content

Commit f7b0b80

Browse files
Merge pull request #62 from step-security/auto-cherry-pick
chore: Cherry-picked changes from upstream
2 parents 0ff4785 + 7a87800 commit f7b0b80

File tree

7 files changed

+55
-24
lines changed

7 files changed

+55
-24
lines changed

.github/workflows/test-auth.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
node-version: [18, 20]
13-
mongodb-version: ['4.4', '5.0', '6.0']
12+
node-version: [20, 22]
13+
mongodb-version: ['5.0', '6.0', '7.0']
1414
mongodb-db: ['ci']
1515
mongodb-username: ['ci']
1616
mongodb-password: ['ci']

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
node-version: [18, 20]
13-
mongodb-version: ['4.4', '5.0', '6.0']
12+
node-version: [20, 22]
13+
mongodb-version: ['5.0', '6.0', '7.0']
1414

1515
steps:
1616
- name: Harden Runner
@@ -45,9 +45,9 @@ jobs:
4545
runs-on: ubuntu-latest
4646
strategy:
4747
matrix:
48-
node-version: [18, 20]
48+
node-version: [20, 22]
4949
mongodb-port: [23456]
50-
mongodb-version: ['4.4', '5.0', '6.0']
50+
mongodb-version: ['5.0', '6.0', '7.0']
5151

5252
name: MongoDB v${{ matrix.mongodb-version }} RS, Port ${{ matrix.mongodb-port }} — Node.js v${{ matrix.node-version }}
5353
steps:

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
node-version: [18, 20]
13-
mongodb-version: ['4.4', '5.0', '6.0']
12+
node-version: [20, 22]
13+
mongodb-version: ['5.0', '6.0', '7.0']
1414

1515
steps:
1616
- name: Harden Runner
@@ -46,8 +46,8 @@ jobs:
4646
strategy:
4747
matrix:
4848
mongodb-port: [12345]
49-
mongodb-version: ['4.4', '5.0', '6.0']
50-
node-version: [18, 20]
49+
mongodb-version: ['5.0', '6.0', '7.0']
50+
node-version: [20, 22]
5151

5252
name: MongoDB v${{ matrix.mongodb-version }}, Port ${{ matrix.mongodb-port }} — Node.js v${{ matrix.node-version }}
5353
steps:

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ jobs:
3333
node-version: ${{ matrix.node-version }}
3434

3535
- name: Start MongoDB
36-
uses: step-security/mongodb-github-action@1.11.0
36+
uses: step-security/mongodb-github-action@1.12.0
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
@@ -73,7 +75,7 @@ jobs:
7375
node-version: ${{ matrix.node-version }}
7476
7577
- name: Start MongoDB
76-
uses: step-security/mongodb-github-action@1.11.0
78+
uses: step-security/mongodb-github-action@1.12.0
7779
with:
7880
mongodb-version: ${{ matrix.mongodb-version }}
7981
mongodb-replica-set: test-rs
@@ -117,7 +119,7 @@ jobs:
117119
node-version: ${{ matrix.node-version }}
118120
119121
- name: Start MongoDB
120-
uses: step-security/mongodb-github-action@1.11.0
122+
uses: step-security/mongodb-github-action@1.12.0
121123
with:
122124
mongodb-version: ${{ matrix.mongodb-version }}
123125
mongodb-replica-set: test-rs
@@ -132,6 +134,18 @@ jobs:
132134
CI: true
133135
```
134136

137+
### Using a Custom Mongo Image
138+
You can utilize an alternative MongoDB docker image using the `mongodb-image` input:
139+
140+
141+
```yaml
142+
- name: Start MongoDB
143+
uses: step-security/[email protected]
144+
with:
145+
# Here we are using an image from Amazon's ECR rather than the default image from Docker Hub
146+
mongodb-image: 'public.ecr.aws/docker/library/mongo'
147+
mongodb-version: ${{ matrix.mongodb-version }}
148+
```
135149

136150
### With Authentication (MongoDB `--auth` Flag)
137151
Setting the `mongodb-username` and `mongodb-password` inputs. As per the [Dockerhub documentation](https://hub.docker.com/_/mongo), this automatically creates an admin user and enables `--auth` mode.
@@ -161,7 +175,7 @@ jobs:
161175
node-version: ${{ matrix.node-version }}
162176
163177
- name: Start MongoDB
164-
uses: step-security/mongodb-github-action@1.11.0
178+
uses: step-security/mongodb-github-action@1.12.0
165179
with:
166180
mongodb-version: ${{ matrix.mongodb-version }}
167181
mongodb-username: supercharge
@@ -205,7 +219,7 @@ jobs:
205219
node-version: ${{ matrix.node-version }}
206220
207221
- name: Start MongoDB
208-
uses: step-security/mongodb-github-action@1.11.0
222+
uses: step-security/mongodb-github-action@1.12.0
209223
with:
210224
mongodb-version: ${{ matrix.mongodb-version }}
211225
mongodb-container-name: mongodb-${{ matrix.node-version }}-${{ matrix.mongodb-version }}

action-types.yml

Lines changed: 2 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

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 MongoDB Docker 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)