Skip to content
This repository was archived by the owner on Jan 11, 2026. It is now read-only.

Commit ebe17b8

Browse files
committed
Log into Dockerhub when credentials are provided
What? - Add 2 new optional inputs to the Github action: - `dockerhub-username`: the "docker ID" (aka username) for the Dockerhub account the action should log in as - `dockerhub-password`: the account password or a personal access token used to authorize the account login. - Update the `./start-mongodb.sh` script to log into Dockerhub when these two inputs are provided. Why? - To allow users to authenticate with Dockerhub, and increase their rate limits. Otherwise, unauthorized requests can be rate limited, see: - https://www.docker.com/increase-rate-limits/ - supercharge#62
1 parent 5a87bd8 commit ebe17b8

3 files changed

Lines changed: 43 additions & 7 deletions

File tree

action-types.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# See https://github.com/krzema12/github-actions-typing
22
inputs:
3+
dockerhub-username:
4+
type: string
5+
dockerhub-password:
6+
type: string
37
mongodb-version:
48
type: string
59
mongodb-replica-set:

action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ branding:
66
color: 'green'
77

88
inputs:
9+
dockerhub-username:
10+
description: 'Docker username to use to log into Dockerhub'
11+
required: false
12+
default: ''
13+
14+
dockerhub-password:
15+
description: 'Docker password or personal access token to use to log into Dockerhub'
16+
required: false
17+
default: ''
18+
919
mongodb-version:
1020
description: 'MongoDB version to use (default "latest")'
1121
required: false
@@ -45,6 +55,8 @@ runs:
4555
using: 'docker'
4656
image: 'Dockerfile'
4757
args:
58+
- ${{ inputs.dockerhub-username }}
59+
- ${{ inputs.dockerhub-password }}
4860
- ${{ inputs.mongodb-version }}
4961
- ${{ inputs.mongodb-replica-set }}
5062
- ${{ inputs.mongodb-port }}

start-mongodb.sh

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
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+
DOCKERHUB_USERNAME=$1
5+
DOCKERHUB_PASSWORD=$2
6+
MONGODB_VERSION=$3
7+
MONGODB_REPLICA_SET=$4
8+
MONGODB_PORT=$5
9+
MONGODB_DB=$6
10+
MONGODB_USERNAME=$7
11+
MONGODB_PASSWORD=$8
12+
MONGODB_CONTAINER_NAME=$9
1113

1214
# `mongosh` is used starting from MongoDB 5.x
1315
MONGODB_CLIENT="mongosh --quiet"
@@ -73,6 +75,24 @@ wait_for_mongodb () {
7375
# docker rm -f $MONGODB_CONTAINER_NAME
7476
# fi
7577

78+
login_to_dockerhub () {
79+
echo "::group::Logging in to Docker Hub"
80+
echo "Logging in as [$DOCKERHUB_USERNAME]"
81+
echo ""
82+
83+
echo $DOCKERHUB_PASSWORD | docker login --username $DOCKERHUB_USERNAME --password-stdin
84+
85+
if [ $? -ne 0 ]; then
86+
echo "Error logging in to Docker Hub"
87+
exit 2
88+
fi
89+
echo "::endgroup::"
90+
}
91+
92+
if [[ -n "$DOCKERHUB_USERNAME" && -n "$DOCKERHUB_PASSWORD" ]]; then
93+
login_to_dockerhub
94+
fi
95+
7696

7797
if [ -z "$MONGODB_REPLICA_SET" ]; then
7898
echo "::group::Starting single-node instance, no replica set"

0 commit comments

Comments
 (0)