Skip to content

Commit

Permalink
Merge pull request #65 from yuvalherziger/fix-macos-auth
Browse files Browse the repository at this point in the history
Fix authentication on macOS
  • Loading branch information
yuvalherziger authored Aug 30, 2024
2 parents c14eea6 + 0a40509 commit 03ca9ba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
7 changes: 4 additions & 3 deletions tomodo/common/om_server_provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
console = Console()
logger = logging.getLogger("rich")
# TODO: Switch over when done debugging locally
OM_REPO = "ghcr.io/yuvalherziger/tomodo-om-server"
OM_TAG = "main"
OM_SERVER_REPO = "ghcr.io/yuvalherziger/tomodo-om-server"
OM_SERVER_TAG = "main"

READINESS_MAX_ATTEMPTS = 60
READINESS_DELAY = 1
Expand All @@ -45,7 +45,7 @@ def create_server_container(self, port: int, group_name: str, name: str, om: Ops
}
)
return self.docker_client.containers.run(
f"{OM_REPO}:{OM_TAG}",
f"{OM_SERVER_REPO}:{OM_SERVER_TAG}",
detach=True,
ports={f"{port}/tcp": port},
platform=f"linux/{platform.machine()}",
Expand Down Expand Up @@ -77,6 +77,7 @@ def create(self) -> None:
servers = self.server_config.count
if not is_port_range_available(tuple(range(start_port, start_port + servers))):
raise PortsTakenException
self.check_and_pull_image(image_name=f"{OM_SERVER_REPO}:{OM_SERVER_TAG}")
om_name = self.server_config.agent_config.om_name
om: OpsManagerInstance = Reader().get_deployment_by_name(om_name, get_group=False)
network = self.get_network(om.network_name)
Expand Down
7 changes: 4 additions & 3 deletions tomodo/common/provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from tomodo.common.models import Mongod, ReplicaSet, ShardedCluster, Mongos, Shard, ConfigServer, Deployment, \
AtlasDeployment
from tomodo.common.util import (
is_port_range_available, with_retry, run_mongo_shell_command
is_port_range_available, with_retry, run_mongo_shell_command, get_os
)

DOCKER_ENDPOINT_CONFIG_VER = "1.43"
Expand Down Expand Up @@ -484,6 +484,7 @@ def create_mongod_container(self, port: int, name: str, replset_name: str = None
command.extend(["--dbpath", container_path, "--logpath", f"{container_path}/mongod.log"])

environment = []
target_keyfile_path = "/etc/mongo/mongo_keyfile" if get_os() == "macOS" else "/data/db/mongo_keyfile"
if self.config.username and self.config.password and not self.config.sharded:
environment = [f"MONGO_INITDB_ROOT_USERNAME={self.config.username}",
f"MONGO_INITDB_ROOT_PASSWORD={self.config.password}"]
Expand All @@ -497,9 +498,9 @@ def create_mongod_container(self, port: int, name: str, replset_name: str = None
file.write(base64_bytes)
os.chmod(keyfile_path, 0o400)
mounts.append(
Mount(target="/data/db/mongo_keyfile", source=keyfile_path, type="bind")
Mount(target=target_keyfile_path, source=keyfile_path, type="bind")
)
command.extend(["--keyFile", "/data/db/mongo_keyfile"])
command.extend(["--keyFile", target_keyfile_path])
deployment_type = "Standalone"
if config_svr:
command.extend(["--configsvr", "--replSet", replset_name])
Expand Down
11 changes: 11 additions & 0 deletions tomodo/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import inspect
import io
import logging
import platform
import re
import socket
import time
Expand Down Expand Up @@ -189,3 +190,13 @@ def check_docker():

def split_into_chunks(lst: List[Any], chunk_size: int = 20):
return [lst[i:i + chunk_size] for i in range(0, len(lst), chunk_size)]


def get_os():
os_platform = platform.system()
if os_platform == "Darwin":
return "macOS"
elif os_platform == "Linux":
return "Linux"
else:
return "Unknown OS"

0 comments on commit 03ca9ba

Please sign in to comment.