Package: tomodo
tomodotomodois a Toolbox for MongoDB on Docker.Use it to create and manage Docker-based MongoDB community deployments - standalone instances, replica sets,
and sharded clusters.InstallationInstall with HomebrewInstall with pipInstall from SourceInstall with Poetry Package Manager for PythonInstall from source with pipCLI UsageCreate a DeploymentDescribe DeploymentsList DeploymentsStop DeploymentsStart DeploymentsRemove DeploymentsProgrammatic UsageInstallationInstall with HomebrewHomebrewis a popular package manager for macOS. You can install tomodo by
running the following commands:brewtapyuviherziger/homebrew-tomodo
brewinstalltomodoAfter installing the tool withbrew, you can run it the following way:tomodo--helpInstall with pipTo install withpip, run the following command:pipinstalltomodoInstall from SourceIf you wish to set up a development environment, or if you simply can't use Homebrew or aren't a macOS user,
you can install tomodo using Python. The recommended way to perform the Python installation is by using thePoetryPython package manager.Requirements:Python 3.8 or higherInstall with Poetry Package Manager for PythonIf you have thePoetryPython package manager installed locally, you can install
the CLI the following way:gitclonehttps://github.com/yuviherziger/tomodo.gitcdtomodo
poetryshell
poetryinstallAfter installing the tool with Poetry, you can run it the following way:tomodo--helpInstall from source with pipYou can install the dependencies with pip using the following command:gitclonehttps://github.com/yuviherziger/tomodo.gitcdtomodo
pipinstall.After installing the dependencies with pip, you can validate the installation by invoking the help page:pythontomodo/cmd.py--helpCLI UsageBefore you begin, make sure you have a Docker daemon running. The most popular platform
isDocker Desktop.Create a DeploymentCreate a deployment with theprovisioncommand. For example, here's how you create a standalone
instance with zero configuration:tomodoprovision--standaloneTo create a replica set with zero configuration, run theprovisioncommand in the following way:tomodoprovision--replica-setTo create a sharded cluster with zero configuration, run theprovisioncommand in the following way:tomodoprovision--shardedTake a look at theprovisioncommand's help page to read the full set of options
withtomodo provision --help:Usage: tomodo provision [OPTIONS]

 Provision a MongoDB deployment

╭─ Options ───────────────────────────────────────────────────────────────────────────────────────╮
│ --standalone        --no-standalone                                 Provision a MongoDB         │
│                                                                     standalone instance         │
│                                                                     [default: no-standalone]    │
│ --replica-set       --no-replica-set                                Provision a MongoDB replica │
│                                                                     set                         │
│                                                                     [default: no-replica-set]   │
│ --sharded           --no-sharded                                    Provision a MongoDB sharded │
│                                                                     cluster                     │
│                                                                     [default: no-sharded]       │
│ --replicas                              [1|3|5|7]                   The number of replica set   │
│                                                                     nodes to provision          │
│                                                                     [default: 3]                │
│ --shards                                INTEGER                     The number of shards to     │
│                                                                     provision in a sharded      │
│                                                                     cluster                     │
│                                                                     [default: 2]                │
│ --arbiter           --no-arbiter                                    Add an arbiter node to a    │
│                                                                     replica set                 │
│                                                                     [default: no-arbiter]       │
│ --name                                  TEXT                        The deployment's name;      │
│                                                                     auto-generated if not       │
│                                                                     provided                    │
│                                                                     [default: None]             │
│ --priority          --no-priority                                   Priority (currently         │
│                                                                     ignored)                    │
│                                                                     [default: no-priority]      │
│ --port                                  INTEGER RANGE               The deployment's start port │
│                                         [0<=x<=65535]               [default: 27017]            │
│ --config-servers                        INTEGER                     The number of config server │
│                                                                     replica set nodes           │
│                                                                     [default: 1]                │
│ --mongos                                INTEGER RANGE [x>=1]        The number of mongos        │
│                                                                     routers                     │
│                                                                     [default: 1]                │
│ --auth              --no-auth                                       Whether to enable           │
│                                                                     authentication (currently   │
│                                                                     ignored)                    │
│                                                                     [default: no-auth]          │
│ --username                              TEXT                        Optional authentication     │
│                                                                     username                    │
│                                                                     [default: None]             │
│ --password                              TEXT                        Optional authentication     │
│                                                                     password                    │
│                                                                     [default: None]             │
│ --auth-db                               TEXT                        Authorization DB (currently │
│                                                                     ignored)                    │
│                                                                     [default: None]             │
│ --auth-roles                            TEXT                        Default authentication      │
│                                                                     roles (currently ignored)   │
│                                                                     [default:                   │
│                                                                     dbAdminAnyDatabase          │
│                                                                     readWriteAnyDatabase        │
│                                                                     userAdminAnyDatabase        │
│                                                                     clusterAdmin]               │
│ --image-repo                            TEXT                        The MongoDB image name/repo │
│                                                                     [default: mongo]            │
│ --image-tag                             TEXT                        The MongoDB image tag,      │
│                                                                     which determines the        │
│                                                                     MongoDB version to install  │
│                                                                     [default: latest]           │
│ --network-name                          TEXT                        The Docker network to       │
│                                                                     provision the deployment    │
│                                                                     in; will create a new one   │
│                                                                     or use an existing one with │
│                                                                     the same name if such       │
│                                                                     network exists              │
│                                                                     [default: mongo_network]    │
│ --help                                                              Show this message and exit. │
╰─────────────────────────────────────────────────────────────────────────────────────────────────Describe DeploymentsUse thedescribecommand to print the details of one or all deployments:# Describe all deploymentstomododescribe# Describe a deployment by nametomododescribe--nameyawning-mole# Describe only running deploymentstomododescribe--exclude-stoppedList DeploymentsUse thelistcommand to list your deployments:# List all deploymentstomodolist# List only running deploymentstomodolist--exclude-stoppedStop DeploymentsUse thestopcommand to stop your deployments:# Stop all deploymentstomodostop# Stop a deployment by nametomodostop--nametroubled-narwhal# Stop all deployments without prompting for confirmationtomodostop--auto-approveStart DeploymentsUse thestartcommand to start a deployment you previously stopped:tomodostart--nameprinted-lemmingRemove DeploymentsUse theremovecommand to permanently remove deployments:# Remove all deploymentstomodoremove# Remove a deployment by nametomodoremove--nametroubled-narwhal# Remove all deployments without prompting for confirmationtomodoremove--auto-approveProgrammatic UsageYou can install tomodo in your Python (>=3.8) projects usingpipor any other Python package manager, and use it
programmatically (you'll still need a Docker daemon running).fromtypingimportDictfromtomodoimportfunctionalastfuncfromtomodo.common.errorsimportDeploymentNotFoundfromtomodo.common.modelsimportDeployment,Mongod,ReplicaSet,ShardedCluster# Create a standalone instance:mongod:Mongod=tfunc.provision_standalone_instance(port=1000)# Create a replica set:replica_set:ReplicaSet=tfunc.provision_replica_set(port=2000,replicas=3)# Create a sharded cluster:sh_cluster:ShardedCluster=tfunc.provision_sharded_cluster(port=3000,shards=2,config_servers=3,mongos=2)# Stop a deployment:mongod.stop()# Restart a deployment:mongod.start()# Remove a deployment permanently:mongod.remove()# Find a deployment by nametry:deployment=tfunc.get_deployment(name="elegant-leopard",include_stopped=True)exceptDeploymentNotFound:print("Deployment not found")# List all deployments:deployments:Dict=tfunc.list_deployments(include_stopped=True)fornameindeployments.keys():deployment:Deployment=deployments[name]print(f"Deployment{name}is{deployment.last_known_state}")