Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 110 additions & 95 deletions .evergreen/orchestration/drivers_orchestration.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,99 +42,112 @@


def get_options():
command = sys.argv[1]
if command == "run":
description = __doc__
else:
description = f"{sys.argv[1].capitalize()} mongo-orchestration"

parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
description=description, formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument("command", choices=["run", "start", "stop", "clean"])
parser.add_argument(
"--verbose", "-v", action="store_true", help="Whether to log at the DEBUG level"
)
parser.add_argument(
"--quiet", "-q", action="store_true", help="Whether to log at the WARNING level"
)
parser.add_argument(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No arguments were changed, we just gate them on which command is being run.

"--version",
default="latest",
help='The version to download. Use "latest" to download '
"the newest available version (including release candidates).",
)
parser.add_argument(
"--topology",
choices=["standalone", "replica_set", "sharded_cluster"],
help="The topology of the server deployment (defaults to standalone unless another flag like load_balancer is set)",
)
parser.add_argument(
"--auth", action="store_true", help="Whether to add authentication"
)
parser.add_argument(
"--ssl", action="store_true", help="Whether to add TLS configuration"
)
parser.add_argument(
"--local-atlas",
action="store_true",
help="Whether to use mongodb-atlas-local to start the server",
)
parser.add_argument(
"--orchestration-file", help="The name of the orchestration config file"
)

if command == "run":
parser.add_argument(
"--version",
default="latest",
help='The version to download. Use "latest" to download '
"the newest available version (including release candidates).",
)
parser.add_argument(
"--topology",
choices=["standalone", "replica_set", "sharded_cluster"],
help="The topology of the server deployment (defaults to standalone unless another flag like load_balancer is set)",
)
parser.add_argument(
"--auth", action="store_true", help="Whether to add authentication"
)
parser.add_argument(
"--ssl", action="store_true", help="Whether to add TLS configuration"
)
parser.add_argument(
"--local-atlas",
action="store_true",
help="Whether to use mongodb-atlas-local to start the server",
)
parser.add_argument(
"--orchestration-file", help="The name of the orchestration config file"
)

other_group = parser.add_argument_group("Other options")
other_group.add_argument(
"--load-balancer", action="store_true", help="Whether to use a load balancer"
)
other_group.add_argument(
"--auth-aws", action="store_true", help="Whether to use MONGODB-AWS auth"
)
other_group.add_argument(
"--skip-crypt-shared",
action="store_true",
help="Whether to skip installing crypt_shared lib",
)
other_group.add_argument(
"--install-legacy-shell",
action="store_true",
help="Whether to install the legacy shell",
)
other_group.add_argument(
"--disable-test-commands",
action="store_true",
help="Whether to disable test commands",
)
other_group.add_argument(
"--storage-engine",
choices=["", "mmapv1", "wiredtiger", "inmemory"],
help="The storage engine to use",
)
other_group.add_argument(
"--require-api-version",
action="store_true",
help="Whether to set requireApiVersion",
)
if command == "run":
other_group.add_argument(
"--load-balancer",
action="store_true",
help="Whether to use a load balancer",
)
other_group.add_argument(
"--auth-aws", action="store_true", help="Whether to use MONGODB-AWS auth"
)
other_group.add_argument(
"--skip-crypt-shared",
action="store_true",
help="Whether to skip installing crypt_shared lib",
)
other_group.add_argument(
"--install-legacy-shell",
action="store_true",
help="Whether to install the legacy shell",
)
other_group.add_argument(
"--disable-test-commands",
action="store_true",
help="Whether to disable test commands",
)
other_group.add_argument(
"--storage-engine",
choices=["", "mmapv1", "wiredtiger", "inmemory"],
help="The storage engine to use",
)
other_group.add_argument(
"--require-api-version",
action="store_true",
help="Whether to set requireApiVersion",
)
other_group.add_argument(
"--existing-binaries-dir",
help="A directory containing existing mongodb binaries to use instead of downloading new ones",
)
other_group.add_argument(
"--tls-pem-key-file",
help="A .pem file that contains the TLS certificate and key for the server",
)
other_group.add_argument(
"--tls-ca-file",
help="A .pem file that contains the root certificate chain for the server",
)

other_group.add_argument(
"--mongo-orchestration-home", help="The path to mongo-orchestration home"
)
other_group.add_argument(
"--mongodb-binaries", help="The path to store the MongoDB binaries"
)
other_group.add_argument(
"--existing-binaries-dir",
help="A directory containing existing mongodb binaries to use instead of downloading new ones",
)
other_group.add_argument(
"--tls-cert-key-file",
help="A .pem to be used as the tlsCertificateKeyFile option in mongo-orchestration",
)
other_group.add_argument(
"--tls-pem-key-file",
help="A .pem file that contains the TLS certificate and key for the server",
)
other_group.add_argument(
"--tls-ca-file",
help="A .pem file that contains the root certificate chain for the server",
)

if command in ["start", "run"]:
other_group.add_argument(
"--mongodb-binaries", help="The path to store the MongoDB binaries"
)
other_group.add_argument(
"--tls-cert-key-file",
help="A .pem to be used as the tlsCertificateKeyFile option in mongo-orchestration",
)

# Get the options, and then allow environment variable overrides.
opts = parser.parse_args()
opts = parser.parse_args(sys.argv[2:])
for key in vars(opts).keys():
env_var = key.upper()
if env_var == "VERSION":
Expand All @@ -153,23 +166,25 @@ def get_options():

if opts.mongo_orchestration_home is None:
opts.mongo_orchestration_home = DRIVERS_TOOLS / ".evergreen/orchestration"
if opts.mongodb_binaries is None:
opts.mongodb_binaries = DRIVERS_TOOLS / "mongodb/bin"
if not opts.topology and opts.load_balancer:
opts.topology = "sharded_cluster"
if opts.auth_aws:
opts.auth = True
opts.orchestration_file = "auth-aws.json"
if opts.topology == "standalone" or not opts.topology:
opts.topology = "server"
if not opts.version:
opts.version = "latest"
if command in ["start", "run"]:
if opts.mongodb_binaries is None:
opts.mongodb_binaries = DRIVERS_TOOLS / "mongodb/bin"
if command == "run":
if not opts.topology and opts.load_balancer:
opts.topology = "sharded_cluster"
if opts.auth_aws:
opts.auth = True
opts.orchestration_file = "auth-aws.json"
if opts.topology == "standalone" or not opts.topology:
opts.topology = "server"
if not opts.version:
opts.version = "latest"

if opts.verbose:
LOGGER.setLevel(logging.DEBUG)
elif opts.quiet:
LOGGER.setLevel(logging.WARNING)
return opts
return opts, command


def get_docker_cmd():
Expand Down Expand Up @@ -646,14 +661,14 @@ def stop(opts):


def main():
opts = get_options()
if opts.command == "run":
opts, command = get_options()
if command == "run":
run(opts)
elif opts.command == "start":
elif command == "start":
start(opts)
elif opts.command == "stop":
elif command == "stop":
stop(opts)
elif opts.command == "clean":
elif command == "clean":
clean_run(opts)
clean_start(opts)

Expand Down
7 changes: 5 additions & 2 deletions .evergreen/run-orchestration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ set -eu
# REQUIRE_API_VERSION Set to a non-empty string to set the requireApiVersion parameter. Currently only supported for standalone servers.
# DISABLE_TEST_COMMANDS Set to a non-empty string to use the <topology>/disableTestCommands.json configuration (e.g. DISABLE_TEST_COMMANDS=1).
# SKIP_CRYPT_SHARED Set to a non-empty string to skip downloading crypt_shared
# MONGODB_BINARIES Set the path to the MONGODB_BINARIES for mongo orchestration.
# LOAD_BALANCER Set to a non-empty string to enable load balancer. Only supported for sharded clusters.
# AUTH_AWS Set to a non-empty string to enable MONGODB-AWS authentication.
# PYTHON Set the Python binary to use.
# LOCAL_ATLAS Set to use mongodb-atlas-local to start the server.
# INSTALL_LEGACY_SHELL Set to a non-empty string to install the legacy mongo shell.
# TLS_CERT_KEY_FILE Set a .pem file to be used as the tlsCertificateKeyFile option in mongo-orchestration
# TLS_PEM_KEY_FILE Set a .pem file that contains the TLS certificate and key for the server
# TLS_CA_FILE Set a .pem file that contains the root certificate chain for the server

# The following variables affect the mongo-orchestration server:
# MONGO_ORCHESTRATION_HOME Set the path where the files used by mongo-orchestration will be located.
# MONGODB_BINARIES Set the path to the MONGODB_BINARIES for mongo-orchestration.
# TLS_CERT_KEY_FILE Set a .pem file to be used as the tlsCertificateKeyFile option in mongo-orchestration.

# See https://stackoverflow.com/questions/35006457/choosing-between-0-and-bash-source/35006505#35006505
# Why we need this syntax when sh is not aliased to bash (this script must be able to be called from sh)
# shellcheck disable=SC3028
Expand Down
6 changes: 4 additions & 2 deletions .evergreen/start-orchestration.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env bash
# shellcheck shell=sh

set -o errexit # Exit the script with error if any of the commands fail
set -eu

# See the run-orchestration.sh for a list of supported environment variables for start-orchestration.

# See https://stackoverflow.com/questions/35006457/choosing-between-0-and-bash-source/35006505#35006505
# Why we need this syntax when sh is not aliased to bash (this script must be able to be called from sh)
Expand All @@ -12,4 +14,4 @@ SCRIPT_DIR=$(dirname ${BASH_SOURCE:-$0})
# Ensure the CLIs are up to date.
bash $SCRIPT_DIR/orchestration/setup.sh

$SCRIPT_DIR/orchestration/drivers-orchestration start
$SCRIPT_DIR/orchestration/drivers-orchestration start "$@"
2 changes: 1 addition & 1 deletion .evergreen/stop-orchestration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ SCRIPT_DIR=$(dirname ${BASH_SOURCE:-$0})
# Ensure the CLIs are up to date.
bash $SCRIPT_DIR/orchestration/setup.sh

$SCRIPT_DIR/orchestration/drivers-orchestration stop
$SCRIPT_DIR/orchestration/drivers-orchestration stop "$@"
4 changes: 4 additions & 0 deletions .evergreen/tests/test-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ bash install-cli.sh "$(pwd)/orchestration"
${DOWNLOAD_DIR}/mongod --version | grep v7.0
./orchestration/drivers-orchestration stop

# Ensure we can use a downloaded mongodb directory in start-orchestration.
./orchestration/drivers-orchestration start --mongodb-binaries=${DOWNLOAD_DIR}
./orchestration/drivers-orchestration stop

if [ ${1:-} == "partial" ]; then
popd
make -C ${DRIVERS_TOOLS} test
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ TOPOLOGY=replica_set MONGODB_VERSION=7.0 make run-server
You can also run: `make run-local-atlas` to run a local atlas server in a container.

See (run-orchestration.sh)[./evergreen/run-orchestration.sh] for the available environment variables.
Run `bash ./evergreen/run-orchestration.sh --help` for usage of command line flags.

In order to use custom certificates in your server, set the following environment variables:

Expand All @@ -105,6 +106,17 @@ export TLS_PEM_KEY_FILE=<path-to>/server.pem
export TLS_CA_FILE=<path-to>/ca.pem
```

### Manual use of start-orchestration

The (start-orchestration.sh)[./evergreen/start-orchestration.sh] script can be used directly as a way to
start the orchestration server without downloading binaries or starting a local server.
You are still responsible for having a directory containing the MongoDB binaries in the default
MONGODB_BINARIES folder or setting MONGODB_BINARIES to the appropriate folder.

See (run-orchestration.sh)[./evergreen/run-orchestration.sh] for the available environment variables.

Run `bash ./evergreen/start-orchestration.sh --help` for usage of command line flags.

## Updating Dependencies

The MongoDB server management scripts under [`.evergreen/orchestration`](https://github.com/mongodb-labs/drivers-evergreen-tools/tree/master/.evergreen/orchestration)
Expand Down
Loading