-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add --offline flag to skip network access during up #316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3440d0a
3af9c2d
9f976b4
dc13b02
48f958a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,7 +162,10 @@ def up(args: Namespace, existing_status: Status | None = None) -> None: | |
| }, | ||
| ) | ||
|
|
||
| remote_dependencies = _install_service_dependencies(service, mode, status) | ||
| offline = getattr(args, "offline", False) | ||
| remote_dependencies = _install_service_dependencies( | ||
| service, mode, status, offline=offline | ||
| ) | ||
| _create_devservices_network() | ||
| # Add the service to the starting services table | ||
| state.update_service_entry(service.name, mode, StateTables.STARTING_SERVICES) | ||
|
|
@@ -204,6 +207,7 @@ def up(args: Namespace, existing_status: Status | None = None) -> None: | |
| service_name=local_runtime_dependency_name, | ||
| mode="default", # We intentionally don't use the mode from the parent command here | ||
| exclude_local=True, # TODO: This should be False (or maybe whatever the parent command is set to) | ||
| offline=offline, | ||
| ), | ||
| status, | ||
| ) | ||
|
|
@@ -216,7 +220,12 @@ def up(args: Namespace, existing_status: Status | None = None) -> None: | |
| span.set_data("exclude_local", exclude_local) | ||
| try: | ||
| bring_up_docker_compose_services( | ||
| service, [mode], remote_dependencies, mode_dependencies, status | ||
| service, | ||
| [mode], | ||
| remote_dependencies, | ||
| mode_dependencies, | ||
| status, | ||
| skip_pull=offline, | ||
| ) | ||
| except DockerComposeError as dce: | ||
| capture_exception(dce, level="info") | ||
|
|
@@ -239,25 +248,32 @@ def up(args: Namespace, existing_status: Status | None = None) -> None: | |
|
|
||
|
|
||
| def _install_service_dependencies( | ||
| service: Service, mode: str, status: Status | ||
| service: Service, mode: str, status: Status, offline: bool = False | ||
| ) -> set[InstalledRemoteDependency]: | ||
| with start_span( | ||
| op="service.dependencies.install", name="Install dependencies" | ||
| ) as span: | ||
| status.info("Retrieving dependencies") | ||
| status.info( | ||
| "Using cached dependencies" if offline else "Retrieving dependencies" | ||
| ) | ||
| span.set_data("service_name", service.name) | ||
| span.set_data("mode", mode) | ||
| span.set_data("offline", offline) | ||
| try: | ||
| remote_dependencies = install_and_verify_dependencies( | ||
| service, force_update_dependencies=True, modes=[mode] | ||
| service, | ||
| force_update_dependencies=not offline, | ||
| modes=[mode], | ||
| offline=offline, | ||
| ) | ||
| span.set_data("remote_dependency_count", len(remote_dependencies)) | ||
| return remote_dependencies | ||
| except DependencyError as de: | ||
| capture_exception(de) | ||
| status.failure( | ||
| f"{str(de)}. If this error persists, try running `devservices purge`" | ||
| ) | ||
| msg = de.stderr if de.stderr else str(de) | ||
| if not offline: | ||
| msg = f"{msg}. If this error persists, try running `devservices purge`" | ||
| status.failure(msg) | ||
| exit(1) | ||
| except ModeDoesNotExistError as mde: | ||
| status.failure(str(mde)) | ||
|
|
@@ -310,6 +326,7 @@ def bring_up_docker_compose_services( | |
| remote_dependencies: set[InstalledRemoteDependency], | ||
| mode_dependencies: list[str], | ||
| status: Status, | ||
| skip_pull: bool = False, | ||
| ) -> None: | ||
| relative_local_dependency_directory = os.path.relpath( | ||
| os.path.join(DEVSERVICES_DEPENDENCIES_CACHE_DIR, DEPENDENCY_CONFIG_VERSION), | ||
|
|
@@ -334,27 +351,29 @@ def bring_up_docker_compose_services( | |
| ), | ||
| ) | ||
|
|
||
| # Pull all images in parallel | ||
| status.info("Pulling images") | ||
| pull_commands = get_docker_compose_commands_to_run( | ||
| service=service, | ||
| remote_dependencies=sorted_remote_dependencies, | ||
| current_env=current_env, | ||
| command="pull", | ||
| options=[], | ||
| service_config_file_path=service_config_file_path, | ||
| mode_dependencies=mode_dependencies, | ||
| ) | ||
| if not skip_pull: | ||
| status.info("Pulling images") | ||
| pull_commands = get_docker_compose_commands_to_run( | ||
| service=service, | ||
| remote_dependencies=sorted_remote_dependencies, | ||
| current_env=current_env, | ||
| command="pull", | ||
| options=[], | ||
| service_config_file_path=service_config_file_path, | ||
| mode_dependencies=mode_dependencies, | ||
| ) | ||
|
|
||
| with concurrent.futures.ThreadPoolExecutor() as pull_dependency_executor: | ||
| futures = [ | ||
| pull_dependency_executor.submit( | ||
| _pull_dependency_images, cmd, current_env, status | ||
| ) | ||
| for cmd in pull_commands | ||
| ] | ||
| for future in concurrent.futures.as_completed(futures): | ||
| _ = future.result() | ||
| with concurrent.futures.ThreadPoolExecutor() as pull_dependency_executor: | ||
| futures = [ | ||
| pull_dependency_executor.submit( | ||
| _pull_dependency_images, cmd, current_env, status | ||
| ) | ||
| for cmd in pull_commands | ||
| ] | ||
| for future in concurrent.futures.as_completed(futures): | ||
| _ = future.result() | ||
| else: | ||
| status.info("Skipping image pull (using cached images)") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Offline mode doesn't prevent
|
||
|
|
||
| # Bring up all necessary containers | ||
| up_commands = get_docker_compose_commands_to_run( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -214,6 +214,7 @@ def install_and_verify_dependencies( | |
| service: Service, | ||
| force_update_dependencies: bool = False, | ||
| modes: list[str] | None = None, | ||
| offline: bool = False, | ||
| ) -> set[InstalledRemoteDependency]: | ||
| """ | ||
| Install and verify dependencies for a service | ||
|
|
@@ -235,6 +236,17 @@ def install_and_verify_dependencies( | |
| if dependency_key in mode_dependencies | ||
| ] | ||
|
|
||
| if offline: | ||
| are_dependencies_valid = verify_local_dependencies(matching_dependencies) | ||
| if not are_dependencies_valid: | ||
| raise DependencyError( | ||
| repo_name="", | ||
| repo_link="", | ||
| branch="", | ||
| stderr="Cannot use --offline: some dependencies are not cached locally. Run 'devservices up' without --offline first to cache dependencies", | ||
| ) | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| return get_installed_remote_dependencies(matching_dependencies) | ||
|
Comment on lines
+239
to
+248
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The Suggested FixUpdate the Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews.
sentry[bot] marked this conversation as resolved.
sentry[bot] marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Offline validation misses nested dependencies, yields confusing errorMedium Severity In offline mode, Additional Locations (1)Reviewed by Cursor Bugbot for commit 9f976b4. Configure here. |
||
|
|
||
| if force_update_dependencies: | ||
| remote_dependencies = install_dependencies(matching_dependencies) | ||
| else: | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error message displays raw bytes in non-offline path
Medium Severity
The changed error handling now uses
de.stderr if de.stderr else str(de)for the failure message. However,DependencyError.stderris populated fromCalledProcessError.stderr(viastderr=e.stderrin_update_dependency,_checkout_dependency, etc.), and_run_commandcallssubprocess.runwithouttext=True, meaninge.stderrisbytes, notstr. In the non-offline path, when a git operation fails,msgbecomes abytesobject, and the subsequent f-string renders it asb'fatal: ...'— producing a confusing, ugly user-facing error message. Previously,str(de)was always used, which gave a clean formatted message.Reviewed by Cursor Bugbot for commit 48f958a. Configure here.