Skip to content

Commit 4494cee

Browse files
committed
Fix #1 add mongosh and mongotools
1 parent ed96fb1 commit 4494cee

File tree

7 files changed

+165
-1
lines changed

7 files changed

+165
-1
lines changed

.github/workflows/example.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# mongotools continuous integration
2+
name: action-mongo-tools-example
3+
4+
# Controls when the action will run.
5+
on:
6+
# Triggers the workflow on push or pull request events but only for the prod branch
7+
push:
8+
branches: [ main ]
9+
pull_request:
10+
# Allows you to run this workflow manually from the Actions tab
11+
workflow_dispatch:
12+
13+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
14+
jobs:
15+
# This workflow contains a single job
16+
mongo-tools-example-steps:
17+
# The type of runner that the job will run on
18+
# https://github.com/actions/runner-images/tree/main/images/linux
19+
# runs-on: ubuntu-latest
20+
runs-on: ubuntu-22.04
21+
22+
services:
23+
mongodb:
24+
image: mongo
25+
ports:
26+
- 27017:27017
27+
28+
steps:
29+
30+
# use this action-mongo-tools without parameters to install both. Below parameters is for teaching purpose.
31+
32+
- name: Setup mongo tools - only mongo-shell
33+
uses: boly38/action-mongo-tools@stable
34+
with:
35+
mongo-shell: "true"
36+
mongo-tools: "false"
37+
38+
- name: Mongo-shell usage - setup mongo user
39+
# doc: https://docs.mongodb.com/manual/reference/built-in-roles/ "Backup and Restoration Roles"
40+
# doc: https://docs.mongodb.com/manual/reference/method/db.createUser/
41+
run: |
42+
mongosh --version
43+
mongosh admin --eval 'db.createUser({user:"root",pwd:"mypass",roles:[{"role":"readWrite","db":"myDbForTest"}, "restore"]});'
44+
45+
- name: Setup mongo tools - only mongo-tools
46+
uses: boly38/action-mongo-tools@stable
47+
with:
48+
mongo-shell: "false"
49+
50+
- name: Mongo-tools usage
51+
run: |
52+
mongodump --version
53+
mongorestore --version

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea/

LICENSE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2022
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
11
# action-mongo-tools
2-
add mongo shell and/or mongo tools to github action (Ubuntu-2204 runner)
2+
Add mongo shell and/or mongo tools to github actions
3+
4+
- Ubuntu-22.04 [runner](https://github.com/actions/runner-images/tree/main/images/linux) comes without mongo binaries.
5+
6+
In order to add mongosh and mongodump/mongorestore, you could add this action.
7+
8+
Example:
9+
```yaml
10+
- name: Setup mongo tools
11+
uses: boly38/action-mongo-tools@stable
12+
```
13+
14+
You could select which one to install using parameters:
15+
16+
Example that will install `mongosh` only
17+
```yaml
18+
- name: Setup mongo tools - only shell
19+
uses: boly38/action-mongo-tools@stable
20+
with:
21+
mongo-shell: "true"
22+
mongo-tools: "false"
23+
```
24+
NB: `true` is default value for parameters so could be omitted.
25+
26+
Another working sample: cf. [example.yml](./.github/workflows/example.yml)
27+
28+
# contributing
29+
PRs extending the functionality are welcome and will be reviewed.

action.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: 'action-mongo-tools'
2+
author: boly38
3+
description: 'Github action to install mongoDB database mongo-shell and/or mongo tools (mongodump mongorestore..)'
4+
branding: # https://github.com/haya14busa/github-action-brandings
5+
icon: 'package'
6+
color: 'gray-dark'
7+
inputs: # https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputsinput_iddefault
8+
mongo-shell:
9+
description: 'Install mongo-shell ? "true" is default value. Else skip.'
10+
required: true
11+
default: "true"
12+
mongo-tools:
13+
description: 'Install mongo-tools ? "true" is default value. Else skip.'
14+
required: true
15+
default: "true"
16+
runs:
17+
using: "composite"
18+
steps:
19+
- name: Mongo-shell
20+
run: |
21+
if [[ ${{ inputs.mongo-shell }} = "true" ]]
22+
then
23+
echo "Setup mongo-shell"
24+
${{ github.action_path }}/setupMongoShell.sh
25+
else
26+
echo "Skip mongo-shell setup"
27+
fi
28+
shell: bash
29+
- name: Mongo-tools
30+
run: |
31+
if [[ ${{ inputs.mongo-tools }} = "true" ]]
32+
then
33+
echo "Setup mongo-tools"
34+
${{ github.action_path }}/setupMongoTools.sh
35+
else
36+
echo "Skip mongo-tools setup"
37+
fi
38+
shell: bash

setupMongoShell.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# Setup mongosh - src: https://www.mongodb.com/docs/mongodb-shell/install/
3+
echo "setup keys"
4+
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
5+
sudo apt-get install gnupg
6+
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
7+
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
8+
9+
echo "aptitude update"
10+
sudo apt-get update
11+
12+
echo "aptitude install mongodb-mongosh"
13+
sudo apt-get install -y mongodb-mongosh
14+
15+
echo "show current version"
16+
mongosh --version

setupMongoTools.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
# Setup mongoDB Tools - src: https://www.mongodb.com/docs/database-tools/installation/installation-linux/
3+
echo "aptitude install mongodb-database-tools"
4+
sudo apt install mongodb-database-tools
5+
6+
echo "mongodump --version"
7+
mongodump --version

0 commit comments

Comments
 (0)