Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 9 additions & 7 deletions devservices/commands/down.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
from devservices.constants import DEVSERVICES_DEPENDENCIES_CACHE_DIR
from devservices.constants import DEVSERVICES_DEPENDENCIES_CACHE_DIR_KEY
from devservices.constants import DEVSERVICES_DIR_NAME
from devservices.constants import PROGRAMS_CONF_FILE_NAME
from devservices.exceptions import ConfigError
from devservices.exceptions import ConfigNotFoundError
from devservices.exceptions import DependencyError
from devservices.exceptions import DockerComposeError
from devservices.exceptions import ServiceNotFoundError
from devservices.exceptions import SupervisorConfigError
from devservices.exceptions import SupervisorError
from devservices.utils.console import Console
from devservices.utils.console import Status
Expand Down Expand Up @@ -318,14 +318,16 @@
) -> None:
if len(supervisor_programs) == 0:
return
programs_config_path = os.path.join(
service.repo_path, f"{DEVSERVICES_DIR_NAME}/{PROGRAMS_CONF_FILE_NAME}"
)
manager = SupervisorManager(
programs_config_path,
service_name=service.name,

config_file_path = os.path.join(
service.repo_path, DEVSERVICES_DIR_NAME, CONFIG_FILE_NAME
)

try:
manager = SupervisorManager(service.name, config_file_path)
except SupervisorConfigError:
raise

Check warning on line 329 in devservices/commands/down.py

View check run for this annotation

Codecov / codecov/patch

devservices/commands/down.py#L328-L329

Added lines #L328 - L329 were not covered by tests

with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [
executor.submit(_stop_supervisor_program, manager, program, status)
Expand Down
15 changes: 8 additions & 7 deletions devservices/commands/foreground.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

from sentry_sdk import capture_exception

from devservices.constants import CONFIG_FILE_NAME
from devservices.constants import DependencyType
from devservices.constants import DEVSERVICES_DIR_NAME
from devservices.constants import PROGRAMS_CONF_FILE_NAME
from devservices.exceptions import ConfigError
from devservices.exceptions import ConfigNotFoundError
from devservices.exceptions import ServiceNotFoundError
Expand Down Expand Up @@ -92,14 +92,15 @@
)
return

programs_config_path = os.path.join(
service.repo_path, f"{DEVSERVICES_DIR_NAME}/{PROGRAMS_CONF_FILE_NAME}"
config_file_path = os.path.join(
service.repo_path, DEVSERVICES_DIR_NAME, CONFIG_FILE_NAME
)

manager = SupervisorManager(
programs_config_path,
service_name=service.name,
)
try:
manager = SupervisorManager(service.name, config_file_path)
except SupervisorConfigError as e:
capture_exception(e, level="info")
return

Check warning on line 103 in devservices/commands/foreground.py

View check run for this annotation

Codecov / codecov/patch

devservices/commands/foreground.py#L101-L103

Added lines #L101 - L103 were not covered by tests

try:
program_command = manager.get_program_command(program_name)
Expand Down
8 changes: 3 additions & 5 deletions devservices/commands/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from devservices.constants import DEVSERVICES_DEPENDENCIES_CACHE_DIR_KEY
from devservices.constants import DEVSERVICES_DIR_NAME
from devservices.constants import MAX_LOG_LINES
from devservices.constants import PROGRAMS_CONF_FILE_NAME
from devservices.exceptions import ConfigError
from devservices.exceptions import ConfigNotFoundError
from devservices.exceptions import DependencyError
Expand Down Expand Up @@ -178,12 +177,11 @@ def _supervisor_logs(

supervisor_logs: dict[str, str] = {}

programs_config_path = os.path.join(
service.repo_path, DEVSERVICES_DIR_NAME, PROGRAMS_CONF_FILE_NAME
config_file_path = os.path.join(
service.repo_path, DEVSERVICES_DIR_NAME, CONFIG_FILE_NAME
)

try:
manager = SupervisorManager(programs_config_path, service_name=service.name)
manager = SupervisorManager(service.name, config_file_path)
except SupervisorConfigError as e:
capture_exception(e)
return supervisor_logs
Expand Down
26 changes: 17 additions & 9 deletions devservices/commands/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

from sentry_sdk import capture_exception

from devservices.constants import CONFIG_FILE_NAME
from devservices.constants import DEVSERVICES_DIR_NAME
from devservices.constants import PROGRAMS_CONF_FILE_NAME
from devservices.exceptions import ConfigError
from devservices.exceptions import ConfigNotFoundError
from devservices.exceptions import SupervisorConfigError
Expand Down Expand Up @@ -46,16 +46,24 @@
console.failure(str(e))
exit(1)

programs_config_path = os.path.join(
service.repo_path, f"{DEVSERVICES_DIR_NAME}/{PROGRAMS_CONF_FILE_NAME}"
config_file_path = os.path.join(
service.repo_path, DEVSERVICES_DIR_NAME, CONFIG_FILE_NAME
)
if not os.path.exists(programs_config_path):
console.failure(f"No programs.conf file found in {programs_config_path}.")

try:
manager = SupervisorManager(service.name, config_file_path)
except SupervisorConfigError as e:
capture_exception(e, level="info")
console.failure(

Check warning on line 57 in devservices/commands/serve.py

View check run for this annotation

Codecov / codecov/patch

devservices/commands/serve.py#L55-L57

Added lines #L55 - L57 were not covered by tests
f"Unable to bring up devserver due to supervisor config error: {str(e)}"
)
return

Check warning on line 60 in devservices/commands/serve.py

View check run for this annotation

Codecov / codecov/patch

devservices/commands/serve.py#L60

Added line #L60 was not covered by tests

if not manager.has_programs:
console.failure(
"No programs found in config. Please add the devserver in the `x-programs` block to your config.yml"
)
return
manager = SupervisorManager(
programs_config_path,
service_name=service.name,
)

try:
devserver_command = manager.get_program_command("devserver")
Expand Down
18 changes: 10 additions & 8 deletions devservices/commands/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
from devservices.constants import DEVSERVICES_DEPENDENCIES_CACHE_DIR
from devservices.constants import DEVSERVICES_DEPENDENCIES_CACHE_DIR_KEY
from devservices.constants import DEVSERVICES_DIR_NAME
from devservices.constants import PROGRAMS_CONF_FILE_NAME
from devservices.exceptions import ConfigError
from devservices.exceptions import ConfigNotFoundError
from devservices.exceptions import DependencyError
from devservices.exceptions import DockerComposeError
from devservices.exceptions import ServiceNotFoundError
from devservices.exceptions import SupervisorConfigError
from devservices.utils.console import Console
from devservices.utils.dependencies import construct_dependency_graph
from devservices.utils.dependencies import DependencyGraph
Expand Down Expand Up @@ -103,16 +103,18 @@
console.warning(f"Status unavailable. {service.name} is not running standalone")
return # Since exit(0) is captured as an internal_error by sentry

programs_config_path = os.path.join(
service.repo_path, f"{DEVSERVICES_DIR_NAME}/{PROGRAMS_CONF_FILE_NAME}"
config_file_path = os.path.join(
service.repo_path, DEVSERVICES_DIR_NAME, CONFIG_FILE_NAME
)
process_statuses = {}
if os.path.exists(programs_config_path):
supervisor_manager = SupervisorManager(
programs_config_path,
service.name,
)

try:
supervisor_manager = SupervisorManager(service.name, config_file_path)
process_statuses = supervisor_manager.get_all_process_info()
except SupervisorConfigError as e:
capture_exception(e)
console.failure(str(e))
exit(1)

Check warning on line 117 in devservices/commands/status.py

View check run for this annotation

Codecov / codecov/patch

devservices/commands/status.py#L114-L117

Added lines #L114 - L117 were not covered by tests

try:
status_tree = get_status_for_service(service, process_statuses)
Expand Down
15 changes: 8 additions & 7 deletions devservices/commands/up.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
from devservices.constants import DEVSERVICES_DEPENDENCIES_CACHE_DIR
from devservices.constants import DEVSERVICES_DEPENDENCIES_CACHE_DIR_KEY
from devservices.constants import DEVSERVICES_DIR_NAME
from devservices.constants import PROGRAMS_CONF_FILE_NAME
from devservices.exceptions import ConfigError
from devservices.exceptions import ConfigNotFoundError
from devservices.exceptions import ContainerHealthcheckFailedError
from devservices.exceptions import DependencyError
from devservices.exceptions import DockerComposeError
from devservices.exceptions import ModeDoesNotExistError
from devservices.exceptions import ServiceNotFoundError
from devservices.exceptions import SupervisorConfigError
from devservices.exceptions import SupervisorError
from devservices.utils.console import Console
from devservices.utils.console import Status
Expand Down Expand Up @@ -399,15 +399,16 @@ def bring_up_supervisor_programs(
f"Cannot bring up supervisor programs from outside the service repository. Please run the command from the service repository ({service.repo_path})"
)
return
programs_config_path = os.path.join(
service.repo_path, f"{DEVSERVICES_DIR_NAME}/{PROGRAMS_CONF_FILE_NAME}"
)

manager = SupervisorManager(
programs_config_path,
service_name=service.name,
config_file_path = os.path.join(
service.repo_path, DEVSERVICES_DIR_NAME, CONFIG_FILE_NAME
)

try:
manager = SupervisorManager(service.name, config_file_path)
except SupervisorConfigError:
raise

status.info("Starting supervisor daemon")
manager.start_supervisor_daemon()

Expand Down
24 changes: 14 additions & 10 deletions devservices/configs/service_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from devservices.constants import CONFIG_FILE_NAME
from devservices.constants import DependencyType
from devservices.constants import DEVSERVICES_DIR_NAME
from devservices.constants import PROGRAMS_CONF_FILE_NAME
from devservices.exceptions import ConfigNotFoundError
from devservices.exceptions import ConfigParseError
from devservices.exceptions import ConfigValidationError
from devservices.utils.supervisor import ProgramData
from devservices.utils.supervisor import SupervisorManager

VALID_VERSIONS = [0.1]
Expand Down Expand Up @@ -91,8 +91,10 @@ def load_service_config_from_file(repo_path: str) -> ServiceConfig:

docker_compose_services = config.get("services", {}).keys()

supervisor_programs = load_supervisor_programs_from_file(
repo_path, service_config_data.get("service_name")
supervisor_programs = load_supervisor_programs_from_programs_data(
config_path,
service_config_data.get("service_name"),
config.get("x-programs", {}),
)

valid_dependency_keys = {field.name for field in fields(Dependency)}
Expand All @@ -113,7 +115,7 @@ def load_service_config_from_file(repo_path: str) -> ServiceConfig:
dependency_type = DependencyType.COMPOSE
else:
raise ConfigValidationError(
f"Dependency '{key}' is not remote but is not defined in docker-compose services or programs file"
f"Dependency '{key}' is not remote but is not defined in docker-compose services or x-programs"
)
else:
dependency_type = DependencyType.SERVICE
Expand Down Expand Up @@ -142,13 +144,15 @@ def load_service_config_from_file(repo_path: str) -> ServiceConfig:
return service_config


def load_supervisor_programs_from_file(repo_path: str, service_name: str) -> set[str]:
programs_config_path = os.path.join(
repo_path, DEVSERVICES_DIR_NAME, PROGRAMS_CONF_FILE_NAME
)
if not os.path.exists(programs_config_path):
def load_supervisor_programs_from_programs_data(
service_config_path: str, service_name: str, programs_data: ProgramData
) -> set[str]:
if not programs_data:
return set()
manager = SupervisorManager(programs_config_path, service_name=service_name)

manager = SupervisorManager(
service_name=service_name, service_config_path=service_config_path
)
opts = ServerOptions()
opts.configfile = manager.config_file_path
opts.process_config()
Expand Down
1 change: 0 additions & 1 deletion devservices/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class DependencyType(StrEnum):
MINIMUM_DOCKER_COMPOSE_VERSION = "2.29.7"
DEVSERVICES_DIR_NAME = "devservices"
CONFIG_FILE_NAME = "config.yml"
PROGRAMS_CONF_FILE_NAME = "programs.conf"
DOCKER_CONFIG_DIR = os.environ.get("DOCKER_CONFIG", os.path.expanduser("~/.docker"))
DOCKER_USER_PLUGIN_DIR = os.path.join(DOCKER_CONFIG_DIR, "cli-plugins/")

Expand Down
Loading
Loading