From 2ae9a450cfac8f6d0d4bd074cb201aa589c7277a Mon Sep 17 00:00:00 2001 From: Sam Bate Date: Fri, 25 Oct 2024 14:01:19 +0100 Subject: [PATCH 1/4] #62: add option for specifying image --- .github/workflows/main.yml | 1 + .github/workflows/test-auth.yml | 1 + .github/workflows/test-replica-set.yml | 1 + .github/workflows/test-single-instance.yml | 1 + README.md | 2 ++ action-types.yml | 2 ++ action.yml | 6 +++++ start-mongodb.sh | 27 ++++++++++++++-------- 8 files changed, 32 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6d039fe..97e0d35 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,4 +18,5 @@ jobs: - name: Start MongoDB Server uses: ./ with: + mongodb-image: 'public.ecr.aws/docker/library/mongo' mongodb-version: ${{ matrix.mongodb-version }} diff --git a/.github/workflows/test-auth.yml b/.github/workflows/test-auth.yml index 2423c28..77dda4a 100644 --- a/.github/workflows/test-auth.yml +++ b/.github/workflows/test-auth.yml @@ -22,6 +22,7 @@ jobs: - name: Start MongoDB Server v${{ matrix.mongodb-version }} uses: ./ with: + mongodb-image: 'public.ecr.aws/docker/library/mongo' mongodb-version: ${{ matrix.mongodb-version }} mongodb-db: ${{ matrix.mongodb-db }} mongodb-username: ${{ matrix.mongodb-username }} diff --git a/.github/workflows/test-replica-set.yml b/.github/workflows/test-replica-set.yml index 87c6c35..b7fca2c 100644 --- a/.github/workflows/test-replica-set.yml +++ b/.github/workflows/test-replica-set.yml @@ -19,6 +19,7 @@ jobs: - name: Start MongoDB Server v${{ matrix.mongodb-version }} uses: ./ with: + mongodb-image: 'public.ecr.aws/docker/library/mongo' mongodb-version: ${{ matrix.mongodb-version }} mongodb-replica-set: mongodb-test-rs diff --git a/.github/workflows/test-single-instance.yml b/.github/workflows/test-single-instance.yml index 56adff3..b3e15d4 100644 --- a/.github/workflows/test-single-instance.yml +++ b/.github/workflows/test-single-instance.yml @@ -19,6 +19,7 @@ jobs: - name: Start MongoDB Server v${{ matrix.mongodb-version }} uses: ./ with: + mongodb-image: 'public.ecr.aws/docker/library/mongo' mongodb-version: ${{ matrix.mongodb-version }} - name: Use Node.js ${{ matrix.node-version }} diff --git a/README.md b/README.md index a5d15d7..09ae8f1 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,8 @@ jobs: - name: Start MongoDB uses: supercharge/mongodb-github-action@1.11.0 with: + # Here we are using an image from Amazon's ECR rather than the default image from Docker Hub + mongodb-image: 'public.ecr.aws/docker/library/mongo' mongodb-version: ${{ matrix.mongodb-version }} - run: npm install diff --git a/action-types.yml b/action-types.yml index 467fe41..b03fcf8 100644 --- a/action-types.yml +++ b/action-types.yml @@ -1,5 +1,7 @@ # See https://github.com/krzema12/github-actions-typing inputs: + mongodb-image: + type: string mongodb-version: type: string mongodb-replica-set: diff --git a/action.yml b/action.yml index 170e6a9..2b237cb 100644 --- a/action.yml +++ b/action.yml @@ -6,6 +6,11 @@ branding: color: 'green' inputs: + mongodb-image: + 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")' + required: false + default: 'mongo' + mongodb-version: description: 'MongoDB version to use (default "latest")' required: false @@ -45,6 +50,7 @@ runs: using: 'docker' image: 'Dockerfile' args: + - ${{ inputs.mongodb-image }} - ${{ inputs.mongodb-version }} - ${{ inputs.mongodb-replica-set }} - ${{ inputs.mongodb-port }} diff --git a/start-mongodb.sh b/start-mongodb.sh index 28523ee..d302a49 100644 --- a/start-mongodb.sh +++ b/start-mongodb.sh @@ -1,17 +1,25 @@ #!/bin/sh # Map input values from the GitHub Actions workflow to shell variables -MONGODB_VERSION=$1 -MONGODB_REPLICA_SET=$2 -MONGODB_PORT=$3 -MONGODB_DB=$4 -MONGODB_USERNAME=$5 -MONGODB_PASSWORD=$6 -MONGODB_CONTAINER_NAME=$7 +MONGODB_IMAGE=$1 +MONGODB_VERSION=$2 +MONGODB_REPLICA_SET=$3 +MONGODB_PORT=$4 +MONGODB_DB=$5 +MONGODB_USERNAME=$6 +MONGODB_PASSWORD=$7 +MONGODB_CONTAINER_NAME=$8 # `mongosh` is used starting from MongoDB 5.x MONGODB_CLIENT="mongosh --quiet" +if [ -z "$MONGODB_IMAGE" ]; then + echo "" + echo "Missing MongoDB image in the [mongodb-image] input. Received value: $MONGODB_IMAGE" + echo "" + + exit 2 +fi if [ -z "$MONGODB_VERSION" ]; then echo "" @@ -21,6 +29,7 @@ if [ -z "$MONGODB_VERSION" ]; then exit 2 fi +echo "::group::Using mogo image $MONGODB_IMAGE:$MONGODB_VERSION" echo "::group::Selecting correct MongoDB client" if [ "`echo $MONGODB_VERSION | cut -c 1`" -le "4" ]; then @@ -83,7 +92,7 @@ if [ -z "$MONGODB_REPLICA_SET" ]; then echo " - container-name [$MONGODB_CONTAINER_NAME]" echo "" - 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 + 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 if [ $? -ne 0 ]; then echo "Error starting MongoDB Docker container" @@ -104,7 +113,7 @@ echo " - replica set [$MONGODB_REPLICA_SET]" echo "" -docker run --name $MONGODB_CONTAINER_NAME --publish $MONGODB_PORT:$MONGODB_PORT --detach mongo:$MONGODB_VERSION --port $MONGODB_PORT --replSet $MONGODB_REPLICA_SET +docker run --name $MONGODB_CONTAINER_NAME --publish $MONGODB_PORT:$MONGODB_PORT --detach $MONGODB_IMAGE:$MONGODB_VERSION --port $MONGODB_PORT --replSet $MONGODB_REPLICA_SET if [ $? -ne 0 ]; then echo "Error starting MongoDB Docker container" From 4639b459cd17255fd9908de8910f0edf1b24db40 Mon Sep 17 00:00:00 2001 From: Sam Bate <156081947+Sam-Bate-ITV@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:53:57 +0000 Subject: [PATCH 2/4] apply suggested change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marcus Pöhls --- start-mongodb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start-mongodb.sh b/start-mongodb.sh index d302a49..50f3f9a 100644 --- a/start-mongodb.sh +++ b/start-mongodb.sh @@ -29,7 +29,7 @@ if [ -z "$MONGODB_VERSION" ]; then exit 2 fi -echo "::group::Using mogo image $MONGODB_IMAGE:$MONGODB_VERSION" +echo "::group::Using MongoDB Docker image $MONGODB_IMAGE:$MONGODB_VERSION" echo "::group::Selecting correct MongoDB client" if [ "`echo $MONGODB_VERSION | cut -c 1`" -le "4" ]; then From 812452b9eb78a8ff4cc84ca5678f6b23f4ce5671 Mon Sep 17 00:00:00 2001 From: Sam Bate Date: Mon, 9 Dec 2024 18:15:10 +0000 Subject: [PATCH 3/4] use docker hub for CI --- .github/workflows/main.yml | 1 - .github/workflows/test-auth.yml | 1 - .github/workflows/test-replica-set.yml | 1 - .github/workflows/test-single-instance.yml | 1 - 4 files changed, 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 97e0d35..6d039fe 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,5 +18,4 @@ jobs: - name: Start MongoDB Server uses: ./ with: - mongodb-image: 'public.ecr.aws/docker/library/mongo' mongodb-version: ${{ matrix.mongodb-version }} diff --git a/.github/workflows/test-auth.yml b/.github/workflows/test-auth.yml index 77dda4a..2423c28 100644 --- a/.github/workflows/test-auth.yml +++ b/.github/workflows/test-auth.yml @@ -22,7 +22,6 @@ jobs: - name: Start MongoDB Server v${{ matrix.mongodb-version }} uses: ./ with: - mongodb-image: 'public.ecr.aws/docker/library/mongo' mongodb-version: ${{ matrix.mongodb-version }} mongodb-db: ${{ matrix.mongodb-db }} mongodb-username: ${{ matrix.mongodb-username }} diff --git a/.github/workflows/test-replica-set.yml b/.github/workflows/test-replica-set.yml index b7fca2c..87c6c35 100644 --- a/.github/workflows/test-replica-set.yml +++ b/.github/workflows/test-replica-set.yml @@ -19,7 +19,6 @@ jobs: - name: Start MongoDB Server v${{ matrix.mongodb-version }} uses: ./ with: - mongodb-image: 'public.ecr.aws/docker/library/mongo' mongodb-version: ${{ matrix.mongodb-version }} mongodb-replica-set: mongodb-test-rs diff --git a/.github/workflows/test-single-instance.yml b/.github/workflows/test-single-instance.yml index b3e15d4..56adff3 100644 --- a/.github/workflows/test-single-instance.yml +++ b/.github/workflows/test-single-instance.yml @@ -19,7 +19,6 @@ jobs: - name: Start MongoDB Server v${{ matrix.mongodb-version }} uses: ./ with: - mongodb-image: 'public.ecr.aws/docker/library/mongo' mongodb-version: ${{ matrix.mongodb-version }} - name: Use Node.js ${{ matrix.node-version }} From 1f93cb7bb1c488587386e8dee98f3d800c0375f1 Mon Sep 17 00:00:00 2001 From: Sam Bate Date: Mon, 9 Dec 2024 18:20:46 +0000 Subject: [PATCH 4/4] change README based on PR review --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 09ae8f1..0d5668e 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,6 @@ jobs: - name: Start MongoDB uses: supercharge/mongodb-github-action@1.11.0 with: - # Here we are using an image from Amazon's ECR rather than the default image from Docker Hub - mongodb-image: 'public.ecr.aws/docker/library/mongo' mongodb-version: ${{ matrix.mongodb-version }} - run: npm install @@ -248,6 +246,17 @@ jobs: **Caveat:** due to [this issue](https://github.com/docker-library/mongo/issues/211), you **cannot enable user creation AND replica sets** initially. Therefore, if you use this action to setup a replica set, please create your users through a separate script. +### Using a Custom Mongo Image +You can utilize an alternative Redis image using the `mongodb-image` input: + +```yaml + - name: Start MongoDB + uses: supercharge/mongodb-github-action@1.11.0 + with: + # Here we are using an image from Amazon's ECR rather than the default image from Docker Hub + mongodb-image: 'public.ecr.aws/docker/library/mongo' + mongodb-version: ${{ matrix.mongodb-version }} +``` ## License MIT © [Supercharge](https://superchargejs.com)